張旭

I am looking for a job, give me a chance to work with you.

安裝 Gitlab

Permalink

Gitlab 是一套 Open Source 的 Git 專案管理系統。 可以把它想象成是 Open Source 的 Github 網站。

Gitlab 是使用 Rails 搭配 Gitlab Shell 來實現 Git 專案管理, 其中 Rails 框架負責網頁與專案管理(account、project、issue、wiki 等)相關的東西, 在背後透過 grit: 一個 Ruby 語言實作的操作 Git 的函式庫, 搭配 Gitlab Shell: 一個類似 Gitolite 的 Git Repositories 存取控制系統, 來控制實際在檔案系統(File System)中的 Git Repositories。 題外話,Gitlab 在 5.0 以前,底層的存取控制系統使用的還是 Gitolite。

把 Gitlab 架設起來之後,等於是有了一臺自己的 Git Projects Hosting Server。 其它類似 Gitlab 的 Open Source 軟體還有: 同樣用 Rails 框架開發的 Gitorious; 使用 PHP 的 Pluf 框架開發的 Indefero

本文記錄 RHEL 6.3 x86_64 環境中安裝 Gitlab 的過程。 如果是 Ubuntu 的環境要安裝 Gitlab 會更簡單,請直接參考官方的安裝手冊

安裝相依性套件

  1. cd /opt
  2. wget http://mirror01.idc.hinet.net/EPEL/6/i386/epel-release-6-8.noarch.rpm
  3. rpm -iUvh epel-release-6-8.noarch.rpm
  4. yum clean all
  5. yum list
  6. yum remove gitosis
  7. yum groupinstall “Development Tools”
  8. yum update && yum upgrade
  9. yum install vim python wget curl git openssh-server
  10. yum install sqlite sqlite-devel mysql mysql-libs mysql-devel
  11. yum install ncurses-devel libcurl-devel libcurl curl patch sudo
  12. yum install libxslt-devel libyaml-devel libxml2 libxml2-devel gdbm-devel libffi libffi-devel zlib zlib-devel openssl-devel readline readline-devel curl-devel openssl-devel pcre-devel memcached-devel valgrind-devel ImageMagick-devel ImageMagick libicu libicu-devel make bzip2 autoconf automake libtool bison redis
  13. chkconfig redis on
  14. service redis start
  15. yum install postfix
  16. chkconfig postfix on
  17. service postfix start

如果EPEL 套件庫少東西,請到 http://pkgs.org/ 把套件手動補齊。 比較常有問題的是以下這幾個套件:

  • gdbm-devel
  • libffi-devel
  • libicu-devel
  • iconv-devel
  • valgrind-devel
  • ImageMagick-devel

設定 Gitlab 系統帳號

  1. useradd git
  2. passwd git
  3. chmod 755 /home/git
  4. su - git
  5. mkdir -p /home/git/.ssh
  6. chmod -R 700 /home/git/.ssh
  7. touch /home/git/.ssh/authorized_keys
  8. chmod -R 600 /home/git/.ssh/authorized_keys
  9. ssh-keygen -t rsa
  10. cat /home/git/.ssh/id_rsa.pub >> /home/git/.ssh/authorized_keys

安裝 Ruby 環境

  1. su - git
  2. mkdir -p /home/git/temp
  3. mkdir -p /home/git/ruby
  4. cd /home/git/temp
  5. wget -c “http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz
  6. tar zxvf ruby-1.9.3-p392.tar.gz && cd ruby-1.9.3-p392
  7. ./configure --prefix=/home/git/ruby
  8. make
  9. make install
  10. vim ~/.bash_profile PATH=$HOME/ruby/bin:$PATH:$HOME/bin;
  11. vim ~/.bashrc PATH=$HOME/ruby/bin:$PATH:$HOME/bin;
  12. source ~/.bash_profile
  13. which ruby
  14. ruby --version
  15. gem install bundler
  16. gem install charlock_holmes --version '0.6.9'
  17. cd ~
  18. rm -rf ~/temp

設定資料庫

  1. yum install mysql-server mysql myslq-devel
  2. chkconfig mysqld on
  3. service mysqld start
  4. mysql -u root -p
  5. mysql> CREATE DATABASE IF NOT EXISTS gitlab DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
  6. mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '12345678';
  7. mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON gitlab.* TO 'gitlab'@'localhost';

安裝 Gitlab Shell

  1. su - git
  2. cd /home/git
  3. git clone http://github.com/gitlabhq/gitlab-shell.git
  4. cd gitlab-shell
  5. cp config.yml.example config.yml
  6. vim config.yml
# GitLab user. git by default
user: git
# Url to gitlab instance. Used for api calls. Should be ends with slash.
gitlab_url: "http://your.git.server/"
http_settings:
# user: someone
# password: somepass
self_signed_cert: false
# Repositories path
repos_path: "/home/git/repositories"
# File used as authorized_keys for gitlab user
auth_file: "/home/git/.ssh/authorized_keys"
  1. /home/git/gitlab-shell/bin/install

安裝 Gitlab

  1. su - git
  2. cd /home/git
  3. git config --global user.name “GitLab”
  4. git config --global user.email “gitlab@gitlab.YOUR.HOST
  5. mkdir gitlab-satellites
  6. git clone http://github.com/gitlabhq/gitlabhq.git gitlab
  7. cd gitlab
  8. git checkout 5-0-stable
  9. more VERSION
  10. cp config/gitlab.yml.example config/gitlab.yml
  11. vim config/gitlab.yml
## GitLab settings
gitlab:
## Web server settings
host: your.git.server
port: 80
https: false
user: git
## Gravatar
gravatar:
enabled: false
  1. mkdir tmp/pids/
  2. chown -R git log/ tmp/
  3. chmod -R u+rwX log/ tmp/
  4. cp config/unicorn.rb.example config/unicorn.rb
  5. vim config/unicorn.rb listen "127.0.0.1:8080"
  6. cp config/database.yml.mysql config/database.yml
  7. vim config/database.yml
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: gitlab
pool: 5
username: gitlab
password: "12345678"
host: localhost
  1. cd /home/git/gitlab
  2. 編輯 Gemfile 並將所有 git:// 與 https:// 改成 http://
  3. bundle install --no-deployment
  4. bundle install --deployment --without development test postgres
  5. bundle exec rake gitlab:setup RAILS_ENV=production
  6. bundle exec rake db:seed_fu RAILS_ENV=production
  7. bundle exec rake gitlab:env:info RAILS_ENV=production
  8. bundle exec rake gitlab:check RAILS_ENV=production
  • 碰到 invalid gem format for /path/to/cache/xxx.gem 問題, 刪掉該 cache 的 gem,再重跑 bundle install 即可

設定 Gitlab 啓動腳本

  1. su - root
  2. curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab
  3. chkconfig --add gitlab
  4. chkconfig gitlab on
  5. chmod +x /etc/init.d/gitlab
  6. /etc/init.d/gitlab start
  7. /etc/init.d/gitlab status
  8. Unicorn 與 Sidekiq 服務跑起來需要點時間,要等一下

設定 Apache

  1. su - root
  2. yum install httpd
  3. vim /etc/httpd/conf/httpd.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerName gitlab.YOUR.HOST
DocumentRoot /home/git/gitlab/public
CustomLog logs/gitlab-access.log combined
ErrorLog logs/gitlab-error.log
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
ProxyPreserveHost On
</VirtualHost>
  1. chmod 755 /home/git
  2. chkconfig httpd on
  3. service httpd restart

Gitlab 預設帳號:admin@local.host
Gitlab 預設密碼:5iveL!fe