一、安裝前準備
安裝gitlab、Git、MySQL(這些安裝步驟我其他文章中寫的有)
本文中版本爲:Git 2.8.3 Gitlab 10.1.4 MySQL 5.7.24
我的系統版本爲:(系統可以不一樣)
[root@localhost ~]# cat /etc/redhat-release ##查看系統版本
CentOS Linux release 7.6.1810 (Core)
[root@localhost ~]# uname -r
3.10.0-229.el7.x86_64
1、首先編輯vim /opt/gitlab/embedded/service/gitlab-rails/.bundle/config文件
將BUNDLE_WITHOUT: "development:test:mysql" 改爲BUNDLE_WITHOUT: "development:test:postgres"
2、創建數據庫、用戶,並賦予所有權限。(MySQL8以上的版本創建用戶和權限的方式不一樣,網上自行百度)
create database gitlabhq_production DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; ##創建數據庫
GRANT ALL PRIVILEGES ON gitlabhq_production.*TO 'gitlab'@'%' IDENTIFIED BY 'gitlab' WITH GRANT OPTION; ##創建用戶並賦權
flush privileges; ##刷新數據庫
exit; ##保存退出
3、配置Gitlab添加MySQL,修改gitlab.rb文件中的配置如下:
[root@localhost ~]# vim /etc/gitlab/gitlab.rb
gitlab_rails['db_adapter'] = "mysql2"
gitlab_rails['db_encoding'] = "utf8"
gitlab_rails['db_collation'] = nil
gitlab_rails['db_database'] = "gitlabhq_production"
gitlab_rails['db_username'] = "gitlab"
gitlab_rails['db_password'] = "gitlab"
gitlab_rails['db_host'] = "192.168.190.147"
gitlab_rails['db_port'] = "3306"
postgresql['enable'] = false
4、重新配置gitlab,並安裝相關依賴。
[root@localhost gitlab]# gitlab-ctl reconfigure ##重新配置下gitlab
[root@localhost gitlab]# yum -y install ruby-devel ##安裝依賴
5、缺少 mysql2,用ruby的gem工具下載一個。進入/opt/gitlab/embedded/bin目錄中執行
[root@localhost gitlab]# cd /opt/gitlab/embedded/bin
[root@localhost bin]# ./gem install mysql2
Fetching: mysql2-0.5.2.gem (100%)
Building native extensions. This could take a while...
Successfully installed mysql2-0.5.2
Parsing documentation for mysql2-0.5.2
Installing ri documentation for mysql2-0.5.2
Done installing documentation for mysql2 after 1 seconds
1 gem installed
[root@localhost bin]# ./gem install mysql2
Fetching: mysql2-0.5.2.gem (100%)
Building native extensions. This could take a while...
Successfully installed mysql2-0.5.2
Parsing documentation for mysql2-0.5.2
Installing ri documentation for mysql2-0.5.2
Done installing documentation for mysql2 after 1 seconds
1 gem installed
6、更換gem源並刪除原有gem源,在/opt/gitlab/embedded/bin目錄中執行
[root@localhost bin]# /opt/gitlab/embedded/bin/gem source
*** CURRENT SOURCES ***
https://rubygems.org/
[root@localhost bin]# /opt/gitlab/embedded/bin/gem sources --add https://gems.ruby-china.com/ ##這裏的gem源要用.com結尾的。老版本的是.org結尾,但是網站更新已經不支持.org了
[root@localhost bin]# gem sources --remove https://rubygems.org/ ##刪除原來的gem源
https://rubygems.org/ removed from sources
7、確認系統中的gem 源已更新
[root@localhost bin]# /opt/gitlab/embedded/bin/gem source
*** CURRENT SOURCES ***
https://gems.ruby-china.com/
8、更改配置Gemfile文件的gem源,編輯vim /opt/gitlab/embedded/service/gitlab-rails/Gemfile文件,修改配置源爲:source 'https://gems.ruby-china.com'
9、更新gem install rubygems-bundler 和 gem regenerate_binstubs
[root@localhost bin]# gem install rubygems-bundler
Fetching: bundler-unload-1.0.2.gem (100%)
Successfully installed bundler-unload-1.0.2
Fetching: executable-hooks-1.5.0.gem (100%)
Building native extensions. This could take a while...
# In case of problems run the following command to update binstubs:
gem regenerate_binstubs
Successfully installed executable-hooks-1.5.0
Fetching: rubygems-bundler-1.4.5.gem (100%)
Successfully installed rubygems-bundler-1.4.5
Parsing documentation for bundler-unload-1.0.2
Installing ri documentation for bundler-unload-1.0.2
Parsing documentation for executable-hooks-1.5.0
Installing ri documentation for executable-hooks-1.5.0
Parsing documentation for rubygems-bundler-1.4.5
Installing ri documentation for rubygems-bundler-1.4.5
3 gems installed
[root@localhost bin]# gem regenerate_binstubs
try also: gem pristine --binstubs
rdoc 4.0.0
10、進入系統Gemfile所在的目錄,我的Gemfile文件是放在/opt/gitlab/embedded/service/gitlab-rails/目錄中的
[root@localhost bin]# cd /opt/gitlab/embedded/service/gitlab-rails/
[root@localhost gitlab-rails]# /opt/gitlab/embedded/bin/bundle install
11、重新啓動數據庫,否則在執行下一步gitlab檢查時會報錯,提示找不到數據表。必要時重新配置下gitlab也行。
[root@localhost gitlab-rails]# service mysqld restart
12、gitlab-rake gitlab:check檢查配置,這一步會花費一點時間,中間有需要輸入的地方,直接回車或者輸入yes都可以。
[root@localhost gitlab-rails]# gitlab-ctl reconfigure
13、初始化gitlab,執行gitlab-rake gitlab:setup 之後,會提示以前的數據信息會丟失掉。輸入yes繼續執行。這一步大家要考慮好,最好是提前吧數據庫數據備份好。以後可以恢復到新數據庫中。
[root@localhost gitlab-rails]# gitlab-rake gitlab:setup
14、重啓配置啓動。
[root@localhost gitlab-rails]# gitlab-ctl reconfigure ##重新配置gitlab
[root@localhost gitlab-rails]# service firewalld stop ##關閉防火牆
[root@localhost gitlab-rails]# gitlab-ctl restart ##重啓服務
[root@localhost gitlab-rails]# gitlab-ctl tail #查看啓動情況,ctl+C 可結束查看狀態
15、所有服務都起來後,後臺查看數據庫gitlabhq_production,可以看到數據庫中有了很多表。然後訪問gitlab頁面,此時第一次登錄gitlab,需要重新設置8位數的密碼,然後即可登錄gitlab,賬戶爲root。