搭建 Gitlab

当设置和配置 GitLab 实例并执行诸如创建群组、项目、用户和上传代码等操作时,涉及到多个步骤,每个步骤都有特定的目的。让我们逐步解释每个步骤并说明其背后的原因:

  1. 安装必需的软件
bash 复制代码
yum install -y curl policycoreutils-python openssh-server perl postfix

此命令安装了必要的软件包,包括命令行工具 curl、用于 SELinux 策略管理的 policycoreutils、用于远程访问的 OpenSSH 服务器、用于脚本编写的 Perl,以及用于邮件服务的 Postfix。
2.启用 SSH 和 Postfix

bash 复制代码
systemctl enable --now sshd postfix

此命令启用并启动了 SSH 服务器和 Postfix 邮件服务。SSH 用于远程访问服务器,而 Postfix 用于发送电子邮件通知,GitLab 可能会用于警报和用户通知。
3.安装 GitLab

下面获取 gitlab-ce-12.3.0-ce.0.el7.x86_64.rpm 文件

bash 复制代码
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.3.5-ce.0.el7.x86_64.rpm --no-check-cetificate

rpm -ivh gitlab-ce-12.3.0-ce.0.el7.x86_64.rpm 安装了指定版本的 GitLab 社区版软件包。
4.配置 GitLab 设置 (vim /etc/gitlab/gitlab.rb):

vim /etc/gitlab/gitlab.rb

bash 复制代码
external_url 'http://192.168.179.20:82'
...
nginx['listen_port'] = 82
  • external_url 'http://192.168.179.20:82':设置 GitLab 的外部 URL,以便从中访问。在此情况下,配置为使用 http://192.168.179.20:82
  • nginx['listen_port'] = 82:配置 Nginx Web 服务器以监听端口 82。
    5.重新配置和重启 GitLab

gitlab-ctl reconfigure:根据 gitlab.rb 中的设置重新配置 GitLab。

gitlab-ctl restart :重新启动 GitLab 服务以应用更改。
6.通过浏览器访问 GitLab

浏览器访问:http://192.168.179.20:82 ,访问 GitLab 实例。如果出现 "502 Bad Gateway" 错误,建议用户稍等片刻,然后刷新页面。

1、设置管理员 root 用户的新密码,注意有格式要求,这里设置成 root@123
2、使用管理员 root 用户登录(root/root@123)
3、登录后点击页面右上方的用户选项下拉选择【Settings】,点击左边菜单【Preferences】,在【Localization】的【Language】中选择【简体中文】,点击【Save changes】按钮,再刷新页面使用中文显示。

//Gitlab添加组、创建用户、创建项目
#创建群组
点击页面左上方的【GitLab】图标,点击 【新建群组】
【群组名称】、【群组URL】、【群组描述】都设置成 devops_group
【可见性级别】设置成 私有
其他都保持默认值,点击 【创建群组】

#创建项目
点击 【新建项目】
【项目URL】群组选项下拉选择 devops_group
【项目名称】设置成 web_demo
【项目描述】设置成 web_demo
【可见等级】设置成 私有
点击 【创建项目】

#创建用户

点击页面上方的【扳手】图标进入"管理区域"

点击 【新建用户】

【姓名】设置成 zhangsan

【用户名】设置成 zhangsan

【电子邮箱】设置成 zhangsan@xny.com

这里密码暂不设置,其他都保持默认值,先点击 【创建用户】

注:Access level:Regular(表示的是普通用户,只能访问属于他的组和项目);Admin(表示的是管理员,可以访问所有组和项目)

创建好用户后再点击右上角的【Edit】,可在这里设置密码,如 zhangsan@123

#将用户添加到组中
点击页面上方的【群组】下拉选择 devops_group
点击"向群组添加用户"菜单【成员】
【添加成员到 devops_group】在search for a user选择 zhangsan,角色权限选择 Owner
点击 【添加到群组】

#使用自己创建的账户进行管理
退出当前账户,使用自己创建的账户 zhangsan 登录(zhangsan/zhangsan@123)
第一次登录会被强制要求修改密码(zhangsan/zhangsan@123),可与旧密码相同,再重新登录

#源码上传到Gitlab仓库

可能现需要yum下载git

yum install git -y

否则会command not fount

git config --global user.name "zhangsan"
git config --global user.email "zhangsan@xny.com"

cd ~
git clone http://192.168.179.20:82/devops_group/web_demo.git #账号/密码:zhangsan/zhangsan@123
ls -A web_demo/

上传 web_demo.zip 文件到 /opt 目录
cd /opt
unzip web_demo.zip
mv web_demo/* /root/web_demo/

cd /root/web_demo
git add .
git commit -m "init web_demo"
git push -u origin master #账号/密码:zhangsan/zhangsan@123

bash 复制代码
[root@localhost web_demo]# git push -u origin master
Username for 'http://192.168.179.20:82': zhangsan
Password for 'http://zhangsan@192.168.179.20:82': 
Counting objects: 10, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (10/10), 1.66 KiB | 0 bytes/s, done.
Total 10 (delta 0), reused 0 (delta 0)
To http://192.168.179.20:82/devops_group/web_demo.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.
[root@localhost web_demo]# 

点击页面上方的【项目】下拉选择 web_demo,即可看到上传的代码

相关推荐
梁萌21 小时前
docker部署gitlab和gitlab runner
docker·eureka·gitlab
johnnyAndCode1 天前
Idea 设置GitLab时使用账密,而不是token的配置方法
gitlab·idea
天外飞雨1 天前
Gitlab使用
gitlab
BUTCHER52 天前
GitLab SSH 密钥配置
运维·ssh·gitlab
明月心9522 天前
GitLab使用
gitlab
明月心9523 天前
gitlab pull requets
gitlab
BUTCHER53 天前
GitLab基本设置
gitlab
张小凡vip3 天前
Kubernetes---gitlab的ci/cd发布基于k8s的项目示例参考
ci/cd·kubernetes·gitlab
cuijiecheng20184 天前
GitLab创建项目
gitlab
_运维那些事儿6 天前
GitLabCI/CD语法
linux·服务器·git·ci/cd·gitlab·运维开发·devops