以镜像的方式部署gitlab,并外挂postgresql、redis数据库。环境为centos7(192.168.117.129),在192.168.117.129安装postgresql、redis数据库。 (一)拉取镜像
1 docker pull twang2218/gitlab-ce-zh:10.6.4
(二)启动 在启动之前需要在postgresql中新建一个数据库gitlab-test1数据库 1)以docker run 方式启动gitlab镜像,挂载的数据库,在容器的配置文件中添加:
1 2 3 4 5 6 7 8 9 docker run -d \ --hostname '192.168.117.129' \ --publish 443:443 --publish 8080:80 --publish 2222:22 \ --name dockercompose_gitlab_1 \ --restart always \ --volume '/gitlab/config:/etc/gitlab' \ --volume '/gitlab/logs:/var/log/gitlab' \ --volume '/gitlab/config/gitlab/data:/var/opt/gitlab' \ twang2218/gitlab-ce-zh:10.6.4
2)以docker-compose 方式启动gitlab镜像:
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 version: '2' services: gitlab: image: 'twang2218/gitlab-ce-zh:10.6.4' restart: unless-stopped hostname: '192.168.117.129' environment: TZ: 'Asia/Shanghai' GITLAB_OMNIBUS_CONFIG: | external_url 'http://192.168.117.129' gitlab_rails['time_zone' ] = 'Asia/Shanghai' gitlab_rails['gitlab_shell_ssh_port' ] = 54322 postgresql['enable' ] = false gitlab_rails['db_adapter' ] = "postgresql" gitlab_rails['db_encoding' ] = "utf8" gitlab_rails['db_database' ] = "gitlab-test1" gitlab_rails['db_username' ] = "postgres" gitlab_rails['db_password' ] = "postgres" gitlab_rails['db_host' ] = "192.168.117.129" gitlab_rails['db_port' ] = 5432 ports: - '8080:80' - '441:443' - '54322:22' volumes: - '/gitlab/config:/etc/gitlab' - '/gitlab/logs:/var/log/gitlab' - '/gitlab/config/gitlab/data:/var/opt/gitlab'
以上两种启动方式,可能出现类似下面的错误:
1 2 3 4 5 6 7 8 9 10 There was an error running gitlab-ctl reconfigure: bash[migrate gitlab-rails database] (gitlab::database_migrations line 49) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1' ---- Begin output of "bash" "/tmp/chef-script20190430-11860-4waqei" ---- STDOUT: bundler: failed to load command : rake (/opt/gitlab/embedded/bin/rake) Bundler::GemNotFound: Could not find mysql2-0.4.10 in any of the sources /opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/bundler- 1.16.2/lib/bundler/spec_set.rb:91:in `block in materialize' /opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/bundler- 1.16.2/lib/bundler/spec_set.rb:85:in `map!' STDERR: ---- End output of "bash" "/tmp/chef-script20190430-11860-4waqei" ---- Ran "bash" "/tmp/chef-script20190430-11860-4waqei" returned 1
解决方案:在192.168.117.129上安装postgresql的extension插件
1 2 进入目录:/home/deployer/postgresql-10.1/contrib make && make install
(三)数据迁移 参考文档:https://www.cnblogs.com/wenwei-blog/p/6362829.html
1.迁移准备工作和思路:从a服务器迁移到b服务器,由于Gitlab自身的兼容性问题,高版本的Gitlab无法恢复低版本备份的数据,需要注意在b服务器部署和a服 务器一样版本的gitlab,部署好环境后开始备份和数据迁移。 查看gitlab版本的命令:
1 gitlab-rake gitlab:env :info(容器中运行)
2.备份原a服务器上的的数据
1 gitlab-rake gitlab:backup:create RAILS_ENV=production(容器中运行)
PS: 备份后的文件一般是位于/var/opt/gitlab/backups(容器中目录)下, 自动生成文件名,文件名如1481529483_gitlab_backup.tar 3.将步骤2生成的tar文件拷贝到b服务器上相应的backups目录下 4.在b服务器恢复数据 将备份文件权限修改为777,不然可能恢复的时候会出现权限不够,不能解压的问题
1 2 chmod 777 1502357536_2017_08_10_9.4.3_gitlab_backup.tar gitlab-rake gitlab:backup:restore RAILS_ENV=production BACKUP=1502357536_2017_08_10_9.4.3
PS:BACKUP的时间点必须与原服务器备份后的文件名一致
(四) gitlab升级并进行数据迁移 如果要升级的gitlab和当前的gitlab不在同一台服务器上,按照3)进行数据的迁移,若在同一台服务器上,则直接按照下述命令操作即可:
修改docker-compose文件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 version: '2' services: gitlab: image: 'twang2218/gitlab-ce-zh:11.1.4' restart: unless-stopped hostname: '192.168.117.129' environment: TZ: 'Asia/Shanghai' GITLAB_OMNIBUS_CONFIG: | external_url 'http://192.168.117.129' gitlab_rails['time_zone' ] = 'Asia/Shanghai' gitlab_rails['gitlab_shell_ssh_port' ] = 54322 postgresql['enable' ] = false gitlab_rails['db_adapter' ] = "postgresql" gitlab_rails['db_encoding' ] = "utf8" gitlab_rails['db_database' ] = "gitlab-test1" gitlab_rails['db_username' ] = "postgres" gitlab_rails['db_password' ] = "postgres" gitlab_rails['db_host' ] = "192.168.117.129" gitlab_rails['db_port' ] = 5432 ports: - '8080:80' - '441:443' - '54322:22' volumes: - '/gitlab/config:/etc/gitlab' - '/gitlab/logs:/var/log/gitlab' - '/gitlab/config/gitlab/data:/var/opt/gitlab'
启动1 2 docker-compose down docker-compose up -d
(五)调试 如果容器启动不成功,可进入容器进行调试 1)查看并修改GitLab 配置。若postgresql在本机,则不设置此项,但须在数据库中新建一个数据库名为gitlabhq_production的数据库,若要外挂的postgresql数据库不在本机,则按下述步骤查看并修改相关配置:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 docker exec -t -i dockercompose_gitlab_1 bash vim /etc/gitlab/gitlab.rb 在该文件中搜索 /db ,在这一栏修改下述语句,若果一致则不修改 gitlab_rails['db_adapter' ] = "postgresql" gitlab_rails['db_encoding' ] = "utf8" gitlab_rails['db_database' ] = "gitlab-test1" gitlab_rails['db_username' ] = "postgres" gitlab_rails['db_password' ] = "postgres" gitlab_rails['db_host' ] = "192.168.117.129" gitlab_rails['db_port' ] = 5432 保存退出 运行 gitlab-rake gitlab:check ,若不出错,即可进行下一步,若报错,解决问题 重新配置gitlab: gitlab-ctl reconfigure 若不报错,则gitlab正常启动,并连接到postgresql数据库。 注:每次删除容器,重新启动镜像时,需删除根目录下的/gitlab目录
2)如果gitlab启动的端口不是80,还需修改HTTP连接方式中的端口,该端口默认为80端口
1 2 docker exec -t -i dockercompose_gitlab_1 bash vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
如上图所示,本文中的gitlab是以8080端口启动的,需修改为8080端口,执行下述命令