企业级CICD环境搭建-Centos 部署Gitlab

一、Gitlab Server 部署
1、环境配置

关闭防火墙、SELinux
setenforce 0
sed -i 's/enforcing/disabled/g' /etc/selinux/config   
 
开启邮件服务
[root@qfedu.com ~]# systemctl start  postfix
[root@qfedu.com ~]# systemctl enable postfix

2、部署 Gitlab

# 安装 gitlab 依赖包
centos7:
[root@qfedu.com ~]# yum install -y curl openssh-server openssh-clients postfix cronie policycoreutils-python
# gitlab-ce 10.x.x以后的版本需要依赖policycoreutils-python

centos8:
[root@qfedu.com ~]# yum install -y curl openssh-server openssh-clients postfix cronie  policycoreutils-python-utils

# 添加官方源
[root@qfedu.com ~]# curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

# 因为官方源太慢,可以使用国内清华yum源,配置如下
[root@qfedu.com ~]# vim /etc/yum.repos.d/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

3、安装 Gitlab

[root@qfedu.com ~]# yum -y install gitlab-ce # 自动安装最新版
[root@qfedu.com ~]# yum -y install gitlab-ce-x.x.x # 安装指定版本Gitlab

4、配置 Gitlab

# 查看Gitlab版本
[root@qfedu.com ~]# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce 10.1.1

# Gitlab 配置登录链接
#设置登录链接
[root@qfedu.com ~]# 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://172.17.0.61'
***
[root@qfedu.com ~]# grep "^external_url" /etc/gitlab/gitlab.rb
external_url 'http://172.17.0.61'     #绑定监听的域名或IP

5、初始化 Gitlab

**配置语言环境**

gitlab要求语言环境为英文环境,必须切换,切换方法如下:
注意:可以先尝试以下方案
    语言环境问题:如果碰到之后的解决方案如下,需要重新登录
    [root@wing ~]# echo "export LC_ALL=en_US.UTF-8"  >>  /etc/profile 

如果上面的方案不可以,再使用下面的方案:    
# yum install langpacks-zh_CN langpacks-en langpacks-en_GB -y
# cat > /etc/profile.d/locale.sh<<-EOF
 export LANG=en_US.UTF-8
 export LANGUAGE=en_US.UTF-8
 export LC_COLLATE=C
 export LC_CTYPE=en_US.UTF-8
 EOF
# source /etc/profile.d/locale.sh

退出终端重新登陆

第一次使用配置时间较长

[root@qfedu.com ~]# gitlab-ctl reconfigure   

# 启动 Gitlab 服务
[root@qfedu.com ~]# 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

[git@qfedu.com ~]# 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)

6、Gitlab 设置 HTTPS 方式 (缺少配置)

– 如果想要以上的 https 方式正常生效使用,则需要把 letsencrypt 自动生成证书的配置打开,这样在执行重新让配置生效命令 (gitlab-ctl reconfigure) 的时候会自动给域名生成免费的证书并自动在 gitlab 自带的 nginx 中加上相关的跳转配置,都是全自动的,非常方便。

[root@qfedu.com ~]# vim /etc/gitlab/gitlab.rb
letsencrypt['enable'] = true //如果因为这行报错,改成false即可
letsencrypt['contact_emails'] = ['1001010086@qq.com'] # 添加联系人的电子邮件地址

7、Gitlab 添加smtp邮件功能

[git@qfedu.com ~]# vim /etc/gitlab/gitlab.rb
postfix 并非必须的;根据具体情况配置,以 SMTP 的为例配置邮件服务器来实现通知;参考配置如下: 
### Email Settings
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '1001010086@qq.com'
gitlab_rails['gitlab_email_display_name'] = 'gitlab'
gitlab_rails['gitlab_email_reply_to'] = '1001010086@qq.com'
gitlab_rails['gitlab_email_subject_suffix'] = '[gitlab]'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "1001010086@qq.com"
gitlab_rails['smtp_password'] = "kktohrvdryglbjjh" #这是我的qq邮箱授权码
gitlab_rails['smtp_domain'] = "smtp.qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true

#修改配置后需要初始化配置,先关掉服务再重新初始化
[git@qfedu.com ~]# gitlab-ctl stop
ok: down: gitaly: 0s, normally up
ok: down: gitlab-monitor: 1s, normally up
ok: down: gitlab-workhorse: 0s, normally up
ok: down: logrotate: 1s, normally up
ok: down: nginx: 0s, normally up
ok: down: node-exporter: 1s, normally up
ok: down: postgres-exporter: 0s, normally up
ok: down: postgresql: 0s, normally up
ok: down: prometheus: 0s, normally up
ok: down: redis: 0s, normally up
ok: down: redis-exporter: 1s, normally up
ok: down: sidekiq: 0s, normally up
ok: down: unicorn: 1s, normally up

[git@qfedu.com ~]# gitlab-ctl reconfigure  
......

[git@qfedu.com ~]# gitlab-ctl start
ok: run: gitaly: (pid 37603) 0s
ok: run: gitlab-monitor: (pid 37613) 0s
ok: run: gitlab-workhorse: (pid 37625) 0s
ok: run: logrotate: (pid 37631) 0s
ok: run: nginx: (pid 37639) 1s
ok: run: node-exporter: (pid 37644) 0s
ok: run: postgres-exporter: (pid 37648) 1s
ok: run: postgresql: (pid 37652) 0s
ok: run: prometheus: (pid 37660) 1s
ok: run: redis: (pid 37668) 0s
ok: run: redis-exporter: (pid 37746) 0s
ok: run: sidekiq: (pid 37750) 1s
ok: run: unicorn: (pid 37757) 0s

8、Gitlab 发送邮件测试

[git@qfedu.com ~]# gitlab-rails console 
[root@wing ~]# gitlab-rails console
---------------------------------------------------------------------
 GitLab:       12.10.1 (e658772bd63) FOSS
 GitLab Shell: 12.2.0
 PostgreSQL:   11.7
---------------------------------------------------------------------
Loading production environment (Rails 6.0.2)
irb(main):003:0> 
irb(main):004:0> Notify.test_email('1001010086@qq.com', 'Message Subject', 'Message Body').deliver_now  //输入测试命令,回车

Notify#test_email: processed outbound mail in 5.2ms
Delivered mail 5eafceaa250a_1d063fb777add9a08601a@wing.mail (1430.1ms)
Date: Mon, 04 May 2020 16:13:30 +0800
From: gitlab <1001010086@qq.com>
Reply-To: gitlab <1001010086@qq.com>
To: 1001010086@qq.com
Message-ID: <5eafceaa250a_1d063fb777add9a08601a@wing.mail>
Subject: Message Subject
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit
Auto-Submitted: auto-generated
X-Auto-Response-Suppress: All

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>Message Body</p></body></html>
=> #<Mail::Message:70056859616080, Multipart: false, Headers: <Date: Mon, 04 May 2020 16:13:30 +0800>, <From: gitlab <1001010086@qq.com>>, <Reply-To: gitlab <1001010086@qq.com>>, <To: 1001010086@qq.com>, <Message-ID: <5eafceaa250a_1d063fb777add9a08601a@wing.mail>>, <Subject: Message Subject>, <Mime-Version: 1.0>, <Content-Type: text/html; charset=UTF-8>, <Content-Transfer-Encoding: 7bit>, <Auto-Submitted: auto-generated>, <X-Auto-Response-Suppress: All>>
irb(main):005:0>

去qq邮箱web界面查看是否收到邮件

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容