Gitlab是开发中一个重要的工具,本文整理Gitlab部署过程,方便未来查阅。
0 初始化机器
推荐RAM 8GB以上。
1 增加至少4GB swap
1 2 3 4 5 6 7 8 9 10 11
| dd if=/dev/zero of=/swapfile bs=4M count=1024 chmod 600 /swapfile mkswap /swapfile swapon /swapfile
swapon -s
echo '/swapfile none swap sw 0 0' >> /etc/fstab
|
2 挂载数据盘,建议nfsv4
1 2
| sudo mount -t nfs -o vers=4.0,noresvport 10.0.0.1:/ /gitlabdata echo '10.0.0.1:/ /gitlabdata nfs vers=4.0,noresvport 0 0' >> /etc/fstab
|
3 修改ssh端口号,防止端口冲突
1 2 3 4 5
| vi /etc/ssh/sshd_config
reboot
|
4 docker跑gitlab-ce
1 2 3 4 5 6 7 8 9 10 11 12
| GITLAB_HOME="/gitlabdata" docker run --detach --hostname git.xxx.com \ --env GITLAB_OMNIBUS_CONFIG="external_url 'http://git.xxx.com'" \ --env TZ="Asia/Shanghai" -v /etc/localtime:/etc/localtime \ --publish 443:443 --publish 80:80 --publish 22:22 --publish 5050:5050 \ --name gitlab --restart always --volume $GITLAB_HOME/config:/etc/gitlab:Z \ --volume $GITLAB_HOME/logs:/var/log/gitlab:Z --volume $GITLAB_HOME/data:/var/opt/gitlab:Z \ --shm-size 1024m gitlab/gitlab-ce:17.2.1-ce.0
docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password
|
5 开启ssl
1 2 3 4 5 6 7 8 9 10
| # 使用let's encrypt签证书 vi /gitlabdata/gitlab/config/gitlab.rb
#修改 external_url 为 htts://xxx.xxx.com 自定义域名 #letsencrypt['enable'] = true #letsencrypt['auto_renew'] = true #letsencrypt['auto_renew_hour'] = 120
应用配置 docker exec -t gitlab gitlab-ctl reconfigure
|
5 配置container registry
配置CR域名指向gitlab机器,修改配置。
1 2 3 4
| registry_external_url 'https://gcr.xxx.xxx' gitlab_rails[registry_enable'] = true gitlab_rails[registry_host'] = 'gcr.xxx.xxx' gitlab_rails[registry_port'] = 443
|
应用配置
1
| docker exec -t gitlab gitlab-ctl reconfigure
|
完结
至此,Gitlab部署完成。