Docker搭建gitlab,配置邮箱并汉化

1. 修改 docker 镜像源为国内源

$ vi /etc/docker/daemon.json
{
  "registry-mirrors": ["https://lvpmz2sk.mirror.aliyuncs.com"]
}
$ systemctl reload docker #修改完成后重新载入docker服务

2. 拉取gitlab镜像

$ docker pull docker.io/gitlab/gitlab-ce:10.5.1-ce.0

注:你可以使用较新版本的gitlab,但不一定有对应版本的汉化包。

3. 启动容器

$ docker run \
-itd \
--name gitlab \
--restart=always \
-v /data/gitlab/etc:/etc/gitlab \
-v /data/gitlab/data:/var/opt/gitlab \
-v /data/gitlab/log:/var/log/gitlab \
-p 122:22 \
-p 127.0.0.1:180:80 \
gitlab/gitlab-ce:10.5.1-ce.0

4. 汉化:

$ cd /data/setup/ #进入文件安装目录(宿主机内执行)
$ yum -y install git #安装git客户端(宿主机内执行)
#--------首次下载汉化包时,执行以下命令---------------
$ git clone https://github.com/marbleqi/gitlab-ce-zh.git #下载汉化包版本库(宿主机内执行)
#--------后续更新汉化包时,执行以下命令
$ cd gitlab-ce-zh #进入版本目录
$ git pull origin #从远端获取最新库
$ git branch -a #显示最新的分支清单
$ git checkout remotes/origin/v10.5.1-zh-patch #切换到相应版本的汉化分支目录
cd .. #返回上一级目录
#--------------------------------------------------
$ docker cp gitlab-ce-zh gitlab:/opt/gitlab/embedded/service/ #将汉化文件从宿主机复制到容器中(宿主机内执行)
$ docker exec -it gitlab bash #进入容器(宿主机内执行)
$ cd /opt/gitlab/embedded/service/ #进入网页文件相关目录(容器内执行)
$ cp -rf gitlab-ce-zh/* gitlab-rails/ #将汉化文件覆盖原文件(容器内执行)

5. gitlab配置

  1. 进入容器(宿主机内执行)
$ docker exec -it gitlab bash #
  1. 编辑配置文件(容器内执行)
$ vi /etc/gitlab/gitlab.rb #编辑gitlab配置文件
  1. 基础配置
external_url 'http://gitlab.yourdomain.com/' #修改为gitlab访问域名
gitlab_rails['time_zone'] = 'PRC' #将标准时修改为中国时间
gitlab_rails['gitlab_shell_ssh_port'] = 22 #修改ssh端口

gitlab_rails['gitlab_default_can_create_group'] = false #限制普通用户创建组
gitlab_rails['gitlab_username_changing_enabled'] = false #username不能修改
  1. 邮箱配置:
    以163个人邮箱为例:
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_display_name'] = 'gitlab'
gitlab_rails['gitlab_email_reply_to'] = '[email protected]'
gitlab_rails['gitlab_email_subject_suffix'] = '[GITLAB]'

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "[email protected]"
gitlab_rails['smtp_password'] = "xxx"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = '[email protected]'
gitlab_rails['smtp_domain'] = "163.com"
user["git_user_email"] = "[email protected]"
  1. 使修改的配置文件生效
$ gitlab-ctl reconfigure #使修改的配置文件生效(容器内执行)
$ gitlab-ctl stop #停止gitlab服务(容器内执行)
$ gitlab-ctl start #启动gitlab服务(容器内执行
$ gitlab-ctl restart #重启gitlab服务(容器内执行)

6. nginx配置

nginx配置git.yourdomain.com,80端口代理127.0.0.1:180

$ vim /etc/nginx/conf.d/gitlab.conf

server {
        listen 80;
        server_name  git.yourdomain.com;
        access_log  /var/log/nginx/gitlab.access.log  main;
        error_log  /var/log/nginx/gitlab.error.log  error;       

        location / {
            proxy_read_timeout 2000;
            proxy_pass_header Server;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Scheme $scheme;
            proxy_pass http://127.0.0.1:180;
        }
    }

7. 数据备份与恢复

  • 备份
$ gitlab-rake gitlab:backup:create

使用以上命令会在/var/opt/gitlab/backups目录下创建一个名称类似为1393513186_gitlab_backup.tar的压缩包, 这个压缩包就是Gitlab整个的完整部分, 其中开头的1393513186是备份创建的日期.

Gitlab 修改备份文件默认目录
你也可以通过修改/etc/gitlab/gitlab.rb来修改默认存放备份文件的目录:

gitlab_rails['backup_path'] = '/mnt/backups'

/mnt/backups修改为你想存放备份的目录即可, 修改完成之后使用gitlab-ctl reconfigure命令重载配置文件即可.

  • 恢复
  1. 停止相关数据连接服务
$ gitlab-ctl stop unicorn
$ gitlab-ctl stop sidekiq
  1. 从1393513186编号备份中恢复
$ gitlab-rake gitlab:backup:restore BACKUP=1393513186
  1. 启动Gitlab
$  gitlab-ctl start

8. 其他:

  1. 查看gitlab的版本信息
$ head -1 /opt/gitlab/version-manifest.txt
  1. gitlab smtp官方帮助文档
https://docs.gitlab.com/omnibus/settings/smtp.html
  1. smtp测试:
$ gitlab-rails console production
irb(main):003:0> Notify.test_email('[email protected]', 'Message Subject', 'Message Body').deliver_now
  1. 查看日志
$ gitlab-ctl tail

or

$ tailf /var/log/gitlab/gitlab-rails/production.log
    1. 完整配置
external_url 'http://git.yourdomain.com'

gitlab_rails['time_zone'] = 'PRC'

gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_display_name'] = 'gitlab'
gitlab_rails['gitlab_email_reply_to'] = '[email protected]'
gitlab_rails['gitlab_email_subject_suffix'] = '[GITLAB]'

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "[email protected]"
gitlab_rails['smtp_password'] = "xxx"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = '[email protected]'
gitlab_rails['smtp_domain'] = "163.com"
user["git_user_email"] = "[email protected]"

gitlab_rails['gitlab_default_can_create_group'] = false
gitlab_rails['gitlab_username_changing_enabled'] = false

你可能感兴趣的:(Docker搭建gitlab,配置邮箱并汉化)