No secret: teach you how to build your own GitLab library by hand

Posted by vynsane on Wed, 18 Sep 2019 04:40:42 +0200

01 Preface

In this article, Gitlab is installed as the host mode. For more installation methods, Click https://git.lug.ustc.edu.cn/help/install/README.md

02 Architecture

Architecture overview:

  • Unicorn: Handles requests for the web interface and API, general gitlab site, mostly due to problems with this service
  • Sidekiq: Background jobs processor
  • Redis: Caching service
  • PostgreSQL: Database

03 Installation

1. Set repo

[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
EOF

2. Install GitLab

$ yum makecache
$ yum install gitlab-ce

3. Modify Configuration

Configuration file/etc/gitlab/gitlab.rb Note: You can modify the configuration file based on the comments, generally as follows
external_url 'http://gitlab.xxxxxx.com '#Change the domain name to your own, if you use https, change to https://gitlab.xxxxxx.com

4. Start the service

$ gitlab-ctl reconfigure  ## Make Configuration Effective
$ gitlab-ctl status  ## Confirm Service Status

04 How to Backup

1. Set up backup directory

Open the /etc/gitlab/gitlab.rb configuration file to see a configuration item related to backup:
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
This item defines the path to the default backup file that can take effect by modifying the configuration and executing gitlab-ctl reconfiguration or gitlab-ctl restart.

2. Perform backup

A backup executes a command that completes: /opt/gitlab/bin/gitlab-rake gitlab:backup:create, or can be added to crontab to execute regularly:

0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create

You can find the backup package at / var/opt/gitlab/backups, decompress it to see if the backup is more comprehensive, and the classification of database, repositories, build, upload, etc. is still clear.

3. Backup parameter comments

Perform backups every day, there is definitely a risk that the directory will burst. We can think of it right away that we can find the files before a certain time by find and delete them with rm.But it doesn't need to be that cumbersome. gitlab-ce has its own integrated auto-delete configuration.
Also open the /etc/gitlab/gitlab.rb configuration file to find the following configurations:
gitlab_rails['backup_keep_time'] = 604800 This is where the backup retention is set for 7 days (7360024=604800), in seconds. If you want to increase or decrease it, you can configure it there directly and restart the service through gitlab-ctl restart.

05 GitLab migration or data recovery

1. The data connection service needs to be stopped before recovery:

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

If it's a desktop host and it doesn't have any operations, you can theoretically not stop these two services.The two services are stopped to ensure data consistency.

2. Migrating data

If you have not modified the default backup directory, copy the backup files from the old server/var/opt/gitlab/backups directory to the new server/var/opt/gitlab/backups

[root@localhost gitlab]# scp 1530773117_2018_07_05_gitlab_backup.tar 10.0.3.111:/var/opt/gitlab/backups/
 
## 600 permissions are not restored.--This changed to 777

[root@localhost backups]# pwd
/var/opt/gitlab/backups
[root@localhost backups]# chmod 777 1530773117_2018_07_05_gitlab_backup.tar
[root@localhost backups]# ll
total 17328900
-rwxrwxrwx 1 git git 17744793600 Jul  5 14:47 1530773117_2018_07_05_gitlab_backup.tar

3. Perform data recovery

Perform the following command to recover: type yes twice later to complete the recovery.

gitlab-rake gitlab:backup:restore BACKUP=1530773117_2018_07_05_gitlab_backup.tar

PS: Recovery may be a bit small depending on version

06 Appendix 1 Common Commands

# The default log home directory is/var/log/gitlab/

# Check the redis log
sudo gitlab-ctl tail redis

# Check postgresql's log
sudo gitlab-ctl tail postgresql

# Check the log of gitlab-workhorse
sudo gitlab-ctl tail gitlab-workhorse

# Check logrotate log
sudo gitlab-ctl tail logrotate
# Check logs for nginx
sudo gitlab-ctl tail nginx

# Check sidekiq logs
sudo gitlab-ctl tail sidekiq

# Check the log of Unicorns
sudo gitlab-ctl tail unicorn

sudo gitlab-ctl status  //Check whether the dependent service is running
sudo gitlab-ctl tail //Check if the service gitlab depends on is in error at runtime

sudo gitlab-rake gitlab:check //Check if the configuration is correct and if there is an error, resolve it as prompted

07 FAQ

Error 1

error: proxyRoundTripper: GET "/" failed with: "dial unix /var/opt/gitlab/gitlab-rails/sockets/gitlab.socket: connect: no such file or directory"

Reason: unicorn did not start properly
Resolution: View the logs of unicorns, /var/log/gitlab/unicorn/*.log, typically port conflicts or permissions issues.Depend on the log, hope you can solve it well, enjoy it.

08 Reference Documents

https://docs.gitlab.com/ee/development/architecture.html

Topics: Operation & Maintenance GitLab sudo git Redis