CentOS 7.5上安装 GitLab 最新版CE/EE
安装系统要求
参见:https://docs.gitlab.com/ee/install/requirements.html
前提准备
1.CentOS 7 服务器一台
2.域名一个(指向公网IP地址)
3.域名SSL证书一份
说明:以下所有操作都是root用户下,非root用户请自觉加sudo权限
由于安装过程下载的资源较大,推荐使用阿里云yum源:
- 使用vim查看yum源
vim /etc/yum.repos.d/CentOS-Base.repo
- 进入/etc/yum.repos.d文件夹
cd /etc/yum.repos.d
- 使用wget下载阿里云yum源至(如果没有wget,需要安装,命令:yum install wget)
wget http://mirrors.aliyun.com/repo/Centos-7.repo
- 备份原有yum源
mv CentOS-Base.repo CentOS-Base.repo.bak
- 复制阿里云yum源,名称为默认yum名称
cp Centos-7.repo CentOS-Base.repo
- 清理缓存
yum clean all
- 重新生成缓存
yum makecache
安装gitlab-ee/ce
- 安装并配置依赖
yum install curl policycoreutils-python openssh-server
systemctl enable sshd
systemctl start sshd
- 安装Postfix(用来发送通知电子邮件)
yum install postfix
systemctl enable postfix
systemctl start postfix
如果出现postfix报错【postfix: fatal: parameter inet_interfaces: no local interface found for ::1】
vi /etc/postfix/main.cf
- 发现配置为:
inet_interfaces = localhost
inet_protocols = all
- 改成:
inet_interfaces = all
inet_protocols = all
- 重新启动
service postfix start
- 添加GitLab软件包存储库
- 企业版最新版(gitlab-ee):https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
- 社区版最新版(gitlab-ce):https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
- 安装GitLab包(将
http://ip
作为您要访问GitLab的域名,安装过程将自动配置并启动该域名的GitLab)
- 企业版最新版(gitlab-ee):
EXTERNAL_URL="http://ip" yum install -y gitlab-ee
- 社区版最新版(gitlab-ce):
EXTERNAL_URL="http://ip" yum install -y gitlab-ce
- 指定版本GitLab安装
EXTERNAL_URL="http://ip" yum install -y gitlab-ce-11.5.0-ee.0.el7.x86_64
EXTERNAL_URL="http://ip" yum install -y gitlab-ce-11.5.0-ce.0.el7.x86_64
- 安装完成
查看运行状态
gitlab-ctl status
- 启动
gitlab-ctl start
- 停止
gitlab-ctl stop
- 重启
gitlab-ctl restart
- 查看版本
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
设置语言
- 浏览地址(http://ip)并登陆:
- 首次访问时,您将被重定向到密码重置页面,设置初始管理员帐户的密,使用默认帐户的用户名root登录
- 选择用户头像,点击Setting
- 选择Profile,将Preferred Language改成简体中文后保存
- 刷新页面
设置邮箱(以163.com为例)
- 在/etc/gitlab/gitlab.rb中新增
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "xxx@163.com"
gitlab_rails['smtp_password'] = "授权密码"
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = 'xxx@163.com'
gitlab_rails['gitlab_email_reply_to'] = 'xxx@163.com'
user['git_user_email'] = 'xxx@163.com'
- 重新配置
gitlab-ctl reconfigure
- 邮箱测试
[root@gitlab ~]# gitlab-rails console
-------------------------------------------------------------------------------------
GitLab: 11.5.0-ee (cb71fca)
GitLab Shell: 8.4.1
postgresql: 9.6.8
-------------------------------------------------------------------------------------
Both Deployment and its :status machine have defined a different default for "status". Use only one or the other for defining defaults to avoid unexpected behaviors.
Loading production environment (Rails 4.2.10)
irb(main):001:0> Notify.test_email('xxx@qq.com', '测试主题', '测试内容').deliver_now
Notify#test_email: processed outbound mail in 532.6ms
Sent mail to xxx@qq.com (701.4ms)
Date: Tue, 27 Nov 2018 15:35:41 +0800
From: GitLab <xxx@163.com>
Reply-To: GitLab <xxx@163.com>
To: xxx@qq.com
Message-ID: <5bfcf3cde285d_519a3f9e1c5daf6c11318@gitlab.mail>
Subject: =?UTF-8?Q?=E6=B5=8B=E8=AF=95=E9=82=AE=E4=BB=B6=E4=B8=BB=E9=A2=98?=
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: quoted-printable
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>=E6=B5=8B=E8=AF=95=E9=82=AE=E4=BB=B6=E5=86=85=E5=AE=B9</p>=
</body></html>
=> #<Mail::Message:69947957044360, Multipart: false, Headers: <Date: Tue, 27 Nov 2018 15:35:41 +0800>, <From: GitLab <xxx@163.com>>, <Reply-To: GitLab <xxx@163.com>>, <To: xxx@qq.com>, <Message-ID: <5bfcf3cde285d_519a3f9e1c5daf6c11318@gitlab.mail>>, <Subject: 测试主题>, <Mime-Version: 1.0>, <Content-Type: text/html; charset=UTF-8>, <Content-Transfer-Encoding: quoted-printable>, <Auto-Submitted: auto-generated>, <X-Auto-Response-Suppress: All>>
irb(main):002:0>
设置HTTPS
- 编辑/etc/gitlab/gitlab.rb
vim /etc/gitlab/gitlab.rb
- 发现配置为:
external_url 'http:/ip'
- 改成:
external_url 'https://www.xxx.com'
- 创建存放SSL证书的文件夹
mkdir /etc/gitlab/ssl
- 将预先准备的SSL证书上传到/etc/gitlab/ssl中
- 域名ip映射做好
- 编辑/etc/gitlab/gitlab.rb
此操作可以不做
- 发现配置为:
# nginx['redirect_http_to_https'] = false
# nginx['ssl_certificate'] = "/etc/gitlab/ssl/#{node['fqdn']}.crt"
# nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/#{node['fqdn']}.key"
- 改成:
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/gitlab/ssl/xxxx.pem"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/xxxx.key"
- 重新配置
gitlab-ctl reconfigure
- 重启
gitlab-ctl restart