GitLab 是開源的倉庫管理系統,官方文件以 Ubuntu/Debian 為主,但同樣能在 CentOS 上跑起來,只是需要多手動處理一些相依性。以下以 CentOS 6.2 64 位為例。
開始之前,務必先關閉 iptables 與 SELinux,否則安裝與啟動階段常會遇到莫名的權限或連線問題。
cd /tmp
wget https://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh epel-release-6-8.noarch.rpm
接著一次裝齊編譯工具與函式庫:
yum install -y readline-devel libyaml-devel gdbm-devel ncurses-devel redis openssl-devel zlib-devel gcc gcc-c++ make autoconf curl-devel expat-devel gettext-devel tk-devel libxml2-devel libffi-devel libxslt-devel libicu-devel httpd httpd-devel gitolite git-all python-devel python-pip sqlite-devel sendmail vim mysql-devel mysql-server patch libyaml* pcre-devel
CentOS 6 自帶的是 1.8,版本不足,需自行編譯:
mkdir /tmp/ruby && cd /tmp/ruby
curl --progress https://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz | tar xz
cd ruby-1.9.3-p392/
./configure
make
make install
gem install bundler
ln -s /usr/local/bin/ruby /usr/bin/ruby
ln -s /usr/local/bin/gem /usr/bin/gem
ln -s /usr/local/bin/bundle /usr/bin/bundle
adduser --comment 'GitLab' git
chmod -R 755 /home/git
切換到 git 身分,克隆並切到指定版本,修改 config.yml 中的 gitlab_url 為你的網域,再執行安裝:
su - git
cd /home/git
git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell
git checkout v1.3.0
cp config.yml.example config.yml
vim config.yml
./bin/install
mysql -u root -p 之後依序執行:
CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab';
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
切到 stable 分支,複製範例設定,把 gitlab.yml 中的 localhost 改為正式網域,再建立 log、tmp、uploads、satellites 等目錄並把擁有者交給 git:
cd /home/git
sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab
cd gitlab
sudo -u git -H git checkout 5-1-stable
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
sudo -u git -H vim config/gitlab.yml
sudo chown -R git log/ tmp/
sudo chmod -R u+rwX log/ tmp/
sudo -u git -H mkdir -p tmp/pids tmp/sockets public/uploads
sudo -u git -H cp config/puma.rb.example config/puma.rb
最後設定 git 全域身分,讓 Web 介面操作時的提交有作者資訊:
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "gitlab@localhost"
整體流程整理起來就是:關閉安全機制 → 裝相依 → 編譯 Ruby → 建 git 帳號 → 裝 shell → 建庫授權 → 部署主程式。過程中若某個 gem 裝不上,多半是漏了對應的 devel 套件,回頭補裝即可。