CentOS 6.5 Compile and Install gitlab

Keywords: GitLab git Redis Ruby

Reference resources
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/install/installation.md
https://bbs.gitlab.cc/topic/35/gitlab-ce-8-7-%E6%BA%90%E7%A0%81%E5%AE%89%E8%A3%85%E6%89%8B%E5%86%8C-centos6-rehl6/2

I. Configuration Foundation
1. Install epel source

yum -y install epel-release  vim wget ntpdate gcc gcc-c++ -y
/usr/sbin/ntpdate -us stdtime.gov.hk ntp.sjtu.edu.cn
hwclock -w

2. Install puias source

vi /etc/yum.repos.d/puias-computational.repo
[PUIAS_6_computational]
name=PUIAScomputational Base $releasever - $basearch
mirrorlist=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch/mirrorlist
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puias
cd /etc/pki/rpm-gpg/
wget -q http://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias
rpm --import RPM-GPG-KEY-puias
yum repolist

II. Installation Foundation Dependency Package

yum -y install gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel \
db4-devel byacc libyaml libyaml-devel libffi libffi-devel \
libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel\
 sudo  patch logwatch logrotate perl-Time-HiRes cmake\
 libcom_err-devel libcom_err-devel nodejs python-docutils

Upgrade all software packages to the latest

yum -y update

Install postfix mail server

yum install curl openssh-server postfix cronie -y
service postfix start
chkconfig postfix on
lokkit -s http -s ssh

Third, install git:
1. Remove the low version of git

yum remove git -y

Note: The default git version of centos is 1.7.10. It must be deleted before downloading the source code for installation.
2. Dependency packages for installing git

yum -y install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-devel openssl-devel

3. Compile and install git, pay attention to installing git version to match gitlab version

https://github.com/git/git/releases
tar -zxf git-2.4.3.tar.gz
cd git-2.4.3
make configure
./configure --prefix=/usr/local/git
make 
make install 

4. Configuration of swap variables

echo "export PATH=/usr/local/git/bin:\$PATH" >> /etc/profile
source /etc/profile

5. Verification procedures

which git
git --version 

IV. Installation of ruby
1. Remove the low version of ruby
The ruby version requires 2.0+, so unload the existing system first

yum remove ruby

2. Compile and install ruby

mkdir /soft/ruby && cd /soft/ruby
curl --progress https://cache.ruby-lang.org/pub/ruby/ruby-2.2.4.tar.gz
tar xvzf ruby-2.2.4.tar.gz
cd ruby-2.2.4 && ./configure --prefix=/usr/local/ruby --disable-install-rdoc && make && make install

3. Configure the swap variables and install gem

echo "export PATH=/usr/local/ruby/bin:\$PATH" >> /etc/profile
source /etc/profile
wget http://192.168.0.8:8090/Redis/rubygems-2.6.2.tgz
tar xzf rubygems-2.6.2.tgz 
cd rubygems-2.6.2   
/usr/local/ruby/bin/ruby setup.rb 

4. Verification procedures

which ruby
ruby --version

5. Install bundler
Delete official source images using Taobao

gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/ 
gem sources -l
gem install bundler --no-rdoc
gem install charlock_holmes

Install go language

mkdir /tmp/go && cd /tmp/go
curl -O --progress http://www.golangtc.com/static/go/1.5.3/go1.5.3.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.5.3.linux-amd64.tar.gz
ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/

5. Creating System Users (git)

adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git

Installation and Configuration of MariaDB
Create database users and authorize

yum install -y mysql-server mysql-client libmysqlclient-dev
mysql -u root -p 
create database gitlabhq_production character set utf8;
grant all privileges on gitlabhq_production.*to git@localhost identified by '123456';
flush privileges;

7. Installation and configuration redis

mkdir /soft/redis && cd /soft/redis
wget http://192.168.0.8:8090/Redis/redis-3.0.7.tar.gz
tar xzf redis-3.0.7.tar.gz 
cd   redis-3.0.7
make
make install 
mkdir -p /etc/redis
cp redis.conf /etc/redis

Modify redis configuration

cp /etc/redis/redis.conf /etc/redis/redis.conf.orig
# Set'post'to 0 to prohibit listening on TCP ports
sed 's/^port .*/port 0/' /etc/redis/redis.conf.orig | sudo tee /etc/redis/redis.conf
# Let redis start in socket mode
echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis/redis.conf
# Launch daemons
sed -i 's/daemonize no/daemonize yes/g' /etc/redis/redis.conf
# Create a directory to store socket s
mkdir /var/run/redis
chown redis:redis /var/run/redis
chmod 755 /var/run/redis
# Persist the directory which contains the socket, if applicable
if [ -d /etc/tmpfiles.d ]; then
  echo 'd  /var/run/redis  0755  redis  redis  10d  -' | sudo tee -a /etc/tmpfiles.d/redis.conf
fi
# Add git users to redis group
usermod -aG redis git
# Download redis init script
curl -L http://packages.gitlab.cc/install/init-script/redis/cenots6/redis-server -o /etc/init.d/redis-server
chmod +x /etc/init.d/redis-server

Eighth, install gitlab
1). Take the gitlab source code:

mkdir /soft/gitlab && cd /soft/gitlab
wget https://github.com/gitlabhq/gitlabhq/archive/v8.3.4.tar.gz 
tar xvzf gitlabhq-8.3.4.tar.gz 
mv gitlabhq-8.3.4 /home/git/gitlab
cd /home/git/gitlab
cp config/gitlab.yml.example config/gitlab.yml

vi config/gitlab.yml

  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: git.host.com
    port: 80 
    .
    .
    .
  git:
    bin_path: /usr/local/git/bin/git

chown -R git.git /home/git/ 
su - git

(3) Check Creation Directory and Permissions

mkdir -p /home/git/gitlab-satellites
cd /home/git/gitlab
mkdir -p tmp/pids
mkdir -p tmp/sockets
chown -R git log/
chown -R git tmp/
chmod -R u+rwX,go-w log/
chmod -R u+rwX tmp/
chmod -R u+rwX tmp/pids/
chmod -R u+rwX tmp/sockets/
mkdir public/uploads/
chmod 0700 public/uploads
chmod -R u+rwX builds/
chmod -R u+rwX shared/artifacts/

cp config/unicorn.rb.example config/unicorn.rb
Note the modification of config/unicorn.rb:

working_directory "/home/git/gitlab"
listen "/home/git/gitlab/tmp/sockets/gitlab.socket"
listen "0.0.0.0:8080", :tcp_nopush => true
pid "/home/git/gitlab/tmp/pids/unicorn.pid"

cp config/secrets.yml.example config/secrets.yml
cp config/resque.yml.example config/resque.yml
cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

cp config/database.yml.mysql config/database.yml
Can be modified to

production:
  adapter: mysql2
  encoding: utf8
  collation: utf8_general_ci
  reconnect: false
  database: gitlabhq_production
  pool: 10
  username: git
  password: "123456"
  host: localhost
  socket: /var/lib/mysql/mysql.sock

cd /home/git/gitlab
vi Gemfile

source "https://rubygems.org" Modified into source "https://ruby.taobao.org"

2. Execute gem installation

$ bundle install --deployment --without development test postgres aws

10. Install gitlab-shell
1. Install gitlab-shell
Run the task of installing the gitlab shell (modify REDIS_URL according to your redis installation). If you don't have a clone gitlab-shell warehouse in advance, the official clone warehouse will be installed automatically:

$ bundle exec rake gitlab:shell:install REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production

By default, gitlab-shell configurations are produced based on Gitlab configurations.
You can run the following command to view and modify the configuration of gitlab-shell:
cat /home/git/gitlab-shell/config.yml

2) Install gitlab-workhorse

cd /home/git
git clone https://gitlab.com/gitlab-org/gitlab-workhorse.git
cd gitlab-workhorse
git checkout $(cat /home/git/gitlab/GITLAB_WORKHORSE_VERSION)
make

Initialization of the database and activation of advanced functions

cd /home/git/gitlab
bundle exec rake gitlab:setup RAILS_ENV=production

When this step is completed, a default administrator account will be generated:
root
5iveL!fe
12. Download gitlab startup service script

cd /home/git/gitlab
cp lib/support/init.d/gitlab /etc/init.d/gitlab
chmod +x /etc/init.d/gitlab
chkconfig --add gitlab
chkconfig --level 35 gitlab on 
#Setting logrotate (optional operation)
cp /home/git/gitlab/lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

Thirteen, Detecting Application Status
1. Check the basic environment

su - git
cd gitlab
bundle exec rake gitlab:env:info RAILS_ENV=production

2) Generating GitLab front-end resources

bundle exec rake assets:precompile RAILS_ENV=production

3. View application details

bundle exec rake gitlab:check RAILS_ENV=production

4. Start the service and verify it

service gitlab start

14. Backup and Restore gitlab
1) backup

bundle exec rake gitlab:backup:create RAILS_ENV=production 

2) recovery

bundle exec rake gitlab:backup:restore BACKUP=BACKUPTIME

15. Configuring nginx services

upstream gitlab {
  server unix:/home/git/gitlab/tmp/sockets/gitlab-workhorse.socket fail_timeout=0;
}
server {
  listen 0.0.0.0:80 default_server;
  server_name git.dwhd.org; ## Replace this with something like gitlab.example.com
  server_tokens off; ## Don't show the nginx version number, a security best practice
  root /home/git/gitlab/public;
  client_max_body_size 256m;
  access_log  /var/log/nginx/gitlab_access.log;
  error_log   /var/log/nginx/gitlab_error.log;
  location / {
    try_files $uri $uri/index.html $uri.html @gitlab;
  }
  location @gitlab {
    proxy_read_timeout      300;
    proxy_connect_timeout   300;
    proxy_redirect          off;
    proxy_set_header    Host                $http_host;
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto   $scheme;
    proxy_set_header    X-Frame-Options     SAMEORIGIN;
    proxy_pass http://gitlab;
  }
}

Posted by prinzcy on Tue, 02 Apr 2019 15:45:29 -0700