GitLab official construction tutorial address: https://about.gitlab.com/install/#ubuntu
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.
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.
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
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.
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.
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.
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
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.
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
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.
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
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
chmod 777 1550415608_2019_02_17_11.5.1_gitlab_backup.tar
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
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