新的gitlab 环境 操做系统: Centos 7.6 x86_64 4.4.176-1.el7.elrepo.x86_64 # rpm -qa|grep kernel kernel-lt-4.4.176-1.el7.elrepo.x86_64 kernel-lt-devel-4.4.176-1.el7.elrepo.x86_64 kernel-lt-tools-libs-4.4.176-1.el7.elrepo.x86_64 kernel-lt-headers-4.4.176-1.el7.elrepo.x86_64 kernel-lt-tools-4.4.176-1.el7.elrepo.x86_64 kernel-lt-doc-4.4.176-1.el7.elrepo.noarch kernel-lt-tools-libs-devel-4.4.176-1.el7.elrepo.x86_64 Docker: Server: Docker Engine - Community Engine: Version: 18.09.3 API version: 1.39 (minimum version 1.12) Go version: go1.10.8 Git commit: 774a1f4 Built: Thu Feb 28 06:02:24 2019 OS/Arch: linux/amd64 Experimental: false 原始gitlab版本 # cat /opt/gitlab/embedded/service/gitlab-rails/VERSION 11.3.0 部署在传统物理机
旧gitlab备份 > 恢复至新环境的同版本gitlab > 验证 > 升级新环境的gitlab > 验证
https://hub.docker.com 查找gitlab/gitlab-ce的官方制做版本11.3.0 docker pull gitlab/gitlab-ce:11.3.0-ce.0
# mkdir -p /data/gitlab-backup # mkdir -p /data/docker # docker network create net_A # docker volume create gitlab_config # docker volume create gitlab_logs # docker volume create gitlab_data
数据卷 | 容器位置 | 做用 |
---|---|---|
gitlab_data | /var/opt/gitlab | gitlab的数据存放,包括nginx,postgresql这些 |
gitlab_logs | /var/log/gitlab | 日志存放 |
gitlab_config | /etc/gitlab | gitlab的主配置文件 |
/data/gitlab-backup | /data/gitlab-backup | 备份指令gitlab-rake gitlab:backup:create生成备份文件存放的目录 |
version: "2.4" networks: net_A: external: true volumes: gitlab_config: external: true gitlab_logs: external: true gitlab_data: external: true services: ol-gitlab: image: gitlab/gitlab-ce:11.3.0-ce.0 container_name: ol-gitlab hostname: ol-gitlab ports: - "80:80" - "443:443" - "22:22" networks: - net_A volumes: - "/etc/localtime:/etc/localtime" - "gitlab_config:/etc/gitlab" - "gitlab_logs:/var/log/gitlab" - "gitlab_data:/var/opt/gitlab" - "/data/gitlab-backup:/data/gitlab-backup" environment: GITLAB_OMNIBUS_CONFIG: | unicorn['worker_timeout'] = 60 unicorn['worker_processes'] = 3 unicorn['worker_memory_limit_min'] = "200 * 1 << 20" unicorn['worker_memory_limit_max'] = "300 * 1 << 20" sidekiq['concurrency'] = 10 external_url 'https://你的域名' gitlab_rails['backup_path'] = "/data/gitlab-backup" gitlab_rails['backup_keep_time'] = 1296000 gitlab_rails['time_zone'] = 'Asia/Shanghai' gitlab_rails['backup_archive_permissions'] = 0644 gitlab_rails['gitlab_shell_ssh_port'] = 22 nginx['enable'] = true nginx['client_max_body_size'] = '250m' nginx['redirect_http_to_https'] = true nginx['ssl_certificate'] = "你的公钥" nginx['ssl_certificate_key'] = "你的私钥" nginx['ssl_ciphers'] = "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256" nginx['ssl_prefer_server_ciphers'] = "on" nginx['ssl_protocols'] = "TLSv1.1 TLSv1.2" nginx['ssl_session_cache'] = "builtin:1000 shared:SSL:10m" nginx['listen_addresses'] = ["0.0.0.0"] nginx['http2_enabled'] = true postgresql['max_worker_processes'] = 8 postgresql['shared_buffers'] = "256MB" mem_limit: 3096m restart: always user: root
相关说明:node
官方建议unicorn['worker_processes']该值是等于CPU核心数+1,能够提升服务器的响应速度,若是内存只有4G,或者服务器上有其它业务,就不要改了,以避免内存不足。另外,这个参数最小值是2,设为1服务器可能会卡死,但若是您的内存已消耗太高,请根据业务自行调整,好比8G内存建议您调整4左右,优化是持续性的工做。 如下是官方翻译过来的内容: CPU 1核心CPU最多支持100个用户,全部的workers和后台任务都在同一个核心工做这将致使GitLab服务响应会有点缓慢。 2核心 支持500用户,这也是官方推荐的最低标准。 4 核心支持2,000用户。 8 核心支持5,000用户。 16 核心支持10,000用户。 32 核心支持20,000用户。 64 核心支持40,000用户。 若是想支持更多用户,可使用集群式架构 Memory 安装使用GitLab须要至少4GB可用内存(RAM + Swap)! 因为操做系统和其余正在运行的应用也会使用内存, 因此安装GitLab前必定要注意当前服务器至少有4GB的可用内存. 少于4GB内存会致使在reconfigure的时候出现各类诡异的问题, 并且在使用过程当中也常常会出现500错误. 1GB 物理内存 + 3GB 交换分区 是最低的要求,但咱们 强烈反对 使用这样的配置。 查看下面unicorn worker章节获取更多建议。 2GB 物理内存 + 2GB 交换分区 支持100用户,但服务响应会很慢。 4GB 物理内存 支持100用户,也是 官方推荐 的配置。 8GB 物理内存 支持 1,000 用户。 16GB 物理内存 支持 2,000 用户。 32GB 物理内存 支持 4,000 用户。 64GB 物理内存 支持 8,000 用户。 128GB 物理内存 支持 16,000 用户。 256GB 物理内存 支持 32,000 用户。 若是想支持更多用户,可使用集群式架构 即便你服务器有足够多的RAM, 也要给服务器至少分配2GB的交换分区。 由于使用交换分区能够在你的可用内存波动的时候下降GitLab出错的概率。 注意: Sidekiq的25个workers在查看进程(top或者htop)的时候会发现它会单独显示每一个worker,可是它们是共享内存分配的,这是由于Sidekiq是一个多线程的程序。 详细内容查看下面关于Unicorn workers 的介绍。
证书生成请参考其余文档 复制到数据卷gitlab_data中 # cp -a ssl/ /data/docker_root_dir/volumes/gitlab_config/_data/
# docker-compose up -d
# docker exec ol-gitlab cat /opt/gitlab/embedded/service/gitlab-rails/VERSION 11.3.0 请使用 此配置参数的网址进行访问 external_url 'https://你的域名' 第一次登陆,会让你重置密码,最少8个字符。 默认用户名为root
查找备份设定的备份路径 # cat /etc/gitlab/gitlab.rb |grep 'backup_path' gitlab_rails['backup_path'] = "/data/gitlab-backup" 默认在/var/opt/gitlab/backups 备份指令(建议与开发约定时间,中止使用的状况下备份) 1.中止相关数据链接服务 # gitlab-ctl stop unicorn ok: down: unicorn: 0s, normally up # gitlab-ctl stop sidekiq ok: down: sidekiq: 0s, normally up 2.备份数据 # gitlab-rake gitlab:backup:create 3.安全密钥文件(重要) /etc/gitlab/gitlab-secrets.json 不然会出现问题:https://gitlab.com/gitlab-org/gitlab-ce/issues/53465 须要一点时间,最后生成的文件 -rw-r--r-- 1 git git 11M Mar 14 10:41 1552531259_2019_03_14_11.3.0_gitlab_backup.tar 其中1552531259_2019_03_14_11.3.0为备份的编号,恢复的时候用到。
1. 将备份好的文件 1552531259_2019_03_14_11.3.0_gitlab_backup.tar 和 gitlab-secrets.json复制至 gitlab_rails['backup_path'] = "/data/gitlab-backup" 设定的目录中 2.中止相关数据链接服务 # docker exec -it ol-gitlab bash # gitlab-ctl stop unicorn ok: down: unicorn: 0s, normally up # gitlab-ctl stop sidekiq ok: down: sidekiq: 0s, normally up 3.恢复文件 # ls /data/gitlab-backup/ 1552531259_2019_03_14_11.3.0_gitlab_backup.tar # gitlab-rake gitlab:backup:restore BACKUP=1552531259_2019_03_14_11.3.0 Unpacking backup ... done Before restoring the database, we will remove all existing tables to avoid future upgrade problems. Be aware that if you have custom tables in the GitLab database these tables and all data will be removed. 在还原数据库以前,咱们将删除全部现有的表以免未来的升级问题。注意若是你有 Gitlab数据库中的自定义表这些表和全部数据将被移除的。 Do you want to continue (yes/no)? yes Removing all tables. Press `Ctrl-C` within 5 seconds to abort Cleaning the database ... done Restoring database ... ...中间省略... This will rebuild an authorized_keys file. You will lose any data stored in authorized_keys file. 这将重建受权authorized_keys密钥文件。您将丢失任何存储在受权密钥文件中的数据 Do you want to continue (yes/no)? yes Deleting tmp directories ... done done done done done done done done 4.恢复安全文件 # cp /data/gitlab-backup/gitlab-secrets.json /etc/gitlab/ 5.从新启动相关服务 # gitlab-ctl start unicorn ok: run: unicorn: (pid 2711) 0s # gitlab-ctl start sidekiq ok: run: sidekiq: (pid 2803) 0s 6.登录WEB页面查看代码是否存在 7. 带验证 重启服务 # gitlab-ctl restart ok: run: alertmanager: (pid 4983) 1s ok: run: crond: (pid 4993) 0s ok: run: gitaly: (pid 5001) 1s ok: run: gitlab-monitor: (pid 5014) 0s ok: run: gitlab-workhorse: (pid 5027) 0s ok: run: logrotate: (pid 5039) 0s ok: run: nginx: (pid 5045) 0s ok: run: node-exporter: (pid 5053) 1s ok: run: postgres-exporter: (pid 5058) 0s ok: run: postgresql: (pid 5141) 1s ok: run: prometheus: (pid 5150) 0s ok: run: redis: (pid 5161) 0s ok: run: redis-exporter: (pid 5166) 1s ok: run: sidekiq: (pid 5173) 1s ok: run: sshd: (pid 5180) 1s ok: run: unicorn: (pid 5188) 0s 验证指令 # gitlab-rake gitlab:check SANITIZE=true Checking GitLab Shell ... GitLab Shell version >= 8.3.3 ? ... OK (8.3.3) Repo base directory exists? default... yes Repo storage directories are symlinks? default... no Repo paths owned by git:root, or git:git? default... yes Repo paths access is drwxrws---? default... yes hooks directories in repos are links: ... 3/1 ... repository is empty 5/2 ... ok 5/3 ... ok 5/6 ... ok 5/9 ... ok 5/10 ... ok Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Check GitLab API access: OK Redis available via internal API: OK Access to /var/opt/gitlab/.ssh/authorized_keys: OK gitlab-shell self-check successful Checking GitLab Shell ... Finished Checking Sidekiq ... Running? ... yes Number of Sidekiq processes ... 1 Checking Sidekiq ... Finished Reply by email is disabled in config/gitlab.yml Checking LDAP ... LDAP is disabled in config/gitlab.yml Checking LDAP ... Finished Checking GitLab ... Git configured correctly? ... yes Database config exists? ... yes All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... yes Init script exists? ... skipped (omnibus-gitlab has no init script) Init script up-to-date? ... skipped (omnibus-gitlab has no init script) Projects have namespace: ... 3/1 ... yes 5/2 ... yes 5/3 ... yes 5/6 ... yes 5/9 ... yes 5/10 ... yes Redis version >= 2.8.0? ... yes Ruby version >= 2.3.5 ? ... yes (2.4.4) Git version >= 2.9.5 ? ... yes (2.18.0) Git user has default SSH configuration? ... yes Active users: ... 17 Checking GitLab ... Finished
中止容器 # docker container stop ol-gitlab 删除容器 docker rm ol-gitlab 把docker-compose文件中 image: gitlab/gitlab-ce:11.3.0-ce.0 修改成 image: gitlab/gitlab-ce 启动容器 # docker-compose up -d Creating ol-gitlab ... done
全新安装可参考 docker 部署 gitlab最新版本( 当前 11.8.1经过验证)linux