萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 作業系統 >  >> Linux 教學

CentOS 6.2 安裝 GitLab 完整部署指南(含依賴、Ruby、資料庫、Shell)

GitLab 官方支援 Ubuntu/Debian,但在 CentOS 也可透過手動編譯部署。本文記錄在 CentOS 6.2 64 位元環境下,從關閉防火牆/SELinux、安裝 EPEL 與開發套件、編譯 Ruby 1.9.3、建立 git 使用者、部署 gitlab-shell、建立 MySQL 資料庫、克隆 GitLab 原始碼至設定 Puma/Unicorn 的完整流程。

前置準備

# 關閉防火牆與 SELinux
service iptables stop; chkconfig iptables off
setenforce 0; sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

1. 安裝 EPEL 與基礎開發套件

rpm -Uvh https://download.fedoraproject.org/pub/epel/6/i386/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.9)

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

3. 建立 git 使用者

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

4. 部署 gitlab-shell

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  # 修改 gitlab_url 為實際域名
./bin/install

5. 建立 MySQL 資料庫與授權

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';
\q

6. 克隆 GitLab 原始碼並設定

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  # 修改 host、email 等
sudo chown -R git log/ tmp/
sudo chmod -R u+rwX log/ tmp/
sudo -u git -H mkdir /home/git/gitlab-satellites
sudo -u git -H mkdir -p tmp/pids/ tmp/sockets/ public/uploads
sudo chmod -R u+rwX tmp/pids/ tmp/sockets/ public/uploads
sudo -u git -H cp config/puma.rb.example config/puma.rb
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "gitlab@localhost"

後續步驟

仍需設定 database.yml、執行 bundle install --deployment --without development test postgres aws、資料庫遷移 bundle exec rake gitlab:setup RAILS_ENV=production、設定 Init script/系统服務與 Nginx 反向代理,方能正式上線。

copyright © 萬盛學電腦網 all rights reserved