Rocky9 GitLab Docker 部署

2024-07-25 361 0

环境准备

sed -e 's|^mirrorlist=|#mirrorlist=|g' \
    -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \
    -i.bak  /etc/yum.repos.d/rocky-*.repo
dnf makecache
setenforce 0
sed -i 's#^SELINUX=.*#SELINUX=disabled#' /etc/sysconfig/selinux
systemctl stop firewalld

部署Docker

curl -o /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
dnf install docker-ce

部署GitLab

[root@gitlab ~]# cat docker-compose.yaml 
version: '3.6'
services:
  gitlab:
    image: gitlab/gitlab-ce:latest
    container_name: gitlab
    restart: always
    hostname: 'gitlab'
    environment:
      TZ: 'Asia/Shanghai'
      GITLAB_OMNIBUS_CONFIG: |
        # Add any other gitlab.rb configuration here, each on its own line
        external_url 'http://git.sundayhk.com'
        gitlab_rails['gitlab_shell_ssh_port'] = 8022
        #nginx['listen_port'] = 80
        nginx['client_max_body_size'] = '2048m'
        gitlab_rails['smtp_enable'] = true
        gitlab_rails['smtp_address'] = "smtp.qq.com"
        gitlab_rails['smtp_port'] = 465
        gitlab_rails['smtp_user_name'] = "sundayle@qq.com"
        gitlab_rails['smtp_password'] = "bdoowbhvqywydaeh"
        gitlab_rails['smtp_domain'] = "smtp.qq.com"
        gitlab_rails['smtp_authentication'] = "login"
        gitlab_rails['smtp_enable_starttls_auto'] = false
        gitlab_rails['smtp_tls'] = true
        gitlab_rails['gitlab_email_enabled'] = true
        gitlab_rails['gitlab_email_from'] = 'sundayle@qq.com'
        #gitlab_rails['openssl_verify_mode'] = false
        #gitlab_rails['smtp_openssl_verify_mode'] = 'none'
    ports:
      - '80:80'
      - '8443:443'
      - '8022:22'
    volumes:
      - '/data/app_data/gitlab/config:/etc/gitlab'
      - '/data/app_data/gitlab/logs:/var/log/gitlab'
      - '/data/app_data/gitlab/data:/var/opt/gitlab'
    shm_size: '256m'

[root@gitlab ~]# docker compose up -d

获取gitlab root默认密码

[root@gitlab ~]# docker exec gitlab cat /etc/gitlab/initial_root_password | grep ^Password
Password: UCc6hQKMurkvNllkBamAkS+7DCDGxxxxxxxxx=

访问 http://git.sundayhk.com/
使用root和密码登陆

关闭注册 (帐号通过管理员添加)

image-20240727174406722

禁用 Gravatar

image-20240727174031413

邮件配置及测试

上面通过docker-compose.yaml 配置ENV Gitlab邮件相关变量,已经实现邮件配置。

这里也可以直接编辑容器内的gitlab.rb文件实现

[root@gitlab ~]# docker exec -it gitlab bash
root@gitlab:/# vi /etc/gitlab/gitlab.rb

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "sundayhk@qq.com"
gitlab_rails['smtp_password'] = "bdoowbxxxxxxxxxxxxxx" # 授权码
gitlab_rails['smtp_domain'] = "smtp.qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = false
gitlab_rails['smtp_tls'] = true
# gitlab_rails['smtp_pool'] = false

gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = 'sundayhk@qq.com'

每次修改都要重新生成配置文件及重启服务

# gitlab-rake gitlab:check
gitlab-ctl reconfigure
gitlab-ctl restart

邮件测试

root@gitlab:/# gitlab-rails console
--------------------------------------------------------------------------------
 Ruby:         ruby 3.1.5p253 (2024-04-023 revision 1945f8dc0e) [x86_64-linux]
 GitLab:       17.2.1 (b30193cc04c) FOSS
 GitLab Shell: 14.37.0
 PostgreSQL:   14.11
------------------------------------------------------------[ booted in 59.20s ]
=> #<Mail::Message:513100, Multipart: false, Headers: <Date: Sat, 27 Jul 2024 13:45:40 +0000>, <From: GitLab <sundayle@qq.com>>, <Reply-To: GitLab <noreply@git.sundayhk.com>>, <To: shaopenghk@qq.com>, <Message-ID: <66a4fa04941de_11ef2ff8446b4@gitlab.mail>>, <Subject: test>, <Mime-Version: 1.0>, <Content-Type: text/html; charset=US-ASCII>, <Content-Transfer-Encoding: 7bit>, <Auto-Submitted: auto-generated>, <X-Auto-Response-Suppress: All>>
irb(main):012:0> 

配置邮件后 添加新用户 则会发邮件 通过链接设置用户密码
image-20240727220754262

Gitlab备份

手动备份

[root@gitlab ~]# docker exec gitlab gitlab-rake gitlab:backup:create

[root@gitlab ~]# docker exec gitlab ls /var/opt/gitlab/backups/
1722090118_2024_07_27_17.2.1_gitlab_backup.tar

宿主机定时备份任务

[root@gitlab ~]# crontab -e

# m h  dom mon dow   command
# gitlab backup 
00 02 * * * /data/shell/gitlab_backup.sh > /dev/null 2>&1

备份脚本

[root@gitlab ~]#  vim /data/shell/gitlab_backup.sh

#!/bin/bash
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

docker exec gitlab gitlab-rake gitlab:backup:create

Gitlab恢复

[root@gitlab ~]# docker exec -it gitlab bash

# 停止相关数据连接服务
root@gitlab:/# gitlab-ctl stop unicorn
root@gitlab:/# gitlab-ctl stop sidekiq
root@gitlab:/# cd /var/opt/gitlab/backups
root@gitlab:/var/opt/gitlab/backups# ls -l
total 1000
-rw-------. 1 git git 512000 Jul 27 22:22 1722090118_2024_07_27_17.2.1_gitlab_backup.tar

root@gitlab:/var/opt/gitlab/backups# gitlab-rake gitlab:backup:restore
BACKUP=1722090118_2024_07_27_17.2.1

# 启动Gitlab
root@gitlab:/var/opt/gitlab/backups# gitlab-ctl start

报错解决

Running handlers:
[2024-07-27T18:23:17+08:00] ERROR: Running exception handlers
There was an error running gitlab-ctl reconfigure:

gitlab_rails['smtp_tls'] and gitlab_rails['smtp_enable_starttls_auto'] are mutually exclusive. Set one of them to false. SMTP providers usually use port 465 for TLS and port 587 for STARTTLS.

在配置文件/etc/gitlab/gitlab.rb中,同时配置了smtp_tls和smtp_enable_starttls_auto为true,把其中一个设置为false就行了。

相关文章

Linux Sudo 权限配置
阿里云ECS云盘IOPS压测
nextcloud preview-generate 报错文件无权限解决
tcpdump 抓包使用小结
Linux Tcpdump抓包
Ubuntu 18 SSH禁用密码登陆失效

发布评论