CentOS7 installation and maintenance of Gitlab

Official installation method##

The following is the official installation method copied from the official website. The simplest installation is in my great empire. You can only visit the foreign website to install it or skip here. See below.

  1. Install and configure the necessary dependencies

If you install Postfix to send email please select 'Internet Site' during setup. Instead of using Postfix you can also use Sendmail or configure a custom SMTP server and configure it as an SMTP server.

On Centos 6 and 7, the commands below will also open HTTP and SSH access in the system firewall.

sudo yum install curl openssh-server openssh-clients postfix cronie
sudo service postfix start
sudo chkconfig postfix on
sudo lokkit -s http -s ssh
  1. Add gitlab server package and installation package
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo yum install gitlab-ce

If you are not comfortable installing the repository through a piped script, you can find the entire script here and select and download the package manually and install using gitlab/gitlab-ce

curl -LJO https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/6/gitlab-ce-XXX.rpm/download
curl -LJO https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-10.2.2-ce.0.el7.x86_64.rpm/download
rpm -i gitlab-ce-XXX.rpm
  1. Configure and start GitLab
sudo gitlab-ctl reconfigure
  1. Browser open and log in

On your first visit, you'll be redirected to a password reset screen to provide the password for the initial administrator account. Enter your desired password and you'll be redirected back to the login screen.

The default account's username is root. Provide the password you created earlier and login. After login you can change the username if you wish.

Third-party mirror installation##

Edit source

Create a new /etc/yum.repos.d/gitlab-ce.repo, the content is

Use Tsinghua University TUNA mirror source to open the URL and copy the content to the gitlab-ce.repo file, edit the path vim /etc/yum.repos.d/gitlab-ce.repo

[ gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key

Update local YUM cache###

sudo yum makecache

Install Community Edition###

sudo yum install gitlab-ce 
#( Install the latest version automatically)

sudo yum install gitlab-ce-8.15.2-ce.0.el6 
#( Install the specified version)

Change configuration###

vim /etc/gitlab/gitlab.rb
# Find external_url 'http://000.00.00.00:8081'
# Modify to your address

Configure and start GitLab

# turn on`/etc/gitlab/gitlab.rb`,
# will`external_url = 'http://git.example.com'`Modify it to your own IP address:`http://xxx.xx.xxx.xx`,
# Then execute the following command to compile GitLab.
sudo gitlab-ctl reconfigure
# clear cache
sudo gitlab-rake cache:clear RAILS_ENV=production

Log in to GitLab

Username: root 
Password: 5iveL!fe

Uninstall##

sudo gitlab-ctl uninstall

Operation and maintenance##

# Modify the default configuration file
sudo vim /etc/gitlab/gitlab.rb

# View version
sudo cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

# echo "vm.overcommit_memory=1">>/etc/sysctl.conf
# sysctl -p
# echo never >/sys/kernel/mm/transparent_hugepage/enabled
# Check gitlab
gitlab-rake gitlab:check SANITIZE=true--trace
gitlab-rake gitlab:check
gitlab-rake gitlab:check SANITIZE=true

# View log
gitlab-ctl tail

# Database relationship upgrade
gitlab-rake db:migrate

# Clear cache
gitlab-rake cache:clear

# Update gitlab package
yum update gitlab-ce

# Upgrade gitlab
yum install gitlab-ce

# Upgrade data command
gitlab-ctl pg-upgrade

Service Management###

gitlab-ctl start 
# Start all gitlab components:

gitlab-ctl stop  
# Stop all gitlab components:

gitlab-ctl stop postgresql 
# Stop all gitlab postgresql components:
# Stop related data connection services

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-ctl restart 
# Restart all gitlab components:

gitlab-ctl restart gitlab-workhorse 
# Restart all gitlab gitlab-workhorse component:

gitlab-ctl status 
# Check service status

gitlab-ctl reconfigure 
# Generate configuration start service

Log View###

sudo gitlab-ctl tail 
# View log

sudo gitlab-ctl tail redis 
# Check the redis log

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

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

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

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

sudo gitlab-ctl tail sidekiq  
# Check sidekiq logs

sudo gitlab-ctl tail unicorn  
# Check unicorn log

Reset administrator password###

The gitlab administrator password is forgotten, how to reset the password, Gitlab changes the root user password

Use rails tool to open terminal

sudo gitlab-rails console production

Query the user’s email, username, password and other information, id:1 means root account

user = User.where(id:1).first

Reset password

user.password ='new password'
user.password_confirmation ='new password'

Save password

user.save!

Complete operation ruby script

user = User.where(id:1).first
user.password ='new password'
user.password_confirmation ='new password'
user.save!

Backup and recovery##

It is very simple to install Gitlab using the Gitlab one-click installation package. The same backup recovery and migration are also very simple. You can create a complete Gitlab backup with one command:

Modify the default directory of the backup file###

Modify /etc/gitlab/gitlab.rb to modify the default directory for storing backup files:

gitlab_rails['backup_path']='/mnt/backups'

Create a backup

gitlab-rake gitlab:backup:create

The above command will create a compressed package named xxxxxxxx_gitlab_backup.tar in the /var/opt/gitlab/backups directory. This compressed package is the entire part of Gitlab, where xxxxxx at the beginning is the timestamp of the backup creation.

After modification, use the gitlab-ctl reconfigure command to reload the configuration file.

Start backup

Put your backup file folder and warehouse source files here.

/var/opt/gitlab/backups                   
# Backup file folder
/var/opt/gitlab/git-data/repositories     
# git repository source file

Automatic backup

Use the backup command to realize automatic backup through crontab

crontab -e
# Back up gitlab data at 2 o'clock every day
02***/usr/bin/gitlab-rake gitlab:backup:create
02***/opt/gitlab/bin/gitlab-rake gitlab:backup:create

After saving the above two lines, reload the configuration

service crond reload
# or
systemctl reload crond.service

Backup retention for seven days###

Set to save only the backup of the last 7 days, edit the /etc/gitlab/gitlab.rb configuration file, find the following code, delete the comment # save

# /etc/gitlab/gitlab.rb configuration file modify the following line
gitlab_rails['backup_keep_time']=604800

Reload the gitlab configuration file

sudo gitlab-ctl reconfigure  

Start recovery

Migration is the same as the steps of backup and recovery, you only need to copy the backup files in the /var/opt/gitlab/backups directory of the old server to /var/opt/gitlab/backups on the new server (if you have not modified the default If you back up the directory). Then execute the restore command. If modified, first enter the directory of the backup gitlab. This directory is gitlab_rails['backup_path'] in the configuration file, and the default is /var/opt/gitlab/backups.

Then stop unicorn and sidekiq to ensure that there is no new connection to the database and there will be no write data.

# Stop related data connection services

gitlab-ctl stop unicorn
# ok: down: unicorn: 0s, normally up

gitlab-ctl stop sidekiq
# ok: down: sidekiq: 0s, normally up

# Restore from xxxxx numbered backup

# Then restore the data, 1406691018 is the timestamp of the backup file

gitlab-rake gitlab:backup:restore BACKUP=1406691018
# New version 1483533591_2017_01_04_gitlab_backup.tar

gitlab-rake gitlab:backup:restore BACKUP=1483533591_2017_01_04_gitlab_backup.tar
# Start Gitlab

sudo gitlab-ctl start

It is judged that the gitlab related user who performed the actual operation: git, did not get sufficient permissions. Execute commands in sequence:

# No permission during recovery

mkdir /var/opt/gitlab/backups
chown git /var/opt/gitlab/backups
chmod 700/var/opt/gitlab/backups

# The recovery success page reports an error of no permission

sudo chown -R git:git /var/opt/gitlab/git-data/repositories
sudo chmod -R ug+rwX,o-rwx /var/opt/gitlab/git-data/repositories
sudo chmod -R ug-s /var/opt/gitlab/git-data/repositories
sudo find /var/opt/gitlab/git-data/repositories -type d -print0 | sudo xargs -0 chmod g+s

If the backup file report does not have permission, use ls -al to check whether the permission is git instead of root, and give the git user permission by the following method

sudo chown -R git:git 1483533591_2017_01_04_gitlab_backup.tar

Violence Escalation##

Directly edit the source /etc/yum.repos.d/gitlab-ce.repo, install GitLab Community Edition

sudo yum install gitlab-ce 
#( Install the latest version automatically)

sudo yum install gitlab-ce-8.15.2-ce.0.el6 
#( Install the specified version)

Error during installation

gitlab preinstall: Automatically backing up only the GitLab SQL database(excluding everything else!)
Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... pg_dump:[archiver(db)] connection to database "gitlabhq_production" failed: could not connect to server:No such file or directory
 Is the server running locally and accepting
 connections on Unix domain socket "/var/opt/gitlab/postgresql/.s.PGSQL.5432"?
Backup failed
[ FAILED]
gitlab preinstall:
gitlab preinstall: Backup failed! If you want to skip this backup, run the following command and
gitlab preinstall:try again:
gitlab preinstall:
gitlab preinstall:   sudo touch /etc/gitlab/skip-auto-migrations
gitlab preinstall:
error:%pre(gitlab-ce-8.15.2-ce.0.el6.x86_64) scriptlet failed, exit status 1
Error in PREIN scriptlet in rpm package gitlab-ce-8.15.2-ce.0.el6.x86_64
error:   install:%pre scriptlet failed(2), skipping gitlab-ce-8.15.2-ce.0.el6
gitlab-ce-8.11.5-ce.0.el6.x86_64 was supposed to be removed but is not!
 Verifying  : gitlab-ce-8.11.5-ce.0.el6.x86_64    1/2
 Verifying  : gitlab-ce-8.15.2-ce.0.el6.x86_64    2/2

Failed:
 gitlab-ce.x86_64 0:8.11.5-ce.0.el6

Looking at the above piles of errors, I was stunned in an instant. I saw a savior command that made me try to run sudo touch /etc/gitlab/skip-auto-migrations so I forced to re-run yum install gitlab-ce , The installation was really successful, ?.

...
gitlab: Thank you for installing GitLab!
gitlab: To configure and start GitLab, RUN THE FOLLOWING COMMAND:

sudo gitlab-ctl reconfigure

gitlab: GitLab should be reachable at http://114.55.148.71:8081
gitlab: Otherwise configure GitLab for your system by editing /etc/gitlab/gitlab.rb file
gitlab: And running reconfigure again.
gitlab:
gitlab: For a comprehensive list of configuration options please see the Omnibus GitLab readme
gitlab: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
gitlab:

gitlab: GitLab now ships with a newer version ofPostgreSQL(9.6.1), and will be used
gitlab:as the defaultin the next major relase. To upgrade, RUN THE FOLLOWING COMMANDS:

sudo gitlab-ctl pg-upgrade

gitlab: For more details, please see:
gitlab: https://docs.gitlab.com/omnibus/settings/database.html#upgrade-packaged-postgresql-server
gitlab:
 Clean up: gitlab-ce-8.11.5-ce.0.el6.x86_64                                                                                                                                                             2/2
Found /etc/gitlab/skip-auto-migrations, exiting...
 Verifying  : gitlab-ce-8.15.2-ce.0.el6.x86_64                                                                                                                                                             1/2
 Verifying  : gitlab-ce-8.11.5-ce.0.el6.x86_64                                                                                                                                                             2/2

update completed:
 gitlab-ce.x86_64 0:8.15.2-ce.0.el6

complete!

Restarting the configuration can solve most of the 502 errors.

gitlab-ctl reconfigure

Error handling##

Solve 80 port is occupied

Nginx configuration solves 80 port is occupied

upstream gitlab {
 server 114.55.111.111:8081;}
server {
 # Listening port 80
 listen       80; 
 server_name  git.diggg.cn;  
 location /{    
 proxy_pass   http://gitlab;    #Set up a proxy here, with the same name as upstream
 # The following are some reverse proxy configurations that can be deleted
 proxy_redirect             off; #The back-end web server can pass X-Forwarded-For obtaining user's real IP
 proxy_set_header           Host $host;    
 proxy_set_header           X-Real-IP $remote_addr;    
 proxy_set_header           X-Forwarded-For $proxy_add_x_forwarded_for;    
 client_max_body_size       10m; #Maximum number of single file bytes allowed by the client
 client_body_buffer_size    128k; #The maximum number of bytes requested by the buffer agent to buffer the client
 proxy_connect_timeout      300; #Nginx connects to the backend server timeout time(Agent connection timed out)
 proxy_send_timeout         300; #Backend server data return time(Proxy sending timeout)
 proxy_read_timeout         300; #After a successful connection, the back-end server response time(Proxy receiving timeout)
 proxy_buffer_size          4k; #Set the buffer size of the proxy server (nginx) to save user header information
 proxy_buffers              4 32k; #proxy_buffers, if the average web page is below 32k, set this way
 proxy_busy_buffers_size    64k; #Buffer size under high load (proxy_buffers*2)
 proxy_temp_file_write_size 64k; #Set the size of the cache folder, greater than this value, will be uploaded from the upstream server
  }}

Nginx configuration check and take effect immediately

# Check configuration
/usr/local/nginx/sbin/nginx -tc conf/nginx.conf
# nginx reload configuration
/usr/local/nginx/sbin/nginx -s reload

The avatar cannot be displayed normally###

Reason: gravatar is walled. Solution: Edit /etc/gitlab/gitlab.rb, change

# gitlab_rails['gravatar_plain_url']='http://gravatar.duoshuo.com/avatar/%{hash}?s=%{size}&d=identicon'

change into:

gitlab_rails['gravatar_plain_url']='http://gravatar.duoshuo.com/avatar/%{hash}?s=%{size}&d=identicon'

Then execute on the command line:

sudo gitlab-ctl reconfigure 
sudo gitlab-rake cache:clear RAILS_ENV=production

internal API unreachable

This error is a self-made pit, I have no way to clone and submit, but the website can run normally, tried a lot of methods, in the end my problem is that the 22 port is not hidden, which is embarrassing.

GitLab: Failed to authorize your Git request: internal API unreachable

Solution: https://gitlab.com/gitlab-org/gitlab-ce/issues/33702 through the firewall rule 127.0.0.1

The proxy_temp directory has no permissions##

[ crit]14788#0:*215open()"/usr/local/nginx/proxy_temp/5/01/0000000015"failed(13: Permission denied)while reading upstream

Solved in the following way

chown -R root:root /usr/local/nginx/proxy_temp
# Edit nginx.conf

sudo vi /usr/local/nginx/conf/nginx.conf
# Add in the first line

user root;

Other errors###

Error executing action `run` on resource 
' bash[migrate gitlab-rails database]'

The above error is that the database is not started, I don't know how to start it, I restarted the server, and it was a hit. ? https://gitlab.com/gitlab-org/gitlab-ce/issues/2052#note_1667899

NameError: uninitialized constant Devise::Async
Processing by RootController#index as HTML
Completed 401 Unauthorized in17ms(ActiveRecord:2.7ms)
/var/log/gitlab/nginx/gitlab_access.log <==114.55.148.71--[04/Jan/2017:17:20:24+0800]"GET /favicon.ico HTTP/1.0"5022662"http://git.xxxxx.cn/" 
" Mozilla/5.0(Macintosh; Intel Mac OS X 10_12_2) 
AppleWebKit/537.36(KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36"

Recommended Posts

CentOS7 installation and maintenance of Gitlab
Centos7 installation and deployment of gitlab server
Centos7 installation and configuration of Jenkins
Centos6.5 installation and deployment of KVM
CentOS7 installation and maintenance of nginx from entry to master
Installation and use of Mysql under CentOS
Centos-6.5 installation and deployment of LNMP environment
Installation and configuration of redis under centos7
Centos7 installation and deployment of Airflow detailed
Graphical installation of CentOS8
Installation and configuration of JDK in CentOS 7 system
Centos7 installation of PHP and Nginx tutorial detailed
Installation and configuration of rsync server under CentOS 6.5
Installation and configuration of CentOS 7 in VMware Workstation
Installation, configuration and uninstallation of GitLab in Ubuntu19.1
Centos mysql installation and configuration
Centos7 installation and configuration prometheus
CentOS 7 installation and configuration PPTP
CentOS installation and configuration cmake
Centos7.5 installation and configuration MongoDB4.0.4
CentOS 7 installation and configuration PPTP
GitLab installation and basic use
centos7 kvm installation and use
Centos7 silent installation of Oracle11g
CentOS7 postgresql installation and use
CentOS environment installation of Docker
Centos7 elk7.1.1 installation and use
Installation and cracking of confluence6.3 operation records under Centos
Installation and cracking of Jira7 operation records under Centos
Analysis of Hyper-V installation CentOS 8 problem
Centos7 installation of Dameng database tutorial
CentOS 8 installation of MariaDB detailed tutorial
Installation under centos6.9 of jenkins learning
Detailed explanation of Spark installation and configuration tutorial under centOS7
Centos7 hadoop cluster installation and configuration
CentOS 7.X system installation and optimization
Java-JDK installation and configuration under CentOS
CentOS 7 Tomcat service installation and configuration
001. Installation of enterprise-level CentOS7.6 operating system
Centos8 minimal deployment and installation of OpenStack Ussuri detailed tutorial
Introduction to CentOS7 installation process of openjdk, tomcat and mysql
CentOS NTP server installation and configuration
2019-07-09 CentOS7 installation
centos7_1708 installation
CentOs7 installation and deployment Zabbix3.4 original
Erlang 20.2 installation and deployment under CentOS 7
Centos7 mysql database installation and configuration
CentOS 7 system installation and configuration graphic tutorial
ubuntu Docker installation and deployment of Rancher
MySQL 8.0 installation, deployment and configuration under CentOS 6/7
Linux kernel compilation and CentOS system installation
Centos7.6 operating system installation and optimization record
Installation and uninstallation of CUDA under Ubuntu 16.04
Installation and deployment of Nginx in Ubuntu
Installation and use of Win10 subsystem Ubuntu
Centos python3 compile installation and compile gcc upgrade
Zabbix installation and deployment and localization under CentOS
Centos7 hive stand-alone mode installation and configuration
CentOS7 installation zabbix 4.0 tutorial (graphics and text)
Jenkins installation and deployment tutorial under CentOS 7
KVM installation and preliminary use under CentOS 7.2