Gitlab Server 部署
环境准备
- 一台服务器,配置域名,主机名,关闭防火墙,selinux打开邮件系统服务,具体的操作如下:
1、修改主机名
[root@localhost ~]# hostnamectl --static set-hostname cicd-gitlab
2、关闭防火墙
[root@cicd-gitlab ~]# systemctl stop iptables firewalld
[root@cicd-gitlab ~]# systemctl disable iptables firewalld
3、开启邮件服务
[root@cicd-gitlab ~]# systemctl start postfix
[root@cicd-gitlab ~]# systemctl enable postfix
4、关闭 SELinux
[root@cicd-gitlab ~]# sed -ri '/SELINUX=/cSELINUX=disabled' /etc/selinux/config
[root@cicd-gitlab ~]# setenforce 0 # 临时关闭SELinux
[root@cicd-gitlab ~]# reboot #修改完毕之后重启生效
5、添加 hosts
[root@cicd-gitlab ~]# vim /etc/hosts
192.168.152.150 gitlab.qfedu.com
部署gitlab
安装依赖包
[root@cicd-gitlab ~]# yum install -y curl openssh-server openssh-clients postfix cronie policycoreutils-python
# gitlab-ce 10.x.x以后的版本需要依赖policycoreutils-python
添加源
这里添加的清华源,也可以使用别的源
[root@cicd-gitlab ~]# vim gitlab-ce.repo
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
[root@cicd-gitlab ~]# vim gitlab-ee.repo
[gitlab-ee]
name=Gitlab EE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ee/yum/el$releasever/
gpgcheck=0
enabled=1
阿里源
[root@cicd-gitlab ~]# vim /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
Repo_gpgcheck=0
Enabled=1
Gpgkey=https://packages.gitlab.com/gpg.key
添加官方源
[root@cicd-gitlab ~]# vim runner_gitlab-ci-multi-runner.repo
[runner_gitlab-ci-multi-runner]
name=runner_gitlab-ci-multi-runner
baseurl=https://packages.gitlab.com/runner/gitlab-ci-multi-runner/el/7/$basearch
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/runner/gitlab-ci-multi-runner/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
[runner_gitlab-ci-multi-runner-source]
name=runner_gitlab-ci-multi-runner-source
baseurl=https://packages.gitlab.com/runner/gitlab-ci-multi-runner/el/7/SRPMS
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/runner/gitlab-ci-multi-runner/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
任选一种即可,千万不要都加上哦
安装gitlab(根据需要选择 ce/ee)
[root@cicd-gitlab ~]# yum -y install gitlab-ce # # 自动安装最新版
[root@cicd-gitlab ~]# yum -y install gitlab-ce-x.x.x # 安装指定版本Gitlab
[root@cicd-gitlab ~]# yum -y install gitlab-ce
warning: gitlab-ce-13.1.3-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:gitlab-ce-13.1.3-ce.0.el7 ################################# [100%]
It looks like GitLab has not been configured yet; skipping the upgrade script.
*. *.
*** ***
***** *****
.****** *******
******** ********
,,,,,,,,,***********,,,,,,,,,
,,,,,,,,,,,*********,,,,,,,,,,,
.,,,,,,,,,,,*******,,,,,,,,,,,,
,,,,,,,,,*****,,,,,,,,,.
,,,,,,,****,,,,,,
.,,,***,,,,
,*,.
_______ __ __ __
/ ____(_) /_/ / ____ _/ /_
/ / __/ / __/ / / __ `/ __ \
/ /_/ / / /_/ /___/ /_/ / /_/ /
\____/_/\__/_____/\__,_/_.___/
Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
sudo gitlab-ctl reconfigure
For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
查看版本
[root@cicd-gitlab ~]# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce-13.1.3
配置文件登录的链接
#设置登录链接
[root@cicd-gitlab ~]# vim /etc/gitlab/gitlab.rb
***
## GitLab URL
##! URL on which GitLab will be reachable.
##! For more details on configuring external_url see:
##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
# 没有域名,可以设置为本机IP地址
external_url 'http://192.168.152.142'
***
[root@cicd-gitlab ~]# grep "^external_url" /etc/gitlab/gitlab.rb
external_url 'http://192.168.152.142' #绑定监听的域名或IP
初始化配置
[root@cicd-gitlab ~]# gitlab-ctl reconfigure
..... #命令行工具,操控命令行
启动 Gitlab 服务
[root@cicd-gitlab ~]# gitlab-ctl start #启动服务,出来下面的信息,证明已经成功启动
ok: run: gitaly: (pid 22896) 2922s
ok: run: gitlab-monitor: (pid 22914) 2921s
ok: run: gitlab-workhorse: (pid 22882) 2922s
ok: run: logrotate: (pid 22517) 2987s
ok: run: nginx: (pid 22500) 2993s
ok: run: node-exporter: (pid 22584) 2974s
ok: run: postgres-exporter: (pid 22946) 2919s
ok: run: postgresql: (pid 22250) 3047s
ok: run: prometheus: (pid 22931) 2920s
ok: run: redis: (pid 22190) 3053s
ok: run: redis-exporter: (pid 22732) 2962s
ok: run: sidekiq: (pid 22472) 3005s
ok: run: unicorn: (pid 22433) 3011s
[root@cicd-gitlab ~]# lsof -i:80 #来查看端口
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 22500 root 7u IPv4 50923 0t0 TCP *:http (LISTEN)
nginx 22501 gitlab-www 7u IPv4 50923 0t0 TCP *:http (LISTEN)
gitlab常用的命令
[root@cicd-gitlab ~]# gitlab-ctl start # 启动所有 gitlab 组件;
[root@cicd-gitlab ~]# gitlab-ctl stop # 停止所有 gitlab 组件;
[root@cicd-gitlab ~]# gitlab-ctl restart # 重启所有 gitlab 组件;
[root@cicd-gitlab ~]# gitlab-ctl status # 查看服务状态;
[root@cicd-gitlab ~]# gitlab-ctl reconfigure # 初始化服务;
[root@cicd-gitlab ~]# vim /etc/gitlab/gitlab.rb # 修改默认的配置文件;
[root@cicd-gitlab ~]# gitlab-ctl tail # 查看日志;
Gitlab 命令行修改密码
[root@cicd-gitlab ~]# gitlab-rails console production
irb(main):001:0>user = User.where(id: 1).first # id为1的是超级管理员 system 系统
irb(main):002:0>user.password = 'yourpassword' # 密码必须至少8个字符
irb(main):003:0>user.save! # 如没有问题 返回true
exit # 退出
登录gitlab
端口启动之后便在网页访问
- 在浏览器中输入 http://192.168.152.148 ,然后 change password: ,并使用root用户登录 即可 (后续动作根据提示操作)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fxv0co5J-1601300407540)(/home/afang/文档/第三阶段/第三天 分布式版本控制系统 CICD详解/assets/1.png)]
2、修改默认端口
- 如果需要手工修改nginx的port ,可以在gitlab.rb中设置 nginx[‘listen_port’] = 8000 ,然后再次 gitlab-ctl reconfigure即可
- 登录 gitlab 如下所示(首次登陆设置 root 密码):
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-dMsY9iL9-1601300407544)(/home/afang/文档/第三阶段/第三天 分布式版本控制系统 CICD详解/assets/2.1.png)]
3、设置中文
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-kAzOBqzg-1601300407546)(/home/afang/文档/第三阶段/第三天 分布式版本控制系统 CICD详解/assets/1-1594452411919.png)]
访问成功之后,就部署成功了