CentOS7安装 Gitlab

一、准备工作

1.1安装必要的工具
yum install -y wget vim net-tools git

1.2更换阿里yum

1
2
3
mv /etc/yum.repos.d /etc/yum.repos.d.backup
mkdir /etc/yum.repos.d
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

1.3重建缓存

1
2
yum clean all
yum makecache

二、下载gitlab汉化包

2.1克隆汉化版本库
git clone https://gitlab.com/xhang/gitlab.git
2.2查看汉化补丁版本
cat gitlab/VERSION

三、安装gitlab社区版

3.1安装依赖包
yum install -y curl openssh-server openssh-clients cronie policycoreutils-python
如果要在本机启动邮件服务,可以安装‘postfix’
3.2获取gitlab的rpm包并安装
下载和刚汉化包相同版本的额rpm包

1
2
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.3.6-ce.0.el7.x86_64.rpm
rpm -i gitlab-ce-11.3.6-ce.0.el7.x86_64.rpm

按提示修改配置文件
vim /etc/gitlab/gitlab.rb
external_url ‘http://192.168.100.152'
3.3查看gitlab版本
head -1 /opt/gitlab/version-manifest.txt

四、汉化包覆盖

4.1 停止服务并备份文件

1
2
3
gitlab-ctl stop
mkdir /home/bak
cp -r /opt/gitlab/embedded/service/gitlab-rails/* /home/bak/

4.2 去掉cp默认的-i属性,并覆盖

1
2
unalias cp
cp -rf /root/gitlab/* /opt/gitlab/embedded/service/gitlab-rails/

4.3 重新配置,并启动

1
2
gitlab-ctl reconfigure
gitlab-ctl restart

4.4 登录gitlab
http://192.168.100.152

五、配置LDAP

5.1修改配置文件
vim /etc/gitlab/gitlab.rb
gitlab_rails['ldap_enabled'] = true

取消以下内容的注释

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
main: # 'main' is the GitLab 'provider ID' of this LDAP server
label: 'LDAP'
host: '_your_ldap_server'
port: 389
uid: 'sAMAccountName'
bind_dn: '_the_full_dn_of_the_user_you_will_bind_with'
password: '_the_password_of_the_bind_user'
encryption: 'plain' # "start_tls" or "simple_tls" or "plain"
verify_certificates: true
active_directory: true
allow_username_or_email_login: false
lowercase_usernames: false
block_auto_created_users: false
base: ''
user_filter: ''
## EE only
group_base: ''
admin_group: ''
sync_ssh_keys: false

ps:后面还有一个EOF需要取消注释,不要漏掉。

代入自己的LDAP配置

5.2 重新加载配置文件,重启gitlab

1
2
gitlab-ctl reconfigure
gitlab-ctl restart

六、添加邮件回复功能

6.1 找到配置文件,并取消注释

vim /etc/gitlab/gitlab.rb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
### GitLab email server settings
###! Docs: https://docs.gitlab.com/omnibus/settings/smtp.html
###! **Use smtp instead of sendmail/postfix.**

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "your_email_address"
gitlab_rails['smtp_password'] = "your_email_passwd"
gitlab_rails['smtp_domain'] = "exmail.qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = "your_email_address"
gitlab_rails['gitlab_email_display_name'] = 'Gitlab'

重新加载配置文件,重启gitlab

6.2 测试发送邮件

1
2
3
gitlab-rails console

Notify.test_email('to_email_address', '邮件标题', '邮件正文').deliver_now

0%