gitlab升級和遷移


       由於近期公司gitlab服務器老是卡頓和出現其他問題,然后也很久沒有升級過了,現在版本還是8.10.5,而官網最新版本已經是11.2了。另一個原因是gitlab所在的這台服務器快到期了,想換一台配置更好些的服務器,故對此進行升級和遷移。

  升級思路:先在新服務器上安裝一個和原版本相同版本的gitlab,然后備份原版本gitlab數據,備份完在新服務器恢復,恢復完在進行升級。

  本文參照:https://github.com/gitlabhq/gitlab-recipes/tree/master/install/centos

安裝環境:

      操作系統CentOS  6.10

                      #Distribution     : CentOS  6.10

                      #GitLab version    : 8.10.5

                      #GitLab-shell      : 3.2.1

                      #Ruby version      : ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]

                      #Gem version       : 2.4.5

                      #Redis-server      : Redis server version3.2.11 

                      #Web Server        : Nginx/1.10.2

                      #Database          : mysql 5.7

1、添加epel庫

#wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 https://getfedora.org/static/0608B895.txt
#rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
驗證密鑰是否已成功安裝:
#rpm -qa gpg*
gpg-pubkey-0608b895-4bd22942

2、安裝epel-release-6-8.noarch包,它將在您的系統上啟用EPEL存儲庫:(這里雖然我們是6.10的系統,但裝這個也能用)

#rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

 驗證是否已啟用EPEL和remi-safe存儲庫:

 

如果看不到它們,請使用下面的命令(從yum-utils包中)啟用它們:

#yum-config-manager --enable epel --enable remi-safe

3、安裝gitlab所需的工具:

#yum -y update
#yum -y groupinstall 'Development Tools'
#yum -y install readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui redis sudo wget crontabs logwatch logrotate perl-Time-HiRes git cmake libcom_err-devel.i686 libcom_err-devel.x86_64 nodejs

# For reStructuredText markup language support, install required package:
#yum -y install python-docutils

RHEL備注

如果未安裝某些軟件包(例如gdbm-devel,libffi-devel和libicu-devel),請將rhel6可選軟件包repo添加到服務器以獲取這些軟件包:

#yum-config-manager --enable rhel-6-server-optional-rpms

4、安裝郵件服務器:

#yum -y install postfix

#chkconfig postfix on

5、安裝git(這里我們用源碼包安裝方式)

1)先移除系統中原有的低版本git:

#yum -y remove git

備注:默認centos的git版本是1.7.10,必須刪除后,再下載源碼進行安裝

2)安裝git的相關依賴包:

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

3)編譯安裝git:

#mkdir /tmp/git && cd /tmp/git
#curl --progress https://www.kernel.org/pub/software/scm/git/git-2.9.0.tar.gz | tar xz
#cd git-2.9.0 
#./configure --prefix=/usr/local/git
#make  && make install

4)配置環境變量:

在/etc/profile最后面加上下面這行,然后source /etc/profile使之生效

export PATH=/usr/local/git/bin:$PATH

5)驗證一下是否成功:

6、安裝ruby:

1)移除已有的ruby(如果存在)

yum -y remove ruby

注:如果是源碼包安裝的:

#cd <your-ruby-source-path> && make uninstall

2)編譯安裝ruby:

#mkdir /tmp/ruby && cd /tmp/ruby
#curl --progress https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz |tar xz
#cd ruby-2.2.2 && ./configure --prefix=/usr/local/ruby --disable-install-rdoc && make && make install

3)配置環境變量:

同理在/etc/profile文件最后加上下面一句,並且執行source /etc/profile使之生效。

export PATH=/usr/local/ruby/bin:$PATH

4)驗證是否成功:

5)安裝bundler:

#gem install bundler --no-rdoc

#gem install charlock_holmes

7、安裝go編譯器:

從GitLab 8.0開始,Git HTTP請求由gitlab-workhorse(以前的gitlab-git-http-server)處理。這是一個用Go編寫的小守護進程。要安裝gitlab-workhorse,我們需要一個Go編譯器

#yum -y install golang golang-bin golang-src

8、為gitlab創建系統用戶:

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

9、數據庫安裝和相關庫的創建:

這里由於我們之前版本gitlab使用的是騰訊雲的數據庫,這里就不在另外安裝數據庫了,直接在數據庫相關配置文件里配置之前數據庫的信息即可。

10、安裝配置redis:

1)同樣先刪除舊的redis

#yum -y remove redis

2)重新安裝redis:

#yum -y install redis

裝完后查看下版本:

3)修改redis配置文件:

a、備份配置文件

#cp /etc/redis.conf /etc/redis.conf.bak

#mkdir /var/run/redis

b、修改/tmp/redis.sock為/var/run/redis/redis.sock

 

c、修改/var/run/redis/redis.sock的權限為755

#chown redis:redis /var/run/redis

#chmod 755 /var/run/redis

d、配置redis自啟動

#chkconfig --level 35 redis on

e、啟動redis並驗證

f、附加git到redis組

#usermod -aG redis git

 11、安裝gitlab

1)取gitlab源代碼

#su - git
$cd /data/gitlab $git clone https://gitlab.com/gitlab-org/gitlab-ce.git gitlab $cd /gitlab $git branch -a #查看遠程分支 $git checkout -b v8.10.5 #切換到8.10.5版本分支上
$cat VERSION
8.10.5

2)修改配置文件

$cp config/gitlab.yml.example config/gitlab.yml

$vim config/gitlab.yml

這里host我隨便配置的一個域名,以自身情況進行配置

$cp config/secrets.yml.example config/secrets.yml
$chmod 0600 config/secrets.yml
$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
#查看系統核心數
$nproc
4
$vim config/unicorn.rb #下面的worker_processes就是配置成上面nproc的值

$cp config/resque.yml.example config/resque.yml

$vim config/resque.yml (redis配置文件)

配置mysql:

$cp config/database.yml.mysql config/database.yml

$vim config/database.yml

12、安裝gem  --網上都說換成淘寶源,但我裝的時候用官網源也不卡,所以就沒換

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

13、安裝gitlab-shell

$cat /data/gitlab/gitlab/GITLAB_SHELL_VERSION --先查看此版本的gitlab需安裝什么版本的gitlab-shell
3.2.1
$su - git
$sudo -u git -H bundle exec rake gitlab:shell:install[v3.2.1] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production

配置config.yml文件

$cp gitlab-shell/config.yml.example  gitlab-shell/config.yml

$vim gitlab-shell/config.yml

執行安裝命令,創建對應目錄和文件

$cd gitlab-shell

$./bin/install

14、安裝gitlab-workhorse

$cd /data/gitlab
$git clone https://gitlab.com/gitlab-org/gitlab-workhorse.git
$cat gitlab/GITLAB_WORKHORSE_VERSION  --查看需要安裝哪個版本的gitlab-workhorse
0.7.8
$cd gitlab-workhorse/
$git checkout v0.7.8
$cat gitlab-workhorse/VERSION
0.7.8
$make

15、設置啟動腳本

$cp lib/support/init.d/gitlab /etc/init.d/gitlab
$chkconfig gitlab on

$vim /etc/init.d/gitlab

16、設置logrotate日志切割(可選操作)

$cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

17、配置web服務器:

這里我們配置nginx為例:

1)安裝nginx:

#yum -y update

#yum -y install nginx

#chkconfig nginx on

2)配置gitlab

#cp /data/gitlab/gitlab/lib/support/nginx/gitlab /etc/nginx/conf.d/gitlab.conf

#vim /etc/nginx/conf.d/gitlab.conf

修改完用nginx -t 檢測下語法有沒有錯誤,沒有錯誤的話就可以啟動nginx了.

18、檢查gitlab環境基礎:

$bundle exec rake gitlab:env:info RAILS_ENV=production

為了沒有遺漏任何內容,進行更徹底的檢查:

$bundle exec rake gitlab:check RAILS_ENV=production

如果檢測出來都是綠色的,那么說明沒有問題,可以啟動gitlab了。

#service gitlab start

至此,gitlab就安裝完成了,接下來進行備份遷移。

這里我們把舊版本那台服務器稱為A服務器,上面新裝的服務器稱為B服務器,以便下文書寫方便:

1、備份數據:

1)升級遷移前先對A服務器上的gitlab作備份:

#su - git
$cd /data/gitlab/gitlab
$bundle exec rake gitlab:backup:create RAILS_ENV=production

備份的文件在/data/gitlab/gitlab/tmp/backups目錄下:

2)備份數據庫:這里由於使用的是第三方數據庫(騰訊雲數據庫),上面數據庫配置這塊已經配了那個數據庫地址,這里就不在進行備份了。

3)備份keys

$cp /data/gitlab/.ssh/authorized_keys /tmp/authorized_keys

4)備份repositories目錄

$cd /data/gitlab

$tar zxvf repositories.tar.gz ./repositories

把A服務器上備份的數據拷貝到B服務器:

#scp -P 36022 xxx_gitlab_backup.tar authorized_keys repositories.tar.gz xxx@xxx.xxx.xxx.xxx:/.......

2、恢復數據

1)導入倉庫,檢查權限

$cd /data/gitlab

$tar xvf repositories.tar.gz  --A服務器拷貝過來的包

$chmod -R git. /data/gitlab/repositories

2)導入keys

$cat authorized_keys >>/data/gitlab/.ssh/authorized_keys

3)導入repos

$cd /data/gitlab/gitlab

$bundle exec rake gitlab:import:repos RAILS_ENV=production

3、檢測

$cd /data/gitlab/gitlab

$bundle exec rake gitlab:check RAILS_ENV=production

檢測沒有問題就可以重啟gitlab了

#service gitlab restart

重啟完登入web客戶端檢查下數據一致性,沒有問題的話,接着就可以進行升級了。

1、首先停掉B服務器的gitlab服務,在進行升級

#service gitlab stop

2、獲取最新版本分支

$su -git
$cd /data/gitlab/gitlab
$git fetch --all
$git checkout -- Gemfile.lock db/schema.rb
$git checkout v10.8 -b v10.8 --切換到要升級到的版本分支
$cat VERSION

3、升級gitlab-shell

$ cd /data/gitlab/gitlab-shell
$ git fetch
$ git checkout v`cat /data/gitlab/gitlab/GITLAB_SHELL_VERSION` -b v`cat /data/gitlab/gitlab/GITLAB_SHELL_VERSION`

4、升級gitlab-workhorse

$ cd /data/gitlab/gitlab-workhorse
$ git fetch
$ git checkout v`cat /data/gitlab/gitlab/GITLAB_WORKHORSE_VERSION` -b v`cat /data/gitlab/gitlab/GITLAB_WORKHORSE_VERSION`
$make

5、安裝庫環境

$cd /data/gitlab/gitlab
# PostgreSQL
    $bundle install --without development test mysql --deployment
# MySQL
    $bundle install --without development test postgres --deployment
# Optional:
  clean up old gems $bundle clean
# Run database migrations
  $bundle exec rake db:migrate RAILS_ENV=production
# Clean up assets and cache
  $bundle exec rake assets:clean assets:precompile cache:clear RAILS_ENV=production

6、啟動gitlab

#service gitlab restart
#service nginx restart

7、檢查程序狀態

檢查GitLab及其環境是否配置正確: 
$ bundle exec rake gitlab:env:info RAILS_ENV=production 
確保沒有報錯,運行一次更徹底的檢查: 
$bundle exec rake gitlab:check RAILS_ENV=production 
如果所有項目是綠色的,那么恭喜你升級完成! 
gitlab從8.10.5升級到10.8到此結束。

 

 

 

 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM