avatar
童琦杰
Jun 12, 2021Technology

Ubuntu下Gitlab安装、备份、恢复及相关问题

安装

bash
sudo dpkg -i gitlab-ce_9.2.5-ce.0_amd64.deb
sudo gitlab-ctl reconfigure

如需重启服务

bash
sudo gitlab-ctl restart

备份

bash
sudo gitlab-rake gitlab:backup:create

默认备份文件位置: /var/opt/gitlab/backups

备份配置文件及密匙: /etc/gitlab/gitlab.rb/etc/gitlab/gitlab-secrets.json

恢复

bash
sudo cp gitlab.rb /etc/gitlab/gitlab.rb
sudo cp gitlab-secrets.json /etc/gitlab/gitlab-secrets.json
sudo cp 1622265010_2021_05_29_9.2.5_gitlab_backup.tar /var/opt/gitlab/backups/
sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
sudo gitlab-ctl status
sudo gitlab-rake gitlab:backup:restore BACKUP=1622265010_2021_05_29_9.2.5
sudo gitlab-ctl start
sudo gitlab-rake gitlab:check SANITIZE=true

配置HTTPS证书

修改Gitlab配置文件

/etc/gitlab/gitlab.rb
external_url '[https://domain]'
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "[path_of_certificate_file]"
nginx['ssl_certificate_key'] = "[path_of_certificate_private_key]"

如果存在反向代理则配置如下

/etc/gitlab/gitlab.rb
external_url '[https://domain]'
nginx['listen_port'] = proxy_port
nginx['listen_https'] = false

更新配置即可。

bash
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart nginx

附:gitlab下nginx配置文件位置

/var/opt/gitlab/nginx/conf/gitlab-http.conf
server_name [https://domain];
ssl on;
ssl_certificate [path_of_certificate_file];
ssl_certificate_key [path_of_certificate_private_key];

访问Gitlab出现Forbidden(403)问题

1.查看IP是否被封,若Redis存在被封记录,则删除对应键即可

bash
cd /opt/gitlab/embedded/bin/
./redis-cli -s /var/opt/gitlab/redis/redis.socket keys '*' | grep 'rack::attack'
./redis-cli -s /var/opt/gitlab/redis/redis.socket del [REDIS_KEY]

查询nginx日志

bash
sudo gitlab-ctl tail nginx/gitlab_access.log

账号

管理员账号用户名: root

Deploy Key

1.创建系统SSH key pair(no passphrase)

bash
ssh-keygen -t rsa -C "your.email@example.com" -b 4096

2.复制SSH公钥($HOME/.ssh/id_rsa.pub)到gitlab

3.验证是否有效

bash
ssh -T git@your-gitlab-domain

4.使用SSH方式拉取代码

bash
ssh git@your-gitlab-domain:your-project.git
© 2015-2022 tongqijie.com 版权所有沪ICP备17000682号