Docker-Gitlab-official

官方版gitlab安装使用

官网教程

docker-statck.yml文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
version: "3.6"
services:
gitlab:
image: gitlab/gitlab-ce:latest
ports:
- "14020:22"
- "14018:80"
#https - "14019:443"
volumes:
- /dockerdata/v-gitlab-ce/data:/var/opt/gitlab
- /dockerdata/v-gitlab-ce/logs:/var/log/gitlab
- /dockerdata/v-gitlab-ce/config:/etc/gitlab
environment:
GITLAB_OMNIBUS_CONFIG: "from_file('/omnibus_config.rb')"
configs:
- source: gitlab_rb
target: /omnibus_config.rb
secrets:
- gitlab_root_password
deploy:
replicas: 1
restart_policy:
condition: on-failure
resources:
limits:
cpus: '2.00' #限制为2核,设置0.50会启动失败,且不报错
memory: 8192M #限制为8g,8g2核为推荐配置,设置为4g,使用卡顿
gitlab-runner:
image: gitlab/gitlab-runner:alpine
deploy:
mode: replicated
replicas: 1
configs:
gitlab_rb:
external: true
secrets:
gitlab_root_password:
external: true

portainer->config->name: gitlab_rb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
external_url 'http://192.168.1.230:14018/'
#这里必须设置监听为80,因为是监听容器内的端口
nginx['listen_port'] = 80
#这里要设置ssh端口,不然ssh不能使用
gitlab_rails['gitlab_shell_ssh_port'] = 14020
gitlab_rails['initial_root_password'] = File.read('/run/secrets/gitlab_root_password')
gitlab_rails['time_zone'] = 'Asia/Shanghai'
#cron时间表达式每天三点
gitlab_rails['backup_cron'] = '0 0 3 * * ?'
# 默认备份目录/var/opt/gitlab/backups
# gitlab_rails['backup_path'] = '/var/opt/gitlab/backups'
# limit backup lifetime to 7 days - 604800 seconds
gitlab_rails['backup_keep_time'] = 604800

# ----优化内存配置-------------
#数据库缓存大小
postgresql['shared_buffers'] = "256MB"
#数据库并发
postgresql['max_worker_processes'] = 6
#进程数
unicorn['worker_processes'] = 2
#
unicorn['worker_memory_limit_min'] = "200 * 1 << 20"
unicorn['worker_memory_limit_max'] = "300 * 1 << 20"
#减少并发
sidekiq['concurrency'] = 10



portainer->secrets->name: gitlab_root_password

1
MySuperSecretAndSecurePass0rd!

登陆时用户名为root,密码为gitlab_root_password的内容

备份

1
docker exec -t <your container name> gitlab-rake gitlab:backup:create

恢复

1550500433_2019_02_18_11.6.2_gitlab_backup.tar文件名分析

11.6.2gitlab版本号,备份还原版本号要一致

1550500433_2019_02_18_11.6.2备份文件编号

1
2
3
4
5
# 移动到目录/var/opt/gitlab/backups并修改权限
chmod 777 1550500433_2019_02_18_11.6.2_gitlab_backup.tar
#进入容器执行
gitlab-rake gitlab:backup:restore BACKUP=1550500433_2019_02_18_11.6.2
#同意几个yes

重置管理员密码

进入容器执行

1
2
3
4
5
6
7
8
9
10
11
gitlab-rails console production
#进入console,查询用户1的用户名,@符号后面为用户名
irb(main):004:0> user = User.where(id:1).first
=> #<User id:1 @root>
#重置密码为xxxx
irb(main):005:0> user.password = 'xxxx'
=> "xxxx"
#保存设置
irb(main):006:0> user.save!
Enqueued ActionMailer::DeliveryJob (Job ID: efc41db4-43bb-4f0f-83ca-7481611c2ff4) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", #<GlobalID:0x00007fea66e486f0 @uri=#<URI::GID gid://gitlab/User/1>>
=> true

到此用root用户登录即可

定时备份

1
2
3
4
5
6
7
8
9
docker exec -t $(docker ps | grep "gitlab_mygitlab" | awk '{ print $1 }') gitlab-backup create
#对于GitLab 12.1和更早版本,请使用
docker exec -t $(docker ps | grep "gitlab_mygitlab" | awk '{ print $1 }') gitlab-rake gitlab:backup:create
## 添加定时任务
crontab -e
# i进行编辑,esc然后:wq
0 4 * * * docker exec -t $(docker ps | grep "gitlab_mygitlab" | awk '{ print $1 }') gitlab-backup create
## 然后查看
crontab -l

centos7 crontab 定时任务

1
2
3
4
5
6
7
8
9
10
11
12
# (查看状态)
systemctl status crond
# (设为开机启动)
systemctl enable crond
# (启动crond服务)
systemctl start crond
#添加定时任务
crontab -e
#查看定时任务
crontab -l
#删除当前用户的定时任务
crontab -r

备份会有如下警告:

因为配置文件和密码文件需要自己手动备份,为了数据安全

1
2
3
Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
and are not included in this backup. You will need these files to restore a backup.
Please back them up manually.

gitlab 升级

详细升级路径见GitLab release and maintenance policy

版本介绍:

规则:(Major).(Minor).(Patch)=(主要版本).(次要版本).(补丁号)

例如,Gitlab版本12.10.6:

  • 12代表主要版本。主要版本是12.0.0,但通常称为12.0。
  • 10代表次要版本。次要版本是12.10.0,但通常称为12.10。
  • 6 代表补丁号。

升级路径为12.10.6->12.10.14->13.0.12->13.2.3

我的理解(仅供参考做好备份):

先将补丁版本升级到最高,然后升级次要版本升级到最高,最后主要版本一级一级的升

可以利用dockerhub的搜索功能,例如搜索框输入12.10,找到最大的补丁版本12.10.14,次要版本的最大输入12.找到次要版本的最大版本

额外

  1. 进入容器可以执行命令gitlab-rake gitlab:env:info更多命令见rake
  2. 备份文件repositoriesxxx.bundle可以用git命令解压git clone xxx.bundle xxx,详情见git bundle打包

常见问题

  1. gitlab runner 500 error

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    ActionView::Template::Error ():
    36:
    37: .col-sm-6
    38: .bs-callout
    39: = render partial: 'ci/runner/how_to_setup_runner',
    40: locals: { registration_token: Gitlab::CurrentSettings.runners_registration_token,
    41: type: 'shared',
    42: reset_token_url: reset_registration_token_admin_application_settings_path }
    lib/gitlab/crypto_helper.rb:27:in `aes256_gcm_decrypt'
    app/models/concerns/token_authenticatable_strategies/encrypted.rb:45:in `get_token'
    app/models/concerns/token_authenticatable_strategies/base.rb:33:in `ensure_token!'
    app/models/concerns/token_authenticatable.rb:48:in `block in add_authentication_token_field'
    app/models/application_setting_implementation.rb:326:in `runners_registration_token'

    解决:

    1
    2
    3
    4
    5
    #需要先还原gtilabb容器的config挂载目录的gitlab-secrets.json,我这里是整个恢复config目录
    #进入gitlab容器,执行
    root@f51be17d113b:/# gitlab-rails console
    然后进入命令行后执行
    irb(main):001:0> ApplicationSetting.current.reset_runners_registration_token!

参考

gitlab.rb配置文件