一、环境准备

1、设置hostName 
# hostnamectl set-hostname gitServer
2、配置Host
# echo "127.0.0.1 gitServer.xx.cn" >> /etc/hosts

### gitServer.xx.cn为你的生产环境域名
3、安装依赖文件
# yum install -y curl policycoreutils-python openssh-server hostname tree
4、安装Postfix
# yum install postfix

#### 启动postfix服务
# systemctl enable postfix
# systemctl start postfix

二、安装yum源

# curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash

三、安装GitLab-CE

# EXTERNAL_URL="http://gitServer.xx.cn" yum install -y gitlab-ee
Running handlers:
Running handlers complete
Chef Client finished, 456/678 resources updated in 03 minutes 20 seconds
gitlab Reconfigured!

       *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.



     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/


Thank you for installing GitLab!

四、配置gitlab.rb

1、SMTP配置
### 编辑gitlab.rb文件,在最后添加以下信息

# vim /etc/gitlab/gitlab.rb
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.xx.cn" #你邮箱的SMTP地址
gitlab_rails['smtp_port'] = 465	#你邮箱的SMTP端口
gitlab_rails['smtp_user_name'] = "你的邮箱"
gitlab_rails['smtp_password'] = "你的邮箱密码"
gitlab_rails['smtp_domain'] = "exmail.xx.cn"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = '你的邮箱'
2、禁用创建组权限
# vim /etc/gitlab/gitlab.rb
gitlab_rails['gitlab_default_can_create_group'] = false
3、配置GitLab数据存储位置
# vim /etc/gitlab/gitlab.rb
git_data_dirs({
   "default" => {
     "path" => "/data/tools/gitlab/data"
    }
})
4、重载配置
# gitlab-ctl reconfigure

五、优化项(可选配置)

1、GitLab备份路径修改
# vim /etc/gitlab/gitlab.rb
####设置备份文件的保存位置
gitlab_rails['backup_path'] = "/export/gitlab/backup"

#设置备份文件的过期时间,单位为秒,默认7天
gitlab_rails['backup_keep_time'] = 604800

# gitlab-ctl reconfigure
2、验证备份路径是否生效
# gitlab-rake gitlab:backup:create
3、自动备份
#### 方法1:
# crontab -e
2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1 
 
#### 方法2:
# echo "2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1" >>/etc/crontab
4、解决gitlab-ctl reconfigure时报卡死的问题
####先启动基础服务:
# /opt/gitlab/embedded/bin/runsvdir-start &

####再启动:
# gitlab-ctl reconfigure
5、解决启动时报错:/etc/sysctl.conf not found
# touch /etc/sysctl.conf
6、解决alertmanager服务无法启动问题
# vim /etc/gitlab/gitlab.rb
alertmanager['flags'] = {
    'cluster.advertise-address' => "127.0.0.1:9093",
    'web.listen-address' => "127.0.0.1:9093",
    'storage.path' => "/var/opt/gitlab/alertmanager/data",
    'config.file' => "/var/opt/gitlab/alertmanager/alertmanager.yml"
}
7、解决页面或API访问时500或502的问题
# vim /etc/gitlab/gitlab.rb

puma['worker_timeout'] = 30
gitlab_rails['time_zone'] = 'Asia/Shanghai'
puma['worker_processes'] = 2
postgresql['shared_buffers'] = "256MB"
sidekiq['max_concurrency'] = 8
postgresql['max_worker_processes'] = 4
puma['per_worker_max_memory_mb'] = 600
prometheus_monitoring['enable'] = false
sidekiq['min_concurrency'] = 8
8、第一次启动的密码
# cat /etc/gitlab/initial_root_password

六、访问:

浏览器里输入:http://gitServer.xx.cn

七、最后附上常用命令

命令

说明

check-config

检查在gitlab中是否有任何配置。在指定版本中删除的rb

deploy-page

安装部署页面

diff-config

将用户配置与包可用配置进行比较

remove-accounts

删除所有用户和组

upgrade

升级

service-list

查看所有服务

once

如果GitLab服务停止了就启动服务,如果已启动就不做任何操作

restart

重启GitLab服务

start

如果GitLab服务停止了就启动服务,如果已启动就重启服务

stop

停止GitLab服务

status

查看GitLab服务状态

reconfigure

reconfigure重新配置GitLab并启动

官方部署文档https://gitlab.cn/install/

后续操作参考官方文档:https://docs.gitlab.cn/jh/install/next_steps.html