gitlab安装部署及备份恢复
安装部署
1、安装依赖包
yum -y install policycoreutils openssh-server openssh-clients postfix wget
2、下载gitlab安装包,然后安装
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-8.0.0-ce.0.el7.x86_64.rpm
rpm -i gitlab-ce-8.0.0-ce.0.el7.x86_64.rpm
[opt]# rpm -ivh gitlab-ce-8.0.0-ce.0.el7.x86_64.rpm Preparing... ################################# [100%] Updating / installing... 1:gitlab-ce-8.0.0-ce.0.el7 ################################# [100%] gitlab: Thank you for installing GitLab! gitlab: To configure and start GitLab, RUN THE FOLLOWING COMMAND: sudo gitlab-ctl reconfigure gitlab: GitLab should be reachable at http://sx-sj-cdn-glsb-5.novalocal gitlab: Otherwise configure GitLab for your system by editing /etc/gitlab/gitlab.rb file gitlab: And running reconfigure again. gitlab: gitlab: For a comprehensive list of configuration options please see the Omnibus GitLab readme gitlab: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md gitlab: It looks like GitLab has not been configured yet; skipping the upgrade script
3、修改gitlab配置文件指定服务器ip和自定义端口
vim /etc/gitlab/gitlab.rb
4、重置并启动GitLab
执行以下命令
gitlab-ctl reconfigure
Recipe: gitlab::unicorn * ruby_block[reload unicorn svlogd configuration] action create - execute the ruby block reload unicorn svlogd configuration Recipe: gitlab::sidekiq * ruby_block[reload sidekiq svlogd configuration] action create - execute the ruby block reload sidekiq svlogd configuration Recipe: gitlab::gitlab-git-http-server * ruby_block[reload gitlab-git-http-server svlogd configuration] action create - execute the ruby block reload gitlab-git-http-server svlogd configuration Recipe: gitlab::nginx * ruby_block[reload nginx svlogd configuration] action create - execute the ruby block reload nginx svlogd configuration Recipe: gitlab::logrotate * ruby_block[reload logrotate svlogd configuration] action create - execute the ruby block reload logrotate svlogd configuration Running handlers: Running handlers complete Chef Client finished, 197/226 resources updated in 71.779745158 seconds gitlab Reconfigured!
启动
gitlab-ctl restart
[gitlab]# gitlab-ctl restart ok: run: gitlab-git-http-server: (pid 28725) 1s ok: run: logrotate: (pid 28731) 0s ok: run: nginx: (pid 28738) 1s ok: run: postgresql: (pid 28751) 0s ok: run: redis: (pid 28753) 0s ok: run: sidekiq: (pid 28765) 0s ok: run: unicorn: (pid 28770) 0s
查看gitlab版本
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
8.0.0
访问gitlab页面
如果没有域名,直接输入服务器ip和指定端口进行访问,初始账户: root 密码: 5iveL!fe
第一次登录修改密码
GitLab相关文件
主配置文件: /etc/gitlab/gitlab.rb GitLab 文档根目录: /opt/gitlab 默认存储库位置: /var/opt/gitlab/git-data/repositories GitLab Nginx 配置文件路径: /var/opt/gitlab/nginx/conf/gitlab-http.conf Postgresql 数据目录: /var/opt/gitlab/postgresql/data
GitLab由以下服务构成
nginx: 静态web服务器 gitlab-shell: 用于处理Git命令和修改authorized keys列表 gitlab-workhorse: 轻量级的反向代理服务器 logrotate:日志文件管理工具 postgresql:数据库 redis:缓存数据库 sidekiq:用于在后台执行队列任务(异步执行) unicorn:An HTTP server for Rack applications,GitLab Rails应用是托管在这个服务器上面的。
常用命令
服务管理 # 启动所有 gitlab 组件: gitlab-ctl start # 停止所有 gitlab 组件: gitlab-ctl stop # 停止所有 gitlab postgresql 组件: gitlab-ctl stop postgresql # 停止相关数据连接服务 gitlab-ctl stop unicorn gitlab-ctl stop sidekiq # 重启所有 gitlab 组件: gitlab-ctl restart # 重启所有 gitlab gitlab-workhorse 组件: gitlab-ctl restart gitlab-workhorse # 查看服务状态 gitlab-ctl status # 生成配置并启动服务 gitlab-ctl reconfigure 日志管理 # 实时查看所有日志 gitlab-ctl tail # 实时检查redis的日志 gitlab-ctl tail redis # 实时检查postgresql的日志 gitlab-ctl tail postgresql # 检查gitlab-workhorse的日志 gitlab-ctl tail gitlab-workhorse # 检查logrotate的日志 gitlab-ctl tail logrotate # 检查nginx的日志 gitlab-ctl tail nginx # 检查sidekiq的日志 gitlab-ctl tail sidekiq # 检查unicorn的日志 gitlab-ctl tail unicorn
gitlab备份恢复(迁移)
1、手动备份gitlab
cd /var/opt/gitlab/backups/ /opt/gitlab/bin/gitlab-rake gitlab:backup:create
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@backups]# crontab -l 0 1 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1 注意:环境变量CRON=1的作用是如果没有任何错误发生时, 抑制备份脚本的所有进度输出
2、gitlab恢复
注意:gitlab恢复必须保证版本一致
2、1 停止相关数据连接服务
[root@gitlab]# gitlab-ctl stop unicorn ok: down: unicorn: 0s, normally up [root@gitlab]#
[root@ gitlab]# gitlab-ctl stop sidekiq ok: down: sidekiq: 0s, normally up [root@gitlab]#
查看状态
[root@gitlab]# gitlab-ctl status run: gitlab-git-http-server: (pid 28725) 3141s; run: log: (pid 28412) 3283s run: logrotate: (pid 28731) 3140s; run: log: (pid 28435) 3279s run: nginx: (pid 28738) 3140s; run: log: (pid 28417) 3281s run: postgresql: (pid 28751) 3138s; run: log: (pid 28303) 3308s run: redis: (pid 28753) 3138s; run: log: (pid 28215) 3319s down: sidekiq: 20s, normally up; run: log: (pid 28397) 3285s down: unicorn: 102s, normally up; run: log: (pid 28360) 3287s
2、2 上传备份文件到新git的备份目录
上传备份文件到新gitlab服务器对应的目录 通过备份文件进行恢复(必须要将备份文件放到新git设置的备份路径下,默认的是/var/opt/gitlab/backups)
注意:Gitlab的恢复操作会先将当前所有的数据清空,然后再根据备份数据进行恢复
cp /tmp/1574182816_gitlab_backup.tar ./ [root@backups]# chown -R git.git 1574182816_gitlab_backup.tar [root@backups]# ll total 2911052 -rwxr-xr-x 1 git git 2980915200 Nov 20 16:37 1574182816_gitlab_backup.tar
2、3 恢复gitlab仓库
gitlab-rake gitlab:backup:restore BACKUP=1574182816
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
Restoring repositories ... * ops/oos_test ... [DONE] * ops/config_test ... [DONE] ..... Put GitLab hooks in repositories dirs [DONE] done Restoring uploads ... done Restoring builds ... done This will rebuild an authorized_keys file. You will lose any data stored in authorized_keys file. Do you want to continue (yes/no)? yes .......... Deleting tmp directories ... done done done done done
2、4 启动gitlab
[root@s]# gitlab-ctl start ok: run: gitlab-git-http-server: (pid 28725) 3704s ok: run: logrotate: (pid 32404) 103s ok: run: nginx: (pid 28738) 3703s ok: run: postgresql: (pid 28751) 3701s ok: run: redis: (pid 28753) 3701s ok: run: sidekiq: (pid 32423) 1s ok: run: unicorn: (pid 32427) 0s
查看运行状态
[root@]# gitlab-ctl status run: gitlab-git-http-server: (pid 28725) 3786s; run: log: (pid 28412) 3928s run: logrotate: (pid 32404) 185s; run: log: (pid 28435) 3924s run: nginx: (pid 28738) 3785s; run: log: (pid 28417) 3926s run: postgresql: (pid 28751) 3783s; run: log: (pid 28303) 3953s run: redis: (pid 28753) 3783s; run: log: (pid 28215) 3964s run: sidekiq: (pid 32423) 82s; run: log: (pid 28397) 3930s run: unicorn: (pid 32427) 81s; run: log: (pid 28360) 3932s
恢复命令完成后,可以执行如下命令check检查一下恢复情况
gitlab-rake gitlab:check SANITIZE=true
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
Checking GitLab Shell ... GitLab Shell version >= 2.6.5 ? ... OK (2.6.5) Repo base directory exists? ... yes Repo base directory is a symlink? ... no Repo base owned by git:git? ... yes Repo base access is drwxrws---? ... no Try fixing it: sudo chmod -R ug+rwX,o-rwx /var/opt/gitlab/git-data/repositories sudo chmod -R ug-s /var/opt/gitlab/git-data/repositories find /var/opt/gitlab/git-data/repositories -type d -print0 | sudo xargs -0 chmod g+s For more information see: doc/install/installation.md in section "GitLab Shell" Please fix the error above and rerun the checks. hooks directories in repos are links: ... 2/1 ... ok 2/2 ... ok 2/3 ... ok 2/4 ... ok 2/5 ... ok 2/6 ... ok 2/7 ... ok 2/8 ... ok 10/9 ... ok 9/10 ... ok 8/11 ... ok 8/12 ... ok 8/13 ... ok 8/14 ... ok 2/15 ... ok 2/16 ... ok 2/17 ... ok 2/18 ... ok 8/19 ... ok 9/20 ... ok 10/27 ... ok 9/28 ... ok 8/29 ... ok 9/30 ... ok 8/31 ... ok 8/32 ... ok 8/33 ... ok 10/34 ... ok 10/35 ... ok 3/36 ... ok 3/37 ... ok 3/38 ... ok 3/39 ... ok 3/40 ... ok 9/41 ... ok 10/42 ... ok 2/43 ... ok 7/44 ... ok 2/45 ... ok 2/46 ... ok 8/47 ... ok 9/48 ... ok 9/49 ... ok 10/50 ... ok 9/51 ... ok 10/52 ... ok 10/53 ... ok 8/54 ... ok 10/55 ... ok 2/57 ... ok 2/58 ... ok 2/59 ... ok 2/60 ... ok 2/61 ... ok 10/62 ... ok 8/63 ... ok 8/64 ... ok 2/67 ... ok 2/68 ... ok 2/69 ... ok 2/70 ... ok 2/71 ... ok 3/72 ... ok Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Check GitLab API access: OK Check directories and files: /var/opt/gitlab/git-data/repositories: OK /var/opt/gitlab/.ssh/authorized_keys: OK Test redis-cli executable: redis-cli 2.8.21 Send ping to redis server: PONG gitlab-shell self-check successful Checking GitLab Shell ... Finished Checking Sidekiq ... Running? ... yes Number of Sidekiq processes ... 1 Checking Sidekiq ... Finished Checking Reply by email ... Reply by email is disabled in config/gitlab.yml Checking Reply by email ... Finished Checking LDAP ... LDAP is disabled in config/gitlab.yml Checking LDAP ... Finished Checking GitLab ... Git configured with autocrlf=input? ... yes Database config exists? ... yes Database is SQLite ... no All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config outdated? ... no Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory setup correctly? ... no Try fixing it: sudo chmod 0750 /var/opt/gitlab/gitlab-rails/uploads For more information see: doc/install/installation.md in section "GitLab" Please fix the error above and rerun the checks. 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: ... 2/1 ... yes 2/2 ... yes 2/3 ... yes 2/4 ... yes 2/5 ... yes 2/6 ... yes 2/7 ... yes 2/8 ... yes 10/9 ... yes 9/10 ... yes 8/11 ... yes 8/12 ... yes 8/13 ... yes 8/14 ... yes 2/15 ... yes 2/16 ... yes 2/17 ... yes 2/18 ... yes 8/19 ... yes 9/20 ... yes 10/27 ... yes 9/28 ... yes 8/29 ... yes 9/30 ... yes 8/31 ... yes 8/32 ... yes 8/33 ... yes 10/34 ... yes 10/35 ... yes 3/36 ... yes 3/37 ... yes 3/38 ... yes 3/39 ... yes 3/40 ... yes 9/41 ... yes 10/42 ... yes 2/43 ... yes 7/44 ... yes 2/45 ... yes 2/46 ... yes 8/47 ... yes 9/48 ... yes 9/49 ... yes 10/50 ... yes 9/51 ... yes 10/52 ... yes 10/53 ... yes 8/54 ... yes 10/55 ... yes 2/57 ... yes 2/58 ... yes 2/59 ... yes 2/60 ... yes 2/61 ... yes 10/62 ... yes 8/63 ... yes 8/64 ... yes 2/67 ... yes 2/68 ... yes 2/69 ... yes 2/70 ... yes 2/71 ... yes 3/72 ... yes Redis version >= 2.4.0? ... yes Ruby version >= 2.1.0 ? ... yes (2.1.6) Your git bin path is "/opt/gitlab/embedded/bin/git" Git version >= 1.7.10 ? ... yes (2.4.3) Active users: 19 Checking GitLab ... Finished
2.5 测试git pull和git push(确保该用户有提交权限)
git clone -b [test]# vim test 11 git add . git commit -a 'test' git push 登录页面查看提交信息