歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> GitLab 7.9 升級到 8.0.1

GitLab 7.9 升級到 8.0.1

日期:2017/2/28 13:52:59   编辑:Linux教程

1.gitlab8.0更新說明

GitLab 8.0 現在完全集成了持續集成工具 (GitLab CI) ,此外還完全重寫了 UI,節省了至少 50% 的磁盤空間。更快的合並,內置持續集成(CI)到 GitLab 本身,提高了界面和導航,以及“通過電子郵件回復”功能,它可以使用戶通過移動設備就能夠對某個問題上迅速發表評論,或者合並請求。

GitLab 8.0 主要改進:

  • 更好的 HTTP 支持
  • 郵件快速回復
  • Gmail 快速打開
  • 改善文件上傳功能
  • 改進 Mattermost
  • Web hooks 的 SSL 認證

更多更新請查看gitlab官網https://github.com/gitlabhq/gitlabhq/blob/master/CHANGELOG

2.gitlab7.9環境

2.1 gitlab7.9安裝說明

系統為CentOS6.7,gitlab7.9為源碼安裝,默認位置為/home/git/gitlab,我安裝位置:/usr/local/git/gitlab,因此請注意你的gitlab安裝位置是否使用默認,相應更改下面的配置

2.2 升級准備

由於gitlab使用git用戶管理,因此我們應當以git身份執行相關配置,升級前請檢查gitlab運行正常

sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

2.3 備份gitlab

升級有風險,因此先做好備份

sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production

如果gitlab運行在虛擬機中,最好給虛擬機做快照,以便更新失敗時恢復

2.4 停止gitlab

升級前先停止gitlab運行

service gitlab stop

service gitlab stop

2.5檢查gitlab相關組件版本

#gitlab8.0組件版本要求
Redis version >= 2.4.0
Ruby version >= 2.1.0
Git version >= 1.7.10
GitLab Shell version >= 2.6.5

組件版本要求如下,如果版本過低請升級,升級參考2.6,2.7步驟

2.6 升級git版本

#檢查git版本
git --version
#升級git
cd /opt/
curl -L --progress https://www.kernel.org/pub/software/scm/git/git-2.4.3.tar.gz | tar xz
./configure
make prefix=/usr/local all -j 4
make prefix=/usr/local install

2.7 升級ruby版本

#下載
wget ftp://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.6.tar.gz
#安裝
tar xvf ruby-2.1.6.tar.gz
cd ruby-2.1.6
./configure --disable-install-rdoc
make -j 4
make install
#配置
gem install bundler --no-ri --no-rdoc
#如果/usr/bin/下存在ruby鏈接,先刪除
ln -s /usr/local/bin/ruby /usr/bin/ruby
ln -s /usr/local/bin/gem /usr/bin/gem
ln -s /usr/local/bin/bundle /usr/bin/bundle

3.升級gitlab到8.0.1

3.1 使用git命令升級gitlab到8.0.1

#進入gitlab安裝目錄
cd /usr/local/git/gitlab
sudo -u git -H git fetch --all
sudo -u git -H git checkout -- Gemfile.lock db/schema.rb
#獲取最新版本,保存在LATEST_TAG變量中
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
#commit是為了提交更改,不然無法cheout到最新版本
sudo -u git git commit -a
sudo -u git -H git checkout $LATEST_TAG -b $LATEST_TAG
#驗證當前版本
sudo -u git git branch -l
#注意:checkout到gitlab8.0.1之後,/usr/local/git/gitlab下的文件為8.0.1版本,但是config/gitlab.yml,config/database.yml等配置文件仍位舊版本7.9的配置文件,後面會更新這些文件

3.2升級gitlab-shell

#進入gitlab-shell主目錄
cd /usr/local/git/gitlab-shell/
sudo -u git -H git fetch
#注意下面路徑/usr/local/git/gitlab為gitlab安裝目錄,如果你的位於/home/git/gitlab請更改下面命令
sudo -u git -H git checkout v`cat /usr/local/git/gitlab/GITLAB_SHELL_VERSION` -b v`cat /usr/local/git/gitlab/GITLAB_SHELL_VERSION`
#驗證gitlab版本
sudo -u git git branch -l

3.3安裝gitlab-git-http-server

3.3.1下載go 1.5版本

#下載go 1.5版本
cd /opt
curl -O --progress https://storage.googleapis.com/golang/go1.5.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.5.linux-amd64.tar.gz
ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/
ln -s /usr/local/bin/go /usr/bin/

3.3.2安裝gitlab-git-http-server

cd /usr/local/git
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-git-http-server.git
cd gitlab-git-http-server/
sudo -u git -H make

3.4安裝ruby依賴包

#由於ruby官網鏈接過慢,因此更改ruby源
cd /usr/local/git/gitlab
#修改Gemfile文件
source "https://rubygems.org/" 改為 source "http://ruby.taobao.org/"
#修改Gemfile.lock文件
remote: https://rubygems.org/ 改為 remote: http://ruby.taobao.org/
#執行安裝(使用mysql,如果你使用postgress,請更改下面postgress為mysql)
yum install cmake
sudo -u git -H bundle install --without postgres development test aws --deployment

3.5遷移數據庫

安裝依賴

yum install nodejs

建立表結構,如果不導入表結構,遷移數據庫時會提示找不到表ci_builds

cat gitlab_builds.sql

DROP TABLE IF EXISTS `ci_builds`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `ci_builds` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`project_id` int(11) DEFAULT NULL,
`status` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`finished_at` datetime DEFAULT NULL,
`trace` longtext COLLATE utf8_unicode_ci,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`started_at` datetime DEFAULT NULL,
`runner_id` int(11) DEFAULT NULL,
`coverage` float DEFAULT NULL,
`commit_id` int(11) DEFAULT NULL,
`commands` text COLLATE utf8_unicode_ci,
`job_id` int(11) DEFAULT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`deploy` tinyint(1) DEFAULT '0',
`options` text COLLATE utf8_unicode_ci,
`allow_failure` tinyint(1) NOT NULL DEFAULT '0',
`stage` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`trigger_request_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `index_ci_builds_on_commit_id` (`commit_id`) USING BTREE,
KEY `index_ci_builds_on_project_id_and_commit_id` (`project_id`,`commit_id`) USING BTREE,
KEY `index_ci_builds_on_project_id` (`project_id`) USING BTREE,
KEY `index_ci_builds_on_runner_id` (`runner_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;DROP TABLE IF EXISTS `ci_commits`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `ci_commits` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`project_id` int(11) DEFAULT NULL,
`ref` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`sha` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`before_sha` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`push_data` mediumtext COLLATE utf8_unicode_ci,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`tag` tinyint(1) DEFAULT '0',
`yaml_errors` text COLLATE utf8_unicode_ci,
`committed_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `index_ci_commits_on_project_id_and_committed_at_and_id` (`project_id`,`committed_at`,`id`) USING BTREE,
KEY `index_ci_commits_on_project_id_and_committed_at` (`project_id`,`committed_at`) USING BTREE,
KEY `index_ci_commits_on_project_id_and_sha` (`project_id`,`sha`) USING BTREE,
KEY `index_ci_commits_on_project_id` (`project_id`) USING BTREE,
KEY `index_ci_commits_on_sha` (`sha`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

導入表結構

mysql -uroot -p gitlab_production < gitlab_builds.sql

執行遷移

sudo -u git -H bundle exec rake db:migrate RAILS_ENV=production

重建緩存

sudo -u git -H bundle exec rake assets:clean assets:precompile cache:clear RAILS_ENV=production

3.6 配置更新

上面說過,雖然用git拉取了gitlab最新版本(8.0.1)但相關配置文件仍為7.9版本,因此需要更新

3.6.1 更新啟動文件

#主目錄
cd /usr/local/git/gitlab
#更新啟動程序
cp lib/support/init.d/gitlab /etc/init.d/gitlab
#更新gitlab配置
cp lib/support/init.d/gitlab.default.example /etc/default/gitlab
#需要修改/etc/default/gitlab文件,因為我們的gitlab安裝在/usr/local/git下,並非默認目錄/home/git
sed -i "s/home/usr\/local/g" /etc/default/gitlab

3.6.2 更新日志

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

3.6.3 更新nginx配置文件

#更新gitlab的nginx配置
cp lib/support/nginx/gitlab /etc/nginx/conf.d/gitlab.conf
#同樣,gitlab並非安裝在默認目錄,因此需要修改配置
sed -i "s/home/usr\/local/g" /etc/nginx/conf.d/gitlab.conf

3.6.4 更新gitlab.yml

cp config/gitlab.yml.example config/gitlab.yml
#當然,需要更改gitlab.yml中的配置,可以參考舊版本配置文件,新配置文件更改了一些結構,但大部分變量都沿用舊版本的

3.6.5 更新database.yml

cp config/database.yml.mysql config/database.yml
#也需要更新配置

3.6.6 更新gitlab-shell配置文件

cd /usr/local/git/gitlab-shell/
cp config.yml.example config.yml
#相關配置也要更新

4 測試gitlab8.0.1

4.1 啟動gitlab

/etc/init.d/gitlab start

4.2 變量檢查

sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

4.3 檢查所有模塊是否運行正常

sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

參考:

https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/update/7.14-to-8.0.md

Copyright © Linux教程網 All Rights Reserved