gitlab 安装
来源:原创
时间:2019-07-15
作者:脚本小站
分类:云原生
安装依赖包:
yum install curl openssh-server openssh-clients postfix cronie policycoreutils-python –y
方法一:
官网安装方法:但是安装使用的yum源不是国内的。
https://packages.gitlab.com/gitlab/gitlab-ce/install
国内下载地址:这是清华大学的开源地址
https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
方法二:
配置yum源:
vim /etc/yum.repos.d/gitlab-ce.repo [gitlab-ce] name=Gitlab CE Repository baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/ gpgcheck=0 enabled=1
安装:因为rpm包比较大,可以先安装一下查看版本,再去清华的yum源下载rpm下来安装。
export EXTERNAL_URL="GitLab服务器的公网IP地址" yum install gitlab-ce
启动:
gitlab-ctl start # 启动所有 gitlab 组件
配置参考:
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
修改配置:
vim /etc/gitlab/gitlab.rb # 关闭不需要的服务,建议开启,gitlab默认集成了grafana监控面板自带面板 grafana['enable'] = false prometheus['enable'] = false alertmanager['enable'] = false # 几个expoter修改为监听在0.0.0.0地址 gitlab_exporter['enable'] = true gitlab_exporter['listen_address'] = '0.0.0.0' gitlab_exporter['listen_port'] = '9168 node_exporter['enable'] = true node_exporter['listen_address'] = '0.0.0.0:9100' redis_exporter['enable'] = true redis_exporter['listen_address'] = '0.0.0.0:9121'
重新读取配置:
gitlab-ctl reconfigure
其他命令:gitlab默认用户名为root。
gitlab-ctl stop # 停止所有 gitlab 组件 gitlab-ctl restart # 重启所有 gitlab 组件 gitlab-ctl status # 查看服务状态 vim /etc/gitlab/gitlab.rb # 修改默认的配置文件 gitlab-rake gitlab:check SANITIZE=true --trace # 检查gitlab gitlab-ctl tail # 查看日志
参考地址:
www.cnblogs.com/weifeng1463/p/7714492.html
常用命令
列出可被单独管理的服务:
]# gitlab-ctl service-list alertmanager* gitaly* gitlab-exporter* gitlab-kas* gitlab-workhorse* grafana* logrotate* nginx* node-exporter* postgres-exporter* postgresql* prometheus* puma* redis* redis-exporter* sidekiq*
查看服务状态:
]# gitlab-ctl status run: alertmanager: (pid 5874) 4925868s; run: log: (pid 1593) 6736553s run: gitaly: (pid 5884) 4925867s; run: log: (pid 1605) 6736553s run: gitlab-exporter: (pid 5902) 4925867s; run: log: (pid 1587) 6736553s run: gitlab-kas: (pid 5906) 4925867s; run: log: (pid 1582) 6736553s run: gitlab-workhorse: (pid 5920) 4925866s; run: log: (pid 1601) 6736553s run: grafana: (pid 5933) 4925866s; run: log: (pid 1596) 6736553s run: logrotate: (pid 25394) 1014s; run: log: (pid 1603) 6736553s run: nginx: (pid 5952) 4925865s; run: log: (pid 1589) 6736553s run: node-exporter: (pid 5964) 4925864s; run: log: (pid 1602) 6736553s run: postgres-exporter: (pid 5971) 4925864s; run: log: (pid 1588) 6736553s run: postgresql: (pid 5980) 4925864s; run: log: (pid 1591) 6736553s run: prometheus: (pid 5992) 4925863s; run: log: (pid 1615) 6736553s run: puma: (pid 6006) 4925863s; run: log: (pid 1599) 6736553s run: redis: (pid 6011) 4925862s; run: log: (pid 1604) 6736553s run: redis-exporter: (pid 6017) 4925862s; run: log: (pid 1613) 6736553s run: sidekiq: (pid 6024) 4925861s; run: log: (pid 1600) 6736553s
停止服务:
]# gitlab-ctl stop ok: down: alertmanager: 0s, normally up ok: down: gitaly: 0s, normally up ok: down: gitlab-exporter: 0s, normally up ok: down: gitlab-kas: 0s, normally up ok: down: gitlab-workhorse: 0s, normally up ok: down: grafana: 0s, normally up ok: down: logrotate: 0s, normally up ok: down: nginx: 1s, normally up ok: down: node-exporter: 0s, normally up ok: down: postgres-exporter: 1s, normally up ok: down: postgresql: 0s, normally up ok: down: prometheus: 0s, normally up ok: down: puma: 0s, normally up ok: down: redis: 0s, normally up ok: down: redis-exporter: 1s, normally up ok: down: sidekiq: 1s, normally up
停止某个服务:
]# gitlab-ctl stop sidekiq ok: down: sidekiq: 0s, normally up
启动服务:
~]# gitlab-ctl start ok: run: alertmanager: (pid 27376) 1s ok: run: gitaly: (pid 27388) 0s ok: run: gitlab-exporter: (pid 27407) 1s ok: run: gitlab-kas: (pid 27410) 0s ok: run: gitlab-workhorse: (pid 27424) 0s ok: run: grafana: (pid 27436) 1s ok: run: logrotate: (pid 27451) 0s ok: run: nginx: (pid 27457) 1s ok: run: node-exporter: (pid 27469) 0s ok: run: postgres-exporter: (pid 27475) 1s ok: run: postgresql: (pid 27484) 0s ok: run: prometheus: (pid 27497) 0s ok: run: puma: (pid 27511) 1s ok: run: redis: (pid 27516) 0s ok: run: redis-exporter: (pid 27522) 1s ok: run: sidekiq: (pid 27529) 0s
启动某个服务:
]# gitlab-ctl start sidekiq ok: run: sidekiq: (pid 27976) 0s
检查配置:
]# gitlab-ctl check-config
直接进入gitlab内部的pg:
]# gitlab-psql psql (13.6) Type "help" for help. gitlabhq_production=#
直接进入gitlab内的redis:
]# gitlab-redis-cli redis /var/opt/gitlab/redis/redis.socket>
备份恢复
备份配置文件:
]# gitlab-ctl backup-etc Could not find '/etc/gitlab/config_backup' directory. Creating. Running configuration backup Creating configuration backup archive: gitlab_config_1671011177_2022_12_14.tar /etc/gitlab/ /etc/gitlab/gitlab-secrets.json /etc/gitlab/initial_root_password /etc/gitlab/trusted-certs/ /etc/gitlab/gitlab.rb Configuration backup archive complete: /etc/gitlab/config_backup/gitlab_config_1671011177_2022_12_14.tar Keeping all older configuration backups
备份gitlab:如下两个命令效果等同。
]# gitlab-rake gitlab:backup:create ]# gitlab-backup create
输出如下:
]# gitlab-backup create 2022-12-14 23:43:43 +0800 -- Dumping database ... Dumping PostgreSQL database gitlabhq_production ... [DONE] 2022-12-14 23:43:47 +0800 -- Dumping database ... done 2022-12-14 23:43:47 +0800 -- Dumping repositories ... ...... 2022-12-14 23:43:48 +0800 -- Dumping repositories ... done 2022-12-14 23:43:48 +0800 -- Dumping uploads ... 2022-12-14 23:43:48 +0800 -- Dumping uploads ... done 2022-12-14 23:43:48 +0800 -- Dumping builds ... 2022-12-14 23:43:48 +0800 -- Dumping builds ... done 2022-12-14 23:43:48 +0800 -- Dumping artifacts ... 2022-12-14 23:43:52 +0800 -- Dumping artifacts ... done 2022-12-14 23:43:52 +0800 -- Dumping pages ... 2022-12-14 23:43:52 +0800 -- Dumping pages ... done 2022-12-14 23:43:52 +0800 -- Dumping lfs objects ... 2022-12-14 23:43:52 +0800 -- Dumping lfs objects ... done 2022-12-14 23:43:52 +0800 -- Dumping terraform states ... 2022-12-14 23:43:52 +0800 -- Dumping terraform states ... done 2022-12-14 23:43:52 +0800 -- Dumping container registry images ... [DISABLED] 2022-12-14 23:43:52 +0800 -- Dumping packages ... 2022-12-14 23:43:52 +0800 -- Dumping packages ... done 2022-12-14 23:43:52 +0800 -- Creating backup archive: 1671032623_2022_12_14_15.0.2_gitlab_backup.tar ... 2022-12-14 23:43:52 +0800 -- Creating backup archive: 1671032623_2022_12_14_15.0.2_gitlab_backup.tar ... done 2022-12-14 23:43:52 +0800 -- Uploading backup archive to remote storage ... [SKIPPED] 2022-12-14 23:43:52 +0800 -- Deleting tar staging files ... 2022-12-14 23:43:52 +0800 -- Cleaning up /var/opt/gitlab/backups/backup_information.yml 2022-12-14 23:43:52 +0800 -- Cleaning up /var/opt/gitlab/backups/db 2022-12-14 23:43:52 +0800 -- Cleaning up /var/opt/gitlab/backups/repositories 2022-12-14 23:43:52 +0800 -- Cleaning up /var/opt/gitlab/backups/uploads.tar.gz 2022-12-14 23:43:52 +0800 -- Cleaning up /var/opt/gitlab/backups/builds.tar.gz 2022-12-14 23:43:52 +0800 -- Cleaning up /var/opt/gitlab/backups/artifacts.tar.gz 2022-12-14 23:43:52 +0800 -- Cleaning up /var/opt/gitlab/backups/pages.tar.gz 2022-12-14 23:43:52 +0800 -- Cleaning up /var/opt/gitlab/backups/lfs.tar.gz 2022-12-14 23:43:52 +0800 -- Cleaning up /var/opt/gitlab/backups/terraform_state.tar.gz 2022-12-14 23:43:52 +0800 -- Cleaning up /var/opt/gitlab/backups/packages.tar.gz 2022-12-14 23:43:52 +0800 -- Deleting tar staging files ... done 2022-12-14 23:43:52 +0800 -- Deleting old backups ... [SKIPPED] 2022-12-14 23:43:52 +0800 -- 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. 2022-12-14 23:43:52 +0800 -- Backup 1671032623_2022_12_14_15.0.2 is done.
恢复:恢复之前先停止如下两个服务
]# gitlab-ctl stop unicorn ok: down: unicorn: 0s, normally up ]# gitlab-ctl stop sidekiq ok: down: sidekiq: 1s, normally up
恢复:
gitlab-rake gitlab:backup:restore BACKUP=要恢复版本的包名 gitlab-backup restore BACKUP=要恢复版本的包名
执行恢复:恢复过程有应答
]# gitlab-rake gitlab:backup:restore BACKUP=1671119227_2022_12_15_15.0.2 2022-12-15 23:51:30 +0800 -- Unpacking backup ... 2022-12-15 23:51:30 +0800 -- Unpacking backup ... done 2022-12-15 23:51:30 +0800 -- Restoring database ... 2022-12-15 23:51:30 +0800 -- Be sure to stop Puma, Sidekiq, and any other process that connects to the database before proceeding. For Omnibus installs, see the following link for more information: https://docs.gitlab.com/ee/raketasks/backup_restore.html#restore-for-omnibus-gitlab-installations 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. Do you want to continue (yes/no)? yes ...... 2022-12-15 23:54:41 +0800 -- Restoring uploads ... done 2022-12-15 23:54:41 +0800 -- Restoring builds ... 2022-12-15 23:54:41 +0800 -- Restoring builds ... done 2022-12-15 23:54:41 +0800 -- Restoring artifacts ... 2022-12-15 23:54:42 +0800 -- Restoring artifacts ... done 2022-12-15 23:54:42 +0800 -- Restoring pages ... 2022-12-15 23:54:42 +0800 -- Restoring pages ... done 2022-12-15 23:54:42 +0800 -- Restoring lfs objects ... 2022-12-15 23:54:42 +0800 -- Restoring lfs objects ... done 2022-12-15 23:54:42 +0800 -- Restoring terraform states ... 2022-12-15 23:54:42 +0800 -- Restoring terraform states ... done 2022-12-15 23:54:42 +0800 -- Restoring packages ... 2022-12-15 23:54:42 +0800 -- Restoring packages ... done This task will now rebuild the authorized_keys file. You will lose any data stored in the authorized_keys file. Do you want to continue (yes/no)? yes 2022-12-15 23:55:00 +0800 -- Deleting tar staging files ... 2022-12-15 23:55:00 +0800 -- Cleaning up /var/opt/gitlab/backups/backup_information.yml 2022-12-15 23:55:00 +0800 -- Cleaning up /var/opt/gitlab/backups/db 2022-12-15 23:55:00 +0800 -- Cleaning up /var/opt/gitlab/backups/repositories 2022-12-15 23:55:00 +0800 -- Cleaning up /var/opt/gitlab/backups/uploads.tar.gz 2022-12-15 23:55:00 +0800 -- Cleaning up /var/opt/gitlab/backups/builds.tar.gz 2022-12-15 23:55:00 +0800 -- Cleaning up /var/opt/gitlab/backups/artifacts.tar.gz 2022-12-15 23:55:00 +0800 -- Cleaning up /var/opt/gitlab/backups/pages.tar.gz 2022-12-15 23:55:00 +0800 -- Cleaning up /var/opt/gitlab/backups/lfs.tar.gz 2022-12-15 23:55:00 +0800 -- Cleaning up /var/opt/gitlab/backups/terraform_state.tar.gz 2022-12-15 23:55:00 +0800 -- Cleaning up /var/opt/gitlab/backups/packages.tar.gz 2022-12-15 23:55:00 +0800 -- Deleting tar staging files ... done 2022-12-15 23:55:00 +0800 -- Deleting backups/tmp ... 2022-12-15 23:55:00 +0800 -- Deleting backups/tmp ... done 2022-12-15 23:55:00 +0800 -- Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data and are not included in this backup. You will need to restore these files manually. 2022-12-15 23:55:00 +0800 -- Restore task is done.
启动被停止的两个服务:
]# gitlab-ctl start sidekiq ]# gitlab-ctl start unicorn
参考:
cnblogs.com/easonscx/p/12615981.html