CI 系統搭建:二. GitLab 的安裝配置


 

上一篇文章 CI 系統搭建:一. 基礎環境設置、規划 大概規划了下環境,本文主要用來記錄安裝 Gitlab 的過程,主要參考官方文檔 並沒有做太多的修改。

 

 

 

 

設置源

 

設置國內 163 apt 源

 

# vim /etc/apt/sources.list
deb http://mirrors.163.com/ubuntu/ precise main universe restricted multiverse
deb http://mirrors.163.com/ubuntu/ precise-security universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ precise-updates universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ precise-proposed universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ precise-backports universe main multiverse restricted

deb-src http://mirrors.163.com/ubuntu/ precise main universe restricted multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-security universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ precise-proposed universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ precise-backports universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ precise-updates universe main multiverse restricted
# apt-get update

 


 

安裝依賴包

 

Gitlab 依賴包、庫

 

sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev \
                        libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall \
                        libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate

 

安裝 markdown 文檔風格依賴包

 

sudo apt-get install -y python-docutils 

 

安裝 git,Gerrit 依賴 gitweb,同時 GitLab 依賴 git 版本 >= 1.7.10,Ubuntu apt-get 默認安裝的是 1.7.9.5,當然不升級也是沒有問題的

 

sudo apt-get install -y git git-core gitweb git-review

 

升級 Git 版本(可選)

 

sudo apt-get install -y git gitweb
sudo apt-get remove git-core
sudo apt-get install -y libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-dev build-essential
cd /tmp
curl --progress https://git-core.googlecode.com/files/git-1.8.4.1.tar.gz | tar xz
cd git-1.8.4.1/
make prefix=/usr/local all
sudo make prefix=/usr/local install
# * 如果升級了 git 的版本,相應修改 Gitlab.yml 中的 git 腳本位置,這一步在 clone gitlab 后在操作*
sudo -u git -H vim /home/git/gitlab/config/gitlab.yml
bin_path: /usr/local/bin/git

 

Gitlab 需要收發郵件,安裝郵件服務器

 

sudo apt-get install -y postfix

 

如果安裝了 ruby1.8,卸載掉,Gitlab 依賴 2.0 以上

 

sudo apt-get remove ruby1.8

 

下載編譯 ruby2.0

 

mkdir /tmp/ruby && cd /tmp/ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz | tar xz
cd ruby-2.0.0-p353
./configure --disable-install-rdoc
make
sudo make install

 

修改 gem 源指向 taobao

 

gem source -r https://rubygems.org/
gem source -a http://ruby.taobao.org/

 

安裝 Bundel 命令

 

sudo gem install bundler --no-ri --no-rdoc

 


 

系統用戶

 

給 Gitlab 創建一個 git 用戶

 

sudo adduser --disabled-login --gecos 'GitLab' git

 


 

GitLab Shell

 

下載 Gitlab Shell,用來 ssh 訪問倉庫的管理軟件

 

cd /home/git
sudo -u git -H git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell
sudo -u git -H cp config.yml.example config.yml

 

修改 gitlab-shell/config.yml

 

sudo -u git -H vim /home/git/gitlab-shell/config.yml
gitlab_url: "http://gitlab.thstack.com/"

 

安裝 GitLab Shell

 

cd /home/git/gitlab-shell
sudo -u git -H ./bin/install

 


 

Mysql

 

安裝 Mysql 包

 

sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev

 

給 Gitlab 創建 Mysql 數據庫並授權用戶訪問

 

sudo mysql -uroot -p
> create database gitlabdb;
> grant all on gitlabdb.* to 'gitlabuser'@'localhost' identified by 'gitlabpass';

 


 

GitLab

 

下載 GitLab 源代碼,並切換到最新的分支上

 

cd /home/git
sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab
cd gitlab
sudo -u git -H git checkout 6-4-stable

 

配置 GitLab,修改 gitlab.yml,其中 host: 項和 gitlab-shell 中 gitlab_url 的主機一致

 

cd /home/git/gitlab
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
sudo -u git -H vim config/gitlab.yml
host: gitlab.thstack.com
email_from: gitlab@thstack.com
support_mail: gitlab@thstack.com
signup_enabled: true             #開啟用戶注冊

 

創建相關目錄

 

cd /home/git/gitlab
sudo -u git -H mkdir tmp/pids/
sudo -u git -H mkdir tmp/sockets/
sudo -u git -H mkdir public/uploads 
sudo -u git -H mkdir /home/git/repositories
sudo -u git -H mkdir /home/git/gitlab-satellites

 

修改相關目錄權限

 

sudo chown -R git:git log/ tmp/
sudo chmod -R u+rwX  log/ tmp/ public/uploads

 

修改 unicorn.rb 監聽端口為:8081

 

cd /home/git/gitlab/
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
sudo -u git -H vim config/unicorn.rb
listen "gitlab.thstack.com:8081", :tcp_nopush => true

 

配置 GitLab 訪問 mysql 數據庫設置

 

cd /home/git/gitlab/
sudo -u git cp config/database.yml.mysql config/database.yml
sudo -u git -H vim config/database.yml  
*修改 Production 部分:*
production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: gitlabdb
  pool: 10
  username: gitlabuser
  password: "gitlabpass"
  host: localhost
  socket: /var/run/mysqld/mysqld.sock

 

設置 GitLab 使用指定郵箱發送郵件,注意 production.rb 的文件格式,開頭空兩格

 

cd /home/git/gitlab/
sudo -u git -H vim config/environments/production.rb
  #修改 :sendmail 為 :smtp
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address              => "smtp.googlemail.com",
    :port                 => 587,
    :domain               => 'thstack.com',
    :user_name            => 'gitlab@thstack.com',
    :password             => 'password',
    :authentication       =>  :plain,
    :enable_starttls_auto => true
  }
end          # 上面內容加入到 end 里面

 

安裝 gem

 

修改 Gemfile 文件中源指向為 taobao

 

cd /home/git/gitlab/
sudo -u git -H vim Gemfile
source "http://ruby.taobao.org/"

 

雖然在文件中指向了國內 taobao 源,但是依然會卡一會,耐心等待…

 

cd /home/git/gitlab/
sudo -u git -H bundle install --deployment --without development test postgres aws

 

初始化數據庫並激活高級功能

 

cd /home/git/gitlab/
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

 

輸入 yes 來初始化數據庫、創建相關表,最后會輸出 GitLab Web 管理員用來登錄的賬號和密碼

 

Do you want to continue (yes/no)? yes
...
Administrator account created:
login.........admin@local.host
password......5iveL!fe

 

設置 GitLab 啟動服務

 

cd /home/git/gitlab/
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
sudo update-rc.d gitlab defaults 21

 

設置 GitLab 使用 Logrotate 備份 Log

 

cd /home/git/gitlab/
sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

 

檢查GitLab及其環境的配置是否正確:

 

cd /home/git/gitlab/
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
System information
System:         Ubuntu 12.04
Current User:   git
Using RVM:      no
Ruby Version:   2.0.0p353
Gem Version:    2.0.14
Bundler Version:1.3.5
Rake Version:   10.1.0

GitLab information
Version:        6.4.2
Revision:       214a013
Directory:      /home/git/gitlab
DB Adapter:     mysql2
URL:            http://gitlab.thstack.com
HTTP Clone URL: http://gitlab.thstack.com/some-project.git
SSH Clone URL:  git@gitlab.thstack.com:some-project.git
Using LDAP:     no
Using Omniauth: no

GitLab Shell
Version:        1.8.0
Repositories:   /home/git/repositories/
Hooks:          /home/git/gitlab-shell/hooks/
Git:            /usr/bin/git

 

啟動 GitLab 服務

 

/etc/init.d/gitlab restart
Shutting down both Unicorn and Sidekiq.
GitLab is not running.
Starting both the GitLab Unicorn and Sidekiq..
The GitLab Unicorn web server with pid 17771 is running.
The GitLab Sidekiq job dispatcher with pid 17778 is running.
GitLab and all its components are up and running

 

最后編譯一下

 

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

 


 

Nginx

 

安裝 Nginx 包

 

sudo apt-get install -y nginx

 

配置 Nginx

 

cd /home/git/gitlab
sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
sudo vim /etc/nginx/sites-available/gitlab
listen *:80 default_server;
server_name gitlab.thstack.com;
proxy_pass http://gitlab.thstack.com:8081;

 

啟動 Nginx

 

/etc/init.d/apache2 stop
/etc/init.d/nginx restart

 

訪問

 

用瀏覽器訪問: http://gitlab.thstack.com
用戶名:admin@local.host
密碼:5iveL!fe

 

2: https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/insta llation.md

 

界面簡單使用

 

使用 admin@local.host 賬號登錄: gitlab-login

 

登錄后系統讓修改密碼,先修改密碼: gitlab-set_pass

 

修改完密碼后,用新密碼登錄一下,然后修改 Admin 用戶得郵箱地址為:admin@thstack.com gitlab-set-email

 

點擊保存更改后,系統會自動給剛才輸入的郵箱地址發送一封確認修改信息,點擊郵件內容中的連接后會自動用新賬號郵箱登錄。

 

創建一個 GROUP:

 

gitlab-click-group

 

輸入 Group 名字為:DevGroup gitlab-create-gourp

 

點擊創建項目: gitlab-click-project

 

創建一個項目,名為:OpenStack,這個項目屬於 DevGroup: gitlab-create-project

 

創建完項目后,點擊添加 ssh 密鑰: gitlab-click-sshkey

 

生成 admin@thstack.com 郵箱密鑰: gitlab-gen-sshkey

 

在界面輸入剛才生成得密鑰: gitlab-add-sshkey

 

再注冊一個賬號,登錄頁面點擊注冊按鈕: gitlab-click-user

 

注冊一個 Longgeek 用戶,輸入郵箱、密碼,然后去輸入得郵箱驗證: gitlab-create-user

 

創建一個 Longgeek 用戶,並生成密鑰: gitlab-longgeek-gen-sshkey

 

用 longgeek@thstack.com 用戶登錄 GitLab,添加剛才生成得密鑰到 sshkey 里: gitlab-longgeek-add-sshkey

 

用 admin@thstack.com 用戶登錄 GitLab,把 longgeek@thstack.com 添加到 DevGroup 組中,權限是 Reporter,這樣 longgeek 用戶也可以訪問 OpenStack 這個項目,不過沒有權限直接 Push: gitlab-add-longgeek-gourp

 

用 longgeek@thstack.com 用戶登錄就可以看到 OpenStack 項目: gitlab-longgeek-view-project

 

用 longgeek@thstack.com clone 項目,嘗試 push: gitlab-longgeek-try-push

 

很顯然 longgeek 用戶是沒有 push 到 master 分支得權限。接下來會安裝 Gerrit、Jenkins。以及它們三個如何整合成流程。請參考后面得文章

 


免責聲明!

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



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