1.环境准备
cat /etc/redhat-release
uname -r
ntpdate -u ntp.api.bz
#下载epel源
wget http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
#关闭 NetworkManager与防火墙
systemctl stop firewalld.service
systemctl disable firewalld
systemctl disable NetworkManager
#关闭SELinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
grep SELINUX=disabled /etc/selinux/config
setenforce 0
getenforce
2.Gitlab安装
yum install curl policycoreutils openssh-server openssh-clients postfix -y
systemctl start postfix
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
yum install -y gitlab-ce
#建议使用国内镜像源
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
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
yum makecache
yum install -y gitlab-ce
#安装Git客户端
yum install -y git
3.配置Gitlab并设置SMTP服务器
#修改配置文件vim /etc/gitlab/gitlab.rb定义SMTP参数
gitlab_rails['gitlab_email_from'] = 'xxx@weizhi.com'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "xxx@weizhi.com"
gitlab_rails['smtp_password'] = "xxx"
gitlab_rails['smtp_domain'] = "qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
user["git_user_email"] = "xxx@weizhi.com"
#保存退出,配置执行gitlab-ctl reconfigure启动
#第一次启动过程会比较长,耐心等待即可!
#查看版本
[root@node1 ~]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
11.11.0
#查看Gitlab状态及80端口有无被占用
[root@node1 ~]# gitlab-ctl status
run: alertmanager: (pid 5037) 1746s; run: log: (pid 1331) 3177s
run: gitaly: (pid 1297) 3177s; run: log: (pid 1296) 3177s
run: gitlab-monitor: (pid 1325) 3177s; run: log: (pid 1324) 3177s
run: gitlab-workhorse: (pid 1323) 3177s; run: log: (pid 1322) 3177s
run: logrotate: (pid 1328) 3177s; run: log: (pid 1321) 3177s
run: nginx: (pid 1304) 3177s; run: log: (pid 1303) 3177s
run: node-exporter: (pid 1327) 3177s; run: log: (pid 1320) 3177s
run: postgres-exporter: (pid 1334) 3177s; run: log: (pid 1333) 3177s
run: postgresql: (pid 1315) 3177s; run: log: (pid 1312) 3177s
run: prometheus: (pid 1332) 3177s; run: log: (pid 1330) 3177s
run: redis: (pid 1316) 3177s; run: log: (pid 1305) 3177s
run: redis-exporter: (pid 1311) 3177s; run: log: (pid 1310) 3177s
run: sidekiq: (pid 4834) 1784s; run: log: (pid 1298) 3177s
run: unicorn: (pid 5210) 1724s; run: log: (pid 1313) 3177s
[root@node1 ~]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 1304 root 7u IPv4 20005 0t0 TCP *:http (LISTEN)
nginx 1425 gitlab-www 7u IPv4 20005 0t0 TCP *:http (LISTEN)
nginx 1426 gitlab-www 7u IPv4 20005 0t0 TCP *:http (LISTEN)
nginx 1427 gitlab-www 7u IPv4 20005 0t0 TCP *:http (LISTEN)
nginx 1428 gitlab-www 7u IPv4 20005 0t0 TCP *:http (LISTEN)
#常用命令:
关闭gitlab:gitlab-ctl stop
启动gitlab:gitlab-ctl start
重启gitlab:gitlab-ctl restart
重载配置文件: gitlab-ctl reconfigure
4.测试发送邮件验证SMTP配置是否正确,执行
[root@node1 ~]# gitlab-rails console
-------------------------------------------------------------------------------------
GitLab: 11.11.0 (3e8ca2fb781)
GitLab Shell: 9.1.0
PostgreSQL: 9.6.11
-------------------------------------------------------------------------------------
Loading production environment (Rails 5.1.7)
irb(main):001:0> Notify.test_email('xxx@weizhi.com','Testmail','test').deliver_now
Notify#test_email: processed outbound mail in 527.8ms
Sent mail to xxx@weizhi.com (2331.8ms)
Date: Fri, 31 May 2019 15:57:01 +0800
From: GitLab <xxx@weizhi.com>
Reply-To: GitLab <noreply@gitlab.example.com>
To: xxx@weizhi.com
Message-ID: <5cf0de4d5990d_36ed3feb289d65f4702b3@node1.mail>
Subject: Testmail
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>test</p></body></html>
=> #<Mail::Message:70278862421960, Multipart: false, Headers: <Date: Fri, 31 May 2019 15:57:01 +0800>, <From: GitLab <xxx@weizhi.com>>, <Reply-To: GitLab <noreply@gitlab.example.com>>, <To: xxx@weizhi.com>, <Message-ID: <5cf0de4d5990d_36ed3feb289d65f4702b3@node1.mail>>, <Subject: Testmail>, <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):002:0>
#发送成功
#访问并设置账号密码
root
admin@example.com