GitLab 部署

jopen 10年前發布 | 83K 次閱讀 GitLab Git 版本控制系統

GitLab是一個利用 Ruby on Rails 開發的開源應用程序,實現一個自托管的Git項目倉庫,可通過Web界面進行訪問公開的或者私人項目。 它擁有與Github類似的功能,能夠瀏覽源代碼,管理缺陷和注釋。可以管理團隊對倉庫的訪問,它非常易于瀏覽提交過的版本并提供一個文件歷史庫。團隊成員可以利用內置的簡單聊天程序(Wall)進行交流。它還提供一個代碼片段收集功能可以輕松實現代碼復用,便于日后有需要的時候進行查找。

GitLab安裝指引包括以下內容:

  1. 包及依賴

  2. Ruby

  3. 系統用戶

  4. GitLab shell

  5. 數據庫

  6. GitLab

  7. Nginx

 

1  包及依賴

 1.1    確認系統更新到最新

root@debian:~# apt-get -y update
root@debian:~# apt-get -y upgrade
root@debian:~# apt-get install sudo  #后面githab啟動腳本需要用到

 1.2   安裝相關依賴包

root@debian:~# 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

  檢查Python版本,2.5+ (3.0+還沒支持)

root@debian:~# python --version
Python 2.7.3


 1.3 確保git版本 1.7.10 + ,如 1.7.12 or 1.8.4

  刪除原有git   

root@debian:~# apt-get remove git-core

  安裝依賴

root@debian:~# apt-get install -y libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-dev build-essential

  下載編譯源碼 1.8.5.2

root@debian:~# cd /tmp
root@debian:tmp# curl --progress https://git-core.googlecode.com/files/git-1.8.5.2.tar.gz | tar xz
root@debian:tmp# cd git-1.8.5.2/
root@debian:git-1.8.5.2# make prefix=/usr/local all
root@debian:git-1.8.5.2# make prefix=/usr/local install  #安裝到 /usr/local/bin

       注意:當編輯config/gitlab.yml 時(在步驟6), 修改 git bin_path 為 /usr/local/bin/git


提示: 為了收取通知郵件,您需要安裝郵件服務。默認的,Debian已隨帶exim4服務,但Ubuntu沒有。推薦的郵件服務是Postfix,

apt-get install -y postfix,然后,選擇'Internet Site',按回車確認主機名。

2. RUBY 

   2.1  如果系統已存在Ruby1.8,刪除它:

root@debian:git-1.8.5.2# apt-get remove ruby1.8

   2.2 下載編譯ruby

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

  2.3 安裝bundler ,一個安裝ruby的包系統 ,用bundler管理gem

root@debian:ruby-2.0.0-p353# gem install bundler --no-ri --no-rdoc
Fetching: bundler-1.6.1.gem (100%)
Successfully installed bundler-1.6.1
1 gem installed

  有可能執行卡主,天朝經常哈,   可以參見http://ruby.taobao.org/

3  系統用戶

root@debian:~# adduser --disabled-login --gecos 'GitLab' git

4  GitLab shell

root@debian:~# su - git
root@debian:~# cd /home/git
git@debian:~$ git clone https://github.com/gitlabhq/gitlab-shell.git
git@debian:~$ cd gitlab-shell/
git@debian:~/gitlab-shell$ cp config.yml.example config.yml
git@debian:~/gitlab-shell$ vim config.yml  # 更改 gitlab_url: "http://gitlab.test.com/"
git@debian:~/gitlab-shell$ ./bin/install

 5  安裝數據庫

   設置/etc/mysql/my.cnf 監聽本地ip 端口

root@debian:~# apt-get install -y mysql-server mysql-client libmysqlclient-dev

設置數據庫
root@debian:~# mysql -uroot -p
mysql> GRANT USAGE ON *.* TO 'gitlab'@'localhost' IDENTIFIED BY 'git';  #創建用戶密碼
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';

6  GitLab

  6.1切回git用戶

root@debian:~# su - git

  6.2克隆gitlab源碼

git@debian:~$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab
git@debian:~$ cd gitlab
git@debian:~/gitlab$ git checkout 6-7-stable
Branch 6-7-stable set up to track remote branch 6-7-stable from origin.
Switched to a new branch '6-7-stable'

  6.3 配置git

git@debian:~$ cd /home/git/gitlab
git@debian:~/gitlab$ cp config/gitlab.yml.example config/gitlab.yml
git@debian:~/gitlab$ vim config/gitlab.yml   #if git source,change the git bin_path to /usr/local/bin/git
                     #host 10.1.1.176
                     #timeout 600
                     #bin_path: /usr/local/bin/git  
git@debian:~/gitlab$ chown -R git log/
git@debian:~/gitlab$ chown -R git tmp/
git@debian:~/gitlab$ chmod -R u+rxX log/
git@debian:~/gitlab$ chmod -R u+rxX tmp/
git@debian:~/gitlab$ mkdir /home/git/gitlab-satellites
git@debian:~/gitlab$ mkdir tmp/pids/
git@debian:~/gitlab$ mkdir tmp/sockets/
git@debian:~/gitlab$ chmod -R u+rwX tmp/pids/
git@debian:~/gitlab$ chmod -R u+rwX tmp/sockets/
git@debian:~/gitlab$ mkdir public/uploads
git@debian:~/gitlab$ chmod -R u+rwX public/uploads/
git@debian:~/gitlab$ cp config/unicorn.rb.example config/unicorn.rb
git@debian:~/gitlab$ vim config/unicorn.rb
                     listen "10.1.1.176:8080", :tcp_nopush => true
#Configure Git global settings for git user, useful when editing via web
git@debian:~/gitlab$ git config --global user.name "GitLab"
git@debian:~/gitlab$ git config --global user.email "gitlab@localhost"
git@debian:~/gitlab$ git config --global core.autocrlf input
git@debian:~/gitlab$ cp config/database.yml.mysql config/database.yml
git@debian:~/gitlab$ vim config/database.yml  #數據庫密碼  只需修改production即可
                     #  username: gitlab
                     #  password: "git"       
                     #  host: localhost                     
git@debian:~/gitlab$ cp config/resque.yml.example config/resque.yml
git@debian:~/gitlab$ vim config/resque.yml
                     #  production: redis://10.1.1.176:6379

#更改redis 監聽地址               
root@debian:~# vim /etc/redis/redis.conf 
               #bind 10.1.1.176
root@debian:~# /etc/init.d/redis-server restart

  確保 gitlab.yml 和 unicorn.rb 配置正確   

 6.3 安裝gems

git@debian:~/gitlab$ cd /home/git/gitlab
#更換Gemfile中的ruby源,加快包的安裝速度    
git@debian:~/gitlab$ vi Gemfile    
                     #source "http://ruby.taobao.org" 
                                          
#初始化數據庫激活高級特性
git@debian:~/gitlab$ bundle exec rake gitlab:setup RAILS_ENV=production
== Seed from /home/git/gitlab/db/fixtures/production/001_admin.rb
2014-04-07T17:30:53Z 9883 TID-oxc268p00 INFO: Sidekiq client with redis options {:url=>"redis://10.1.1.176:6379", :namespace=>"resque:gitlab"}

Administrator account created:

login.........admin@local.host
password......5iveL!fe            

#出現以上表示Ok
#也有可能出現以下錯誤,繼續執行.
rake aborted!
Mysql2::Error: Lost connection to MySQL server during query: INSERT INTO `schema_migrations` (version) VALUES ('20121220064453')

 6.4 安裝啟動腳本

git@debian:~/gitlab$ cd /home/git/gitlab    
git@debian:~/gitlab$ cp lib/support/init.d/gitlab /etc/init.d/    
git@debian:~/gitlab$ chmod +x /etc/init.d/gitlab

設置gitlab開機啟動
root@debian:~# update-rc.d gitlab defaults 21

 6.5 設置logarate

root@debian:~# cd /home/git/gitlab
root@debian:gitlab# cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

 6.6檢查應用環境

root@debian:gitlab# su - git
git@debian:~$ cd gitlab
git@debian:~/gitlab$ bundle exec rake gitlab:env:info RAILS_ENV=production

System information
System:     Debian 7.4
Current User:  git
Using RVM: no
Ruby Version:  2.0.0p353
Gem Version:   2.0.14
Bundler Version:1.6.1
Rake Version:  10.1.1

GitLab information
Version:    6.7.3
Revision:   f88d30f
Directory:  /home/git/gitlab
DB Adapter:    mysql2
URL:        http://10.1.1.39
HTTP Clone URL:   http://10.1.1.39/some-project.git
SSH Clone URL:    git@10.1.1.39:some-project.git
Using LDAP:    no
Using Omniauth:    no

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

啟動gitlab
/etc/init.d/gitlab restart
Starting both the GitLab Unicorn and Sidekiq.
The GitLab Unicorn web server with pid 10080 is running.
The GitLab Sidekiq job dispatcher with pid 10088 is running.
GitLab and all its components are up and running.

   6.7編譯資源

git@debian:~/gitlab$ bundle exec rake gitlab:check RAILS_ENV=production
Checking Environment ...

Git configured for git user? ... yes

Checking Environment ... Finished

Checking GitLab Shell ...

GitLab Shell version >= 1.9.1 ? ... OK (1.9.3)
Repo base directory exists? ... yes
Repo base directory is a symlink? ... no
Repo base owned by git:git? ... yes
Repo base access is drwxrws---? ... yes
update hook up-to-date? ... yes
update hooks in repos are links: ... can't check, you have no projects
Running /home/git/gitlab-shell/bin/check
Check GitLab API access: /usr/local/lib/ruby/2.0.0/net/http.rb:878:in `initialize': getaddrinfo: No address associated with hostname (SocketError)
    from /usr/local/lib/ruby/2.0.0/net/http.rb:878:in `open'
    from /usr/local/lib/ruby/2.0.0/net/http.rb:878:in `block in connect'
    from /usr/local/lib/ruby/2.0.0/timeout.rb:52:in `timeout'
    from /usr/local/lib/ruby/2.0.0/net/http.rb:877:in `connect'
    from /usr/local/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
    from /usr/local/lib/ruby/2.0.0/net/http.rb:851:in `start'
    from /home/git/gitlab-shell/lib/gitlab_net.rb:76:in `get'
    from /home/git/gitlab-shell/lib/gitlab_net.rb:43:in `check'
    from /home/git/gitlab-shell/bin/check:11:in `<main>'
gitlab-shell self-check failed
  Try fixing it:
  Make sure GitLab is running;
  Check the gitlab-shell configuration file:
  sudo -u git -H editor /home/git/gitlab-shell/config.yml
  Please fix the error above and rerun the checks.

如報以上錯誤,需要更改主機名/etc/hosts
root@debian:~# cat /etc/hosts
127.0.0.1   10.1.1.176
127.0.1.1       10.1.1.176


重新編譯資源
git@debian:~/gitlab$ bundle exec rake gitlab:check RAILS_ENV=production

Checking Environment ...

Git configured for git user? ... yes

Checking Environment ... Finished

Checking GitLab Shell ...

GitLab Shell version >= 1.9.1 ? ... OK (1.9.3)
Repo base directory exists? ... yes
Repo base directory is a symlink? ... no
Repo base owned by git:git? ... yes
Repo base access is drwxrws---? ... yes
update hook up-to-date? ... yes
update hooks in repos are links: ... can't check, you have no projects
Running /home/git/gitlab-shell/bin/check
Check GitLab API access: OK
Check directories and files: 
    /home/git/repositories: OK
    /home/git/.ssh/authorized_keys: OK
Test redis-cli executable: redis-cli 2.4.14
Send ping to redis server: PONG
gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Sidekiq ...

Running? ... yes
Number of Sidekiq processes ... 1

Checking Sidekiq ... Finished

Checking LDAP ...

LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab ...

Database config exists? ... yes
Database is SQLite ... no
All migrations up? ... yes
Database contains orphaned UsersGroups? ... no
GitLab config exists? ... yes
GitLab config outdated? ... no
Log directory writable? ... yes
Tmp directory writable? ... yes
Init script exists? ... yes
Init script up-to-date? ... yes
projects have namespace: ... can't check, you have no projects
Projects have satellites? ... can't check, you have no projects
Redis version >= 2.0.0? ... yes
Your git bin path is "/usr/local/bin/git"
Git version >= 1.7.10 ? ... yes (1.8.5)

Checking GitLab ... Finished

7  Nginx

root@debian:~#apt-get install -y nginx
root@debian:~#cd /home/git/gitlab
root@debian:gitlab# cp lib/support/nginx/gitlab /etc/nginx/sites-available/
root@debian:gitlab# ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab

   修改域名:

root@debian:gitlab# vim /etc/nginx/sites-enabled/gitlab
                        server_name gitlab.test.com

  重啟服務

root@debian:gitlab# /etc/init.d/nginx start
Starting nginx: nginx: [emerg] could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32
nginx: configuration file /etc/nginx/nginx.conf test failed

    保存服務器名字的hash表是由指令 server_names_hash_max_size 和 server_names_hash_bucket_size所控制的。參數hash bucket size總是等于hash表的大小,并且是一路處理器緩存大小的倍數。如果Nginx給出需要增大 hash max size 或 hash bucket size的提示,那么首要的是增大前一個參數的大小.

root@debian:gitlab# vim /etc/nginx/sites-enabled/gitlab 
root@debian:gitlab# server_names_hash_bucket_size 64;
root@debian:gitlab# /etc/init.d/nginx restart

8 測試

   綁定域名并輸入域名githab.test.com

     GitLab 部署


      GitLab 部署



參考:

https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md




 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!