1. 使用清华镜像源配置yum源:

  vim /etc/yum.repos.d/gitlab.repo 

[Gitlab-CE]
name=Gitlab CE
baseurl=https://mirror.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/
enabled=1
gpgcheck=0

2. yum安装

 yum install gitlab-ce -y

3. gitlab配置(/opt/gitlab/gitlab.rb)

external_url ' #配置服务器IP地址或域名

#配置e-mail
gitlab_rails['time_zone'] = 'UTC'
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '[email protected]'
gitlab_rails['gitlab_email_display_name'] = 'APICloud_Gitlab'
gitlab_rails['gitlab_email_reply_to'] = '[email protected]' 

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "[email protected]"
gitlab_rails['smtp_password'] = "nxgfvizafijytymx"
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false


gitlab_ci['smtp_enable'] = true
gitlab_ci['smtp_address'] = "smtp.163.com"
gitlab_ci['smtp_port'] = 25
gitlab_ci['smtp_user_name'] = "[email protected]"
gitlab_ci['smtp_password'] = "nxgfvizafijytymx"
gitlab_ci['smtp_domain'] = "163.com"
gitlab_ci['smtp_authentication'] = "login"
gitlab_ci['smtp_enable_starttls_auto'] = true

4. gitlab命令

  1. 重置配置,使修改生效

gitlab-ctl reconfigure

b. 登录测试

Username: root (管理员账号)
Password: 5iveL!fe

c. 解决gitlab默认头像不能正常显示的问题

gitlab_rails['gravatar_plain_url'] = 'http://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon'
gitlab_rails['gravatar_ssl_url'] = 'https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon'

5. 开机自启动脚本设置

vim /opt/startGitlab.sh
==========================
#! /bin/bash 
sudo lokkit -s http -s ssh
==========================
echo "/opt/startGitlab.sh" >> vim  /etc/rc.d/rc.local
================================================

6. 数据备份与恢复

数据备份及恢复命令:
备份path:/var/opt/gitlab/backups (备份和恢复文件都是git用户)
数据备份:gitlab-rake gitlab:backup:create
数据恢复:gitlab-rake gitlab:backup:restore

使用Gitlab一键安装包后的日常备份恢复与迁移 https://segmentfault.com/a/1190000002439923

创建备份:gitlab-rake gitlab:backup:create
恢复备份:
# 停止相关数据连接服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
# 从1393513186编号备份中恢复
gitlab-rake gitlab:backup:restore BACKUP=1393513186
# 启动Gitlab
sudo gitlab-ctl start

7. 参考链接:

http://swht1278.blog.51cto.com/7138082/1643939


8. gitlab9.2维护参考 

gitlab不能正常备份:

[root@tools-gitlab gitlab_backups]# /usr/bin/gitlab-rake  gitlab:backup:createDumping database ... 
Dumping PostgreSQL database gitlabhq_production ... pg_dump: [archiver (db)] connection to database "gitlabhq_production" failed: FATAL:  remaining connection slots are reserved for non-replication superuser connections
[FAILED]
Backup failed
https://blog.51cto.com/yanconggod/2062591

9. gitlab-ce白名单设置杜绝并发数过大引起的封ip故障 

参考:https://cloud.tencent.com/developer/article/1115119 

grep -C 5 'ip_whitelist' /etc/gitlab/gitlab.rb
# gitlab_rails['rate_limit_requests_per_period'] = 10
# gitlab_rails['rate_limit_period'] = 60
gitlab_rails['rack_attack_git_basic_auth'] = {
   'enabled' => true,
   'ip_whitelist' => ["127.0.0.1","192.168.101.219"],
   'maxretry' => 300,
   'findtime' => 5,
   'bantime' => 60
 }

10.gitlab批量创建用户的脚本:

[root@gitlab ~]# cat gitlab.sh
#!/bin/bash
#批量创建gitlab用户
userinfo="userinfo.text"
while read line
do
    password=`echo $line | awk '{print $1}'`
    mail=`echo $line | awk '{print $2}'`
    username=`echo $line | awk '{print $3}'`
    name=`echo $line | awk '{print $4}'`
    curl -d "reset_password=$password&email=$mail&username=$username&name=$name&private_token=ucUctguWU6-2qrvRnGiB" "http://192.168.1.24/api/v4/users"
 
done <$userinfo
 
[root@gitlab ~]# cat userinfo.text
1  [email protected] zhanjiang.feng zhanjiang.feng
1  [email protected] hongkang.yan hongkang.yan
1  [email protected] yansong.wang yansong.wang
1  [email protected] bo.xue bo.xue
1  [email protected] junlong.li junlong.li
1  [email protected] luyu.cao luyu.cao
1  [email protected] xueqing.wang xueqing.wang
1  [email protected] xu.guo xu.guo
1  [email protected] bing.xing bing.xing
1  [email protected] linan linan