Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

CentOS 安裝 GitLab 完整部署指南(含 Ruby 編譯、PostgreSQL/Redis、GitLab Shell、Nginx 整合)

編輯:關於 Linux

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

1. 安裝 EPEL 與基礎依賴

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

2. 編譯安裝 Ruby 1.9.3-p392(系統預設 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
ruby -v
# ruby 1.9.3p392 (2013-02-22) [x86_64-linux]

3. 建立 git 用戶

adduser --comment 'GitLab' git
chmod -R 755 /home/git

4. 部署 GitLab Shell(以 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

5. 安裝資料庫與 Redis

# 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

6. 安裝 GitLab 本體(以 git 用戶)

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 確認建立資料表

7. 整合 Nginx + Unicorn

# 複製 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

8. 設定開機自啟

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

GitLab 安裝過程截圖

驗證與常見問題

  • 瀏覽器訪問 https://your.domain.com/,預設帳號 admin@local.host / 5iveL!fe。
  • 502 Bad Gateway:檢查 Unicorn socket 路徑、Nginx upstream 設定、Unicorn 是否運行。
  • Sidekiq 未啟動: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 等
Copyright © Windows教程網 All Rights Reserved