文章目录
测试系统CentOS6.9,IP地址192.168.0.80
源码编译需要很多依赖,很容易出错,此处直接选择rpm包方式安装
官方地址:https://about.gitlab.com/downloads
中文网站地址:https://www.gitlab.com.cn/downloads
Gitlab安装 {#title-0}
安装所需依赖
yum -y install openssh-server cronie git wget patch
|---|-----------------------------------------------------| | 1 | yum -y install openssh-server cronie git wget patch |
关闭防火墙,关闭selinux(或者自行开放相应端口lokkit -s http -s ssh)
service iptables stop setenforce 0
|-----|------------------------------------| | 1 2 | service iptables stop setenforce 0 |
下载所需rpm包
cd /usr/src/ wget https://mirror.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/gitlab-ce-9.1.3-ce.0.el6.x86_64.rpm rpm -ivh gitlab-ce-9.1.3-ce.0.el6.x86_64.rpm
|-------|----------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 | cd /usr/src/ wget https://mirror.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/gitlab-ce-9.1.3-ce.0.el6.x86_64.rpm rpm -ivh gitlab-ce-9.1.3-ce.0.el6.x86_64.rpm |
注意:此处如果不是gitlab: GitLab should be reachable at http://gitlab.example.com这句的话,可能会在初始化时有问题,可以修改/etc/gitlab/gitlab.rb文件,改成external_url 'http://gitlab.example.com'然后在进行初始化
初始化gitlab
gitlab-ctl reconfigure
|---|------------------------| | 1 | gitlab-ctl reconfigure |
查看服务
gitlab-ctl status
|---|-------------------| | 1 | gitlab-ctl status |
重启、停止或启动服务
gitlab-ctl restart/stop/start
|---|-------------------------------| | 1 | gitlab-ctl restart/stop/start |
配置文件目录
/etc/gitlab/gitlab.rb
安装完成,可以通过浏览器访问IP测试(如访问不了,请检查iptables、selinux)
http://192.168.0.80
首次访问Gitlab需要设置管理员密码,设置成功后会返回登录页面,默认管理员帐号是root,如果想更改默认管理员帐号,需要进入系统后修改帐号名。
Gitlab汉化 {#title-1}
Gitlab中文社区版地址:https://gitlab.com/xhang/gitlab
感谢汉化项目发起人@larryli,感谢@xhang继续汉化本项目
先确认当前Gitlab版本
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
|---|-------------------------------------------------------| | 1 | cat /opt/gitlab/embedded/service/gitlab-rails/VERSION |
克隆版本库(我在这里克隆时大概用了20分钟)
cd /usr/src/ git clone https://gitlab.com/xhang/gitlab.git
|-----|------------------------------------------------------------| | 1 2 | cd /usr/src/ git clone https://gitlab.com/xhang/gitlab.git |
比较原标签和汉化标签,导出patch用的diff文件
cd gitlab/ git diff v9.1.0 v9.1.0-zh > ../9.1.0-zh.diff
|-----|----------------------------------------------------------| | 1 2 | cd gitlab/ git diff v9.1.0 v9.1.0-zh > ../9.1.0-zh.diff |
先停止gitlab
gitlab-ctl stop
|---|-----------------| | 1 | gitlab-ctl stop |
上传9.1.0-zh.diff文件到服务器
patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < ../9.1.0-zh.diff
|---|----------------------------------------------------------------------------| | 1 | patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < ../9.1.0-zh.diff |
然后启动gitlab
gitlab-ctl start
|---|------------------| | 1 | gitlab-ctl start |
此时访问http://192.168.0.80就是全中文页面了
Gitlab邮件配置 {#title-2}
Gitlab邮件功能是必须配置的一块,提供代码提交提醒,用户密码找回等功能,Gitlab也提供了几种邮件配置的方案,sendmail、postfix及smtp,本篇文章所使用的是smtp(sendmail太老了,几乎都被postfix替代了),smtp配置起来比postfix方便,当然怎么方便怎么来了。
修改邮件配置
gitlab中文文档SMTP设置:https://docs.gitlab.com.cn/omnibus/settings/smtp.html
vim /etc/gitlab/gitlab.rb
|---|---------------------------| | 1 | vim /etc/gitlab/gitlab.rb |
修改以下内容
external_url 'http://gitlab.example.com' # gitlab_rails['smtp_enable'] = true # gitlab_rails['smtp_address'] = "smtp.server" # gitlab_rails['smtp_port'] = 465 # gitlab_rails['smtp_user_name'] = "smtp user" # gitlab_rails['smtp_password'] = "smtp password" # gitlab_rails['smtp_domain'] = "example.com" # gitlab_rails['smtp_authentication'] = "login" # gitlab_rails['smtp_enable_starttls_auto'] = true # gitlab_rails['smtp_tls'] = false
|----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 | external_url 'http://gitlab.example.com' # gitlab_rails['smtp_enable'] = true # gitlab_rails['smtp_address'] = "smtp.server" # gitlab_rails['smtp_port'] = 465 # gitlab_rails['smtp_user_name'] = "smtp user" # gitlab_rails['smtp_password'] = "smtp password" # gitlab_rails['smtp_domain'] = "example.com" # gitlab_rails['smtp_authentication'] = "login" # gitlab_rails['smtp_enable_starttls_auto'] = true # gitlab_rails['smtp_tls'] = false |
改成
external_url 'http://192.168.0.80' gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.qq.com" gitlab_rails['smtp_port'] = 465 gitlab_rails['smtp_user_name'] = "54321@qq.com" gitlab_rails['smtp_password'] = "腾讯邮箱授权码" gitlab_rails['smtp_domain'] = "qq.com" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = true
|----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 | external_url 'http://192.168.0.80' gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.qq.com" gitlab_rails['smtp_port'] = 465 gitlab_rails['smtp_user_name'] = "54321@qq.com" gitlab_rails['smtp_password'] = "腾讯邮箱授权码" gitlab_rails['smtp_domain'] = "qq.com" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = true |
注意:这里用的腾讯邮箱,所以smtp_tls必须是true,否则SSL握手失败,邮件发送失败
修改gitlab配置的发件人,此处最好把帐号和发件人都配置了,并保持一致,以免出现问题
gitlab_rails['gitlab_email_from'] = '54321@qq.com' user['git_user_email'] = "54321@qq.com"
|-----|------------------------------------------------------------------------------------------------| | 1 2 | gitlab_rails['gitlab_email_from'] = '54321@qq.com' user['git_user_email'] = "54321@qq.com" |
修改完成后,需要重新加载配置并重启
gitlab-ctl reconfigure gitlab-ctl restart
|-----|-------------------------------------------| | 1 2 | gitlab-ctl reconfigure gitlab-ctl restart |
Gitlab邮件测试 {#title-3}
测试SMTP配置是否成功
配置完成后可以用Rails控制台验证邮件是否能发送成功。 在GitLab服务器上,执行gitlab-rails console进入控制台。 然后在控制台提示符后输入下面的命令发送一封测试邮件:
irb(main):001:0> Notify.test_email('123456@qq.com', 'Message Subject', 'Message Body').deliver_now
|---|-----------------------------------------------------------------------------------------------------| | 1 | irb(main):001:0> Notify.test_email('123456@qq.com', 'Message Subject', 'Message Body').deliver_now |
示例: