GitLab
部署gitlab服务
##开启邮件服务
[root@master \~]# systemctl start postfix
[root@master \~]# systemctl enable postfix
##安装gitlab依赖包
[root@master \~]# yum install -y curl openssh-server openssh-clients postfix cronie policycoreutils-python
##添加清华源
[root@master \~]# cat /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
##安装gitlab
[root@master \~]# yum install -y gitlab-ce-10.1.1
##查看gitlab版本
[root@master \~]# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce 10.1.1
##设置gitlab登录链接
[root@master \~]# vim /etc/gitlab/gitlab.rb
[root@master \~]# grep "^external\_url" /etc/gitlab/gitlab.rb
external\_url 'http://192.168.200.30'
#初始化gitlab
##配置语言环境必须使用utf-8
[root@master \~]# echo "export LC\_ALL=en\_US.UTF-8" >> /etc/profile
[root@master \~]# source /etc/profile
###退出ssh重新链接
##初始
[root@master \~]# gitlab-ctl reconfigure
##启动gitlab服务
[root@master \~]# gitlab-ctl start
ok: run: alertmanager: (pid 14330) 84s
ok: run: gitaly: (pid 14222) 90s
ok: run: gitlab-exporter: (pid 14220) 90s
ok: run: gitlab-workhorse: (pid 14201) 92s
ok: run: grafana: (pid 14346) 83s
ok: run: logrotate: (pid 12946) 473s
ok: run: nginx: (pid 13504) 364s
ok: run: node-exporter: (pid 14212) 91s
ok: run: postgres-exporter: (pid 14337) 83s
ok: run: postgresql: (pid 13192) 450s
ok: run: prometheus: (pid 14237) 88s
ok: run: puma: (pid 13387) 388s
ok: run: redis: (pid 12987) 467s
ok: run: redis-exporter: (pid 14223) 90s
ok: run: sidekiq: (pid 13413) 382s
##查看80
[root@master \~]# netstat -ntpl | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:\* LISTEN 13504/nginx: master
以下是选用配置
如果想要以上的 https 方式正常生效使用,则需要把 letsencrypt 自动生成证书的配置打开,这样在执行重新让配置生效命令 (gitlab-ctl reconfigure) 的时候会自动给域名生成免费的证书并自动在 gitlab 自带的 nginx 中加上相关的跳转配置,都是全自动的,非常方便。
[root@qfedu.com \~]# vim /etc/gitlab/gitlab.rb
letsencrypt['enable'] = true //如果因为这行报错,改成false即可
letsencrypt['contact\_emails'] = ['276267003@qq.com'] # 添加联系人的电子邮件地址
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'] = '2865260231@qq.com'
gitlab\_rails['gitlab\_email\_display\_name'] = 'gitlab'
gitlab\_rails['gitlab\_email\_reply\_to'] = '2865260231@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'] = "2865260231@qq.com"
gitlab\_rails['smtp\_password'] = "pwxvuyuqcozndcie" #这是我的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
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('2865260231@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 <276267003@qq.com>
Reply-To: gitlab <276267003@qq.com>
To: 276267003@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 <276267003@qq.com>>, <Reply-To: gitlab <276267003@qq.com>>, <To: 276267003@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邮箱看看收到没有
gitlab修改密码
##修改gitlab的密码
[root@master \~]# gitlab-rails console -e productionLoading production environment (Rails 4.2.8)irb(main):001:0>
irb(main):002:0\*
irb(main):003:0\* user = User.where(id: 1).first ##管理用户id为1
=> #<User id:1 @root>
irb(main):004:0> user.password = 'youissbb' ##修改密码
=> "youissbb"
irb(main):005:0> user.save! ##保存
Enqueued ActionMailer::DeliveryJob (Job ID: d5ed2d52-f349-41f8-b0e0-32f2a8e90ac9) to Sidekiq(mailers) with arguments: "DeviseMailer", "password\_change", "deliver\_now", gid://gitlab/User/1
=> true
gitlab服务管理
gitlab-ctl start # 启动所有 gitlab 组件;
gitlab-ctl stop # 停止所有 gitlab 组件;
gitlab-ctl restart # 重启所有 gitlab 组件;
gitlab-ctl status # 查看服务状态;
gitlab-ctl reconfigure # 初始化服务;
vim /etc/gitlab/gitlab.rb # 修改默认的配置文件;
gitlab-ctl tail # 查看日志;