安裝步驟總覽
基礎操作系統(CentOS 6.5 x86_64)
Ruby (版本: 2.0.0p353)
創建項目運行用戶(創建git賬號,方便權限管理)
GitLab Shell(版本:2.6.3)
數據庫(可以支持mysql和PostgreSQL,這裏使用mysql,版本:5.1.17)
GitLab(版本:7.10.1)
Web服務器(可支持nginx和apache,這裏使用tengine,版本:2.1.0)
防火牆(iptables)
1、安裝操作系統
這個比較簡單,安裝完成之後記的配置下網絡,使其可以在啓動時自動連接。而後需要升級系統和安裝一些相應的軟件和依賴包,以下逐一說明。
Tips:如果不能連接國外的網絡,經常出現網絡錯誤或者couldn’t not resolve host這樣的錯誤,建議修改dns服務器爲8.8.8.8和8.8.4.4。
a、增加EPEL安裝源
EPEL, 即Extra Packages for Enterprise Linux,這個軟件倉庫裏有很多非常常用的軟件,而且是專門針對RHEL設計的,對RHEL標準yum源是一個很好的補充,完全免費使用,由 Fedora項目維護,所以如果你使用的是RHEL,或者CentOS,Scientific等RHEL系的linux,可以非常放心的使用EPEL的 yum源。
下載並安裝GPG key
$ sudo wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 https://www.fedoraproject.org/static/0608B895.txt $ sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
檢驗下是否安裝成功
$ sudo rpm -qa gpg*
安裝epel-release-6-8.noarch包
$ sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
提示:不要在意x86_64,在i686的機器上一樣能使用。
b、安裝GitLab的所需依賴包和工具
# yum -y groupinstall "Development Tools"
c、配置redis
配置redis使其在開機時啓動:
# yum -y install redis # chkconfig redis on # service redis start
d、配置郵件服務器
筆者注:這個過程筆者沒有配置,請參考英文文檔。
2、安裝Ruby
下載並編譯:
# 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 --prefix=/usr/local/ # make && make install
安裝完成後,重新登錄終端確保$PATH生效,檢測ruby的安裝成功與否:
# which ruby /usr/local/bin/ruby # ruby -v ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
安裝bundle:
$ # gem install bundler --no-ri --no-rdoc
如果提示sudo: gem: command not found,使用root賬號登錄執行該命令即可。
3、系統用戶
創建用戶git
# adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git
因爲git用戶不需要登錄,所以這裏不需要設置git的密碼。
轉發所有郵件
筆者注:因爲上面沒有配置發送郵件,這裏也省略。
4、配置GitLab shell
GitLab shell是專門爲GitLab開發的提供ssh訪問和版本管理的軟件。
先使用root登錄,而後切換成git
$ su - git
克隆gitlab shell
$ git clone https://github.com/gitlabhq/gitlab-shell.git $ cd gitlab-shell
切換成2.6.3版本,並編輯配置
$ git checkout v2.6.3 $ cp config.yml.example config.yml
這裏最重要的是將gitlab_url修改成gitlab的訪問域名。形如:http://172.16.2.2/gitlab
筆 者注:如果gitlab是使用https訪問,則需將http替換成https,配置文件中的self_signed_cert要修改成true,否則 gitlab shell在通過api和gitlab進行通信的時候就會出現錯誤,導致項目push出錯。因爲後面配置web服務器的時候是使用ssl,所以這裏要按照 ssl的方式配置。
Tips: 另外如果使用的域名是測試域名,不要忘記在系統的/etc/hosts做域名映射。
安裝一些需要的目錄和文件
$ ./bin/install
5、安裝數據庫
筆者這裏使用的是msyql,關於PostgreSQL的安裝請參考原文檔。
安裝mysql並設置開機啓動:
$ su - root # yum install -y mysql-server mysql-devel # chkconfig mysqld on # service mysqld start
設置mysql root賬號的密碼:
# /usr/bin/mysql_secure_installation
創建新用戶和數據庫給gitlab使用
# 登錄數據庫 $ mysql -u root -p # 輸入root密碼 # 爲gitlab創建使用用戶 CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab'; # 創建gitlaba使用的數據庫 CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; # 給予gitlab用戶權限 GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost'; # 登出數據庫 \q
6、安裝GitLab
將GitLab安裝在git的家目錄下:
$ su - git
a、克隆GitLab並切換分支到7-10-stable
# 克隆GitLab $ git clone https://github.com/gitlabhq/gitlabhq.git gitlab # 進入gitlab目錄 $ cd /home/git/gitlab # 切換到7-10-stable分支 $ git checkout 7-10-stable
b、配置項目
# 複製配置文件 $ cp config/gitlab.yml.example config/gitlab.yml # 修改配置文件中的訪問域名 (your_domain_name爲項目的訪問域名) $ sed -i 's/localhost/your_domain_name/g' config/gitlab.yml # 設定log和tmp目錄所有者和權限 $ chown -R git log/ $ chown -R git tmp/ $ chmod -R u+rwx log/ $ chmod -R u+rwx tmp/ # 創建gitlab-satellites目錄 $ mkdir /home/git/gitlab-satellites # 創建tmp/pids/和tmp/sockets/目錄,確保gitlab有相應的權限 $ mkdir tmp/pids/ $ mkdir tmp/sockets/ $ chmod -R u+rwx tmp/pids/ $ chmod -R u+rwx tmp/sockets/ # 創建public/uploads目錄 $ mkdir public/uploads $ chmod -R u+rwx public/uploads # 複製unicorn配置 $ cp config/unicorn.rb.example config/unicorn.rb # 編輯unicorn配置(修改listen和超時時間) $ vim config/unicorn.rb listen "172.16.2.2:8080" timeout 300 # 配置git的用戶和郵件 $ git config --global user.name "GitLab" $ git config --global user.email "[email protected]" $ git config --global core.autocrlf input
這邊的配置比較複雜,細心些就行了。
c、配置數據庫訪問文件
$ cp config/database.yml.mysql config/database.yml
編輯config/database.yml,設置其中連接數據庫的賬號密碼,筆者的配置部分如下:
# # PRODUCTION # production: adapter: mysql2 encoding: utf8 reconnect: false database: gitlabhq_production pool: 10 username: gitlab password: "gitlab" # host: localhost # socket: /tmp/mysql.sock
修改其中username和password就可以了,其中密碼就是上面數據庫步驟中創建gitlab用戶的密碼。
確保該文件只有git賬號有權限讀取。
$ chmod o-rwx config/database.yml
d、安裝Gems
$ su - $ gem install charlock_holmes --version '0.6.9.4' $ exit
安裝mysql包
$ cd /home/git/gitlab/ $ bundle install --deployment --without development test postgres puma aws
e、初始化數據和激活高級功能
$ cd /home/git/gitlab $ bundle exec rake gitlab:setup RAILS_ENV=production
這步完成後,會生一個默認的管理員賬號:
[email protected] 5iveL!fe
f、安裝啓動腳本
$ su - $ wget -O /etc/init.d/gitlab https://raw.githubusercontent.com/gitlabhq/gitlab-recipes/master/init/sysvinit/centos/gitlab-unicorn $ chmod +x /etc/init.d/gitlab $ chkconfig --add gitlab
開機時啓動
$ chkconfig gitlab on
g、檢測應用程序狀態
$ su - git $ cd gitlab/ $ bundle exec rake gitlab:env:info RAILS_ENV=production $ exit
可以查看到系統、Ruby、GitLab和GitLab Shell的版本和其他信息。
啓動GitLab實例
$ service gitlab start
h、查看應用更加詳細的信息
$ su - git $ cd gitlab/ $ bundle exec rake gitlab:check RAILS_ENV=production
這裏會提示一個Init script up-to-date的錯誤,如下:
Init script up-to-date? ... no Try fixing it: Redownload the init script For more information see: doc/install/installation.md in section "Install Init Script" Please fix the error above and rerun the checks.
原文說明不用介意這個問題。
7、安裝web服務器
筆者選擇的是tengine,自己打好的rpm包,關於apache方面的請參考原文檔
# rpm -ivh tengine-2.1.0-0.el6.x86_64.rpm # vi /opt/config/tengine/vhost/gitlab.conf server { listen 80; server_name 172.16.2.2; include proxy_opt.conf; access_log /opt/logs/tengine/gitlab_access.log; error_log /opt/logs/tengine/gitlab_error.log; location / { proxy_pass http://172.16.2.2:8080; } }
啓動nginx
# service rc.tengine start
8、配置防火牆
配置iptables,使用戶可以訪問http、https和ssh的端口。
$ lokkit -s http -s https -s ssh
重新啓動防火牆
$ service iptables restart
至此就算安裝完成了。默認的賬號密碼:
[email protected] 5iveL!fe
問題記錄
a、網站不能添加用戶和創建項目問題?
查了下日誌,發現是權限的問題:
Errno::EACCES (Permission denied – /home/git/gitlab/log/application.log):
修改用戶和所屬用戶組爲git就可以了。
b、無法push?
在 上面安裝GitLab shell步驟時,一開始筆者是將配置中的gitlab_url設置成http://test.gitlab.com/,結果在push的時候出錯了,後 來查看GitLab項目日誌,才發現GitLab shell和GitLab通信的時候產生了一個301跳轉。這點通過GitLab的nginx配置也能看的出來。後來將http替換成 https,self_signed_cert設置成true就OK了。
總結
安 裝的過程比較長,其中大部分時間花在了包的下載上。筆者以前沒有接觸過ruby,安裝的過程中也瞭解了下Ruby、Gem、Bundle等軟件,受益匪 淺。一般來講,照着上面的步驟安裝,如果系統,軟件等版本都一致的話,應該能成功安裝。如果出現問題,可以多查查日誌。GitLab項目的日誌在該項目的 log目錄內。GitLab shell的日誌在GitLab shell項目中的gitlab-shell.log