GitLab 是開源的 Git 倉庫管理平台。CentOS 6.2 64 位元部署 GitLab 需關閉 SELinux/iptables、安裝 EPEL 與開發套件、編譯安裝 Ruby 1.9.3+、建立 git 用戶、部署 GitLab Shell、配置 PostgreSQL/Redis、安裝 GitLab 本體、整合 Nginx 與 Unicorn。本文記錄核心步驟與關鍵配置。
# 關閉 SELinux 與防火牆(生產環境請改用精細規則)
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
service iptables stop
chkconfig iptables off
# 系統:CentOS 6.2 x86_64
rpm -Uvh https://download.fedoraproject.org/pub/epel/6/x86_64/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
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
ruby -v
# ruby 1.9.3p392 (2013-02-22) [x86_64-linux]
adduser --comment 'GitLab' git
chmod -R 755 /home/git
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
vi config.yml
# 修改 gitlab_url: "https://your.domain.com/"
./bin/install
# PostgreSQL(推薦)
yum install -y postgresql-server postgresql-devel
service postgresql initdb
service postgresql start
chkconfig postgresql on
# 建立 gitlab 資料庫與用戶
su - postgres
psql -c "CREATE USER gitlab WITH PASSWORD 'secure_password';"
psql -c "CREATE DATABASE gitlabhq_production OWNER gitlab;"
# Redis
service redis start
chkconfig redis on
su - git
cd /home/git
git clone https://github.com/gitlabhq/gitlabhq.git gitlab
cd gitlab
git checkout 6-0-stable # 對應版本
cp config/gitlab.yml.example config/gitlab.yml
vi config/gitlab.yml
# 修改 host、email、gitlab_shell 路徑等
cp config/database.yml.postgresql config/database.yml
vi config/database.yml
# 修改 production 區塊 username/password
gem install charlock_holmes --version '0.6.9.4'
bundle install --deployment --without development test postgres aws
bundle exec rake gitlab:setup RAILS_ENV=production
# 輸入 yes 確認建立資料表
# 複製 Nginx 設定範本
cp lib/support/nginx/gitlab /etc/nginx/conf.d/gitlab.conf
vi /etc/nginx/conf.d/gitlab.conf
# 修改 server_name、root、upstream unix socket 路徑
# Unicorn 設定
cp config/unicorn.rb.example config/unicorn.rb
vi config/unicorn.rb
# 調整 worker_processes、timeout、listen socket
service nginx start
chkconfig nginx on
cp lib/support/init.d/gitlab /etc/init.d/gitlab
chmod +x /etc/init.d/gitlab
chkconfig --add gitlab
chkconfig gitlab on
service gitlab start

https://your.domain.com/,預設帳號 admin@local.host / 5iveL!fe。service gitlab start 應包含 sidekiq,或手動 bundle exec sidekiq -e production。config/initializers/smtp_settings.rb 或使用 Postfix。CentOS 7+/RHEL 7+ 強烈建議使用 Omnibus GitLab(官方預編譯包):
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
yum install -y gitlab-ce
gitlab-ctl reconfigure
# 幾分鐘內完成所有元件安裝配置,含 PostgreSQL、Redis、Nginx、Prometheus、Grafana 等