Ubuntu16.04 build GitLab server tutorial

GitLab official construction tutorial address: https://about.gitlab.com/install/#ubuntu

1. Dependent package installation###

sudo apt-get update
sudo apt-get install -y curl openssh-server ca-certificates

After the execution is complete, select Internet in the mail configuration.

2. GitLab installation###

2.1 Official tutorial

If you follow the official installation method, just run the following commands.

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash
sudo apt-get install gitlab-ce

However, the installation according to the official tutorial will be very slow.It is recommended to use the following methods to install using Tsinghua source.

2.2 Tsinghuayuan####

First trust GitLab's GPG public key

curl https://packages.gitlab.com/gpg.key 2>/dev/null| sudo apt-key add -&>/dev/null

Next open the text of gitlab-ce.list

sudo vim /etc/apt/sources.list.d/gitlab-ce.list

Then write the following

deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu xenial main

Finally :wq save and exit. After writing the text successfully, execute the following command to install GitLab.

sudo apt-get update
sudo apt-get install gitlab-ce

3. GitLab start

Start GitLab after installation is complete

sudo gitlab-ctl reconfigure

Open sshd and postfix services

service sshd start
service postfix start

Finally, enter the following command to check whether GitLab is running successfully.

sudo gitlab-ctl status

If it runs successfully, enter http://127.0.0.1 in the browser to access the GitLab interface. When you use it for the first time, GitLab will prompt to set a password. After the setting is completed, you can use it successfully.

4. GitLab configuration###

4.1 Change server IP address####

Open the gitlab.yml file

cd /opt/gitlab/embedded/service/gitlab-rails/config
sudo vim gitlab.yml

Found the following

gitlab:
 ## Web server settings(note: host is the FQDN,do not include http://)
 host: localhost
 port:80
 https:false

Modify localhost to the local IP, for example, modify it to 192.168.1.25.

gitlab:
 ## Web server settings(note: host is the FQDN,do not include http://)
 host:192.168.1.25
 port:80
 https:false

After the modification is completed and saved, restart the GitLab server.

sudo gitlab-ctl restart

After the restart is successful, you can access the GitLab server through http://192.168.1.25.

4.2 Change server port####

If the 80 and 8080 ports are occupied by other applications, such as apache, you must change the GitLab server port at this time, here change the port to 8081.

First open the gitlab.rb file

cd /etc/gitlab
vim gitlab.rb

Found the following

# nginx['listen_port']=nil

change into

nginx['listen_port']=8081

Next restart GitLab configuration

sudo gitlab-ctl reconfigure

Then restart the GitLab server

sudo gitlab-ctl restart

Finally, http://192.168.1.25:8081 can be used to access the gitlab server.

4.3 Set GitLab to start automatically

Set the GitLab startup command to be

sudo systemctl enable gitlab-runsvdir.service

The command to prohibit GitLab from booting up automatically is

sudo systemctl disable gitlab-runsvdir.service

5. GitLab Backup###

5.1 Create a backup file

Use the following command to create a GitLab backup

sudo gitlab-rake gitlab:backup:create

Then a file similar to 15504156082019021711.5.1gitlabbackup.tar will be created in the /var/opt/gitlab/backups directory. The beginning part is the date of creation.

5.2 Modify the backup directory

First open the gitlab.rb file

cd /etc/gitlab
vim gitlab.rb

Find the following command

gitlab_rails['backup_path']="/var/opt/gitlab/backups"

Then modify the following address. After the modification is completed, restart the configuration file to take effect.

sudo gitlab-ctl reconfigure

5.3 Set up automatic backup mechanism

Manual backup is too cumbersome, so automatic backup is set through crontab. In the crontab file, each line represents a task, and each field in each line represents a setting. There are 6 fields in crontab, and the first 5 fields set the execution time Section, the 6th field setting command.

m h dom mon dow user user command

among them

m: Represents the minute, which can be any integer from 0 to 59.
h: indicates the hour, which can be any integer from 0 to 23.
dom: Represents the date, which can be any integer from 1 to 31.
mon: Represents the month, which can be any integer from 1 to 12.
dow: indicates the day of the week, which can be any integer from 0 to 7, where 0 or 7 represents Sunday.
user: Indicates the executing user.
command: The command to be executed can be a system command or a script file (such as a shell file) written by yourself.

Now let's implement automatic backup of GitLab files at 23 o'clock every day, the crontab command is as follows

023***/opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1

To ensure safety, use the double backup mechanism. So add another crontab task, set 23:00 every day, and put the generated gitlab file on the external hard disk. The crontab command is as follows

123*** cp -rf /var/opt/gitlab/backups/* /media/cciip/New volume 1/gitlab_backup/

After editing the /etc/crontab file, you need to restart the crontab service, the command is as follows

# Reload the cron configuration file
sudo /usr/sbin/service cron reload
# Restart cron service
sudo /usr/sbin/service cron restart

At this point, automatic backup can be performed, and it is a dual backup mechanism.

5.4 Set backup expiration time####

GitLab is backing up every day, and the files will keep growing, so it is best to set an expiration time, such as 7 days.

First open the /etc/gitlab/gitlab.rb file

cd /etc/gitlab
sudo vim gitlab.rb

Find the following command

# gitlab_rails['backup_keep_time']=604800

change into

# 604800=60*60*24*7
gitlab_rails['backup_keep_time']=604800

Finally, restart the GitLab configuration file.

sudo gitlab-ctl reconfigure

5.5 Restore backup files####

If you want to migrate the GitLab server to another host, first make sure that the GitLab version of the new server is the same as the GitLab version of the old server.

Then copy the backup file to the new server. For example, at this time, I copy the backup file on the 192.168.1.25 server to 192.168.1.24. You can use the following command.

scp /var/opt/gitlab/backups/1550415608_2019_02_17_11.5.1_gitlab_backup.tar [email protected]:/var/opt/gitlab/backups

Then perform the following operations on the 192.168.1.24 server

  1. Change the backup file permissions to 777
chmod 777 1550415608_2019_02_17_11.5.1_gitlab_backup.tar
  1. Execute commands to stop related data connection services
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
  1. Execute commands to restore GitLab from the backup file
gitlab-rake gitlab:backup:restore BACKUP=1550415608_2019_02_17_11.5.1_gitlab_backup.tar

Finally start the GitLab server

sudo gitlab-ctl start

You can now access the GitLab server through http://192.168.1.24:8081.

Recommended Posts

Ubuntu16.04 build GitLab server tutorial
CentOS8.1 build Gitlab server detailed tutorial
[Linux] Build Samba server (ubuntu16.04)
ubuntu 16.04 build pptpd V** server
Build Ubuntu 12.04 cross compilation server
Build Nginx-RTMP live server on ubuntu
Ubuntu16.04 build php5.6 Web server environment
Build a file server on ubuntu
Ubuntu operation tutorial
Build a Minecraft Bedrock Edition server (Ubuntu)
Centos7 tutorial to build a master-slave DNS server
Linux (centos7) build gitlab
Ubuntu 18.04 LTS LAMP build
Ubuntu16.04 install Mongodb tutorial
ubuntu install nginx server
ubuntu14.04 install jdk1.8 tutorial
Tutorial for setting up FTP server in Ubuntu 16.04 environment
Build OpenV** Server under CentOS7
Android phone running Ubuntu tutorial
ubuntu16.04 build vim and pyt
Install OpenSSL 1.0.2 on Ubuntu Server 14.04
Ubuntu Server Chapter 8 DNS Service
Build OpenLDAP server under CentOS7
Ubuntu Server Chapter 3 Package Management
Configure tomcat on ubuntu server
Server upgrade Ubuntu 20.04 LTS record
Teach you how to build a Git server on Ubuntu
ubuntu install and configure GitLab
How to build an NFS file sharing server on Ubuntu 16.04
ubuntu1804 build the latest Suricata
Server upgrade Ubuntu 20.04 LTS record
Ubuntu server builds Java web server
ubuntu build python development environment
Ubuntu deploys squid proxy server
Initial setup of Ubuntu 16.04 server
Ubuntu 18.04.1 build Java environment and HelloWorld
Detailed ubuntu14.04 build (migration) hustoj record
Virtual machine Linux Ubuntu installation tutorial
Install Chef server workstation on Ubuntu 18.04
Install MySQL under Ubuntu 18.04 (graphic tutorial)
Centos6 method steps to build gitlab
Build an FTP server under centos7
Ubuntu 20.04 CUDA&cuDNN installation method (graphic tutorial)
Installation instructions for gitlab in Ubuntu
Ubuntu 16.04 installation graphic tutorial under VMware 12
Centos7 build java web server tomcat
Ubuntu Server Chapter 2 Command Line Basics
Build Discuz forum based on ubuntu
Use Ubuntu 16.04 for initial server setup
Install Oracle 11gR2 on Ubuntu Server 12.4.0
Ubuntu uses Docker to install Gitlab