CentOS 7 安裝 Gitlab

安裝基本系統與依賴包

安裝 Gitlab 依賴的工具

bashyum -y update
yum -y groupinstall 'Development Tools'
yum -y install readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui git redis ruby sudo wget crontabs logwatch logrotate perl-Time-HiRes

安裝 Redis

訪問 http://www.redis.io/download,下載 Redis 源代碼。node

bashwget http://download.redis.io/releases/redis-3.0.0.tar.gz
tar zxvf redis-3.0.0.tar.gz
cd redis-3.0.0
make

若在編譯過程當中出錯,則能夠執行下面的命令:mysql

bashsudo make test

安裝:

bashsudo make install
sudo ./utils/install_server.sh

配置

建立 /etc/init.d/redis 並使用下面的代碼做爲啓動腳本。git

添加以下內容:web

bash###########################
PATH=/usr/local/bin:/sbin:/usr/bin:/bin

REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis.pid
CONF="/etc/redis/6379.conf"

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        if [ "$?"="0" ]
        then
              echo "Redis is running..."
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $REDIS_CLI -p $REDISPORT SHUTDOWN
                while [ -x ${PIDFILE} ]
               do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
   restart|force-reload)
        ${0} stop
        ${0} start
        ;;
  *)
    echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
        exit 1
esac
##############################

保存後,添加可執行權限:redis

sudo chmod +x /etc/init.d/redis

確保 redis 能隨系統啓動:sql

vi /etc/rc.d/rc.local

在文件末尾添加下面這行:shell

service redis start

而後使用上面一樣的命令啓動 redis 服務:數據庫

service redis start

安裝郵件服務器

yum -y install postfix

安裝Git

先刪除系統中原有的老版本 gitcentos

bashyum -y remove git
yum install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-devel openssl-devel

從官方網站下載源代碼進行:ruby

bashcurl --progress https://www.kernel.org/pub/software/scm/git/git-2.4.0.tar.gz | tar xz
cd git-2.4.0/
./configure
make
make prefix=/usr/local install

而後使用下面這個命令檢測安裝是否有效:

which git

安裝 ruby

若是 ruby 的版本低於 2.0 的話,則須要從新安裝 ruby

bashcd ~
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz | tar xz
cd ruby-2.2.2
./configure --disable-install-rdoc
make
make prefix=/usr/local install

爲 Gitlab 添加系統用戶

adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git

爲了包含/usr/local/bin到git用戶的$PATH,一個方法是編輯超級用戶文件。以管理員身份運行:

visudo

而後搜索:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

將其改爲:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

安裝數據庫

MySQL 已經再也不包含在 CentOS 7 的源中,而改用了 MariaDB,先搜索 MariaDB 現有的包:

rpm -qa | grep mariadb

而後所有刪除:

rpm -e --nodeps mariadb-*

而後建立 /etc/yum.repos.d/MariaDB.repo

vi /etc/yum.repos.d/MariaDB.repo

將如下內容添加至該文件中:

# MariaDB 10.0 CentOS repository list - created 2015-05-04 19:16 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

而後運行下面命令安裝 MariaDB 10.0

sudo yum install MariaDB-server MariaDB-client

而後啓動 MariaDB 服務:

service mysql start

接着運行 mysql_secure_installation

mysql_secure_installation

登陸 MariaDB 並建立相應的數據庫用戶與數據庫:

mysql -uroot -p
CREATE USER 'git'@'localhost' IDENTIFIED BY '$password';
SET storage_engine=INNODB;
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 'git'@'localhost';
\q

嘗試使用新用戶鏈接數據庫:

sudo -u git -H mysql -u git -p -D gitlabhq_production
\q

安裝 Gitlab

克隆源

sudo -u -git cd /home/git
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-10-stable gitlab

配置

cd /home/git/gitlab

# Copy the example GitLab config
# 複製GitLab的示例配置文件
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

# Make sure to change "localhost" to the fully-qualified domain name of your host serving GitLab where necessary
# 確保修改「localhost」爲你的GitLab主機的FQDN
#
# If you want to use https make sure that you set `https` to `true`. See #using-https for all necessary details.
# 若是你想要使用https確保你設置了`https`爲`true`。具體必要的細節參見#using-https
#
# If you installed Git from source, change the git bin_path to /usr/local/bin/git
# 若是你從源代碼安裝了Git,修改git的bin_path爲/usr/local/bin/git
sudo -u git -H editor config/gitlab.yml

# Make sure GitLab can write to the log/ and tmp/ directories
# 確保GitLab能夠寫入log/和temp/目錄
chown -R git {log,tmp}
chmod -R u+rwX  {log,tmp}

# Create directory for satellites
# 爲衛星(?)建立目錄
sudo -u git -H mkdir /home/git/gitlab-satellites
chmod u+rwx,g+rx,o-rwx /home/git/gitlab-satellites

# Make sure GitLab can write to the tmp/pids/ and tmp/sockets/ directories
# 確保GitLab能夠寫入tmp/pids/和temp/sockets/目錄
chmod -R u+rwX  tmp/{pids,sockets}

# Make sure GitLab can write to the public/uploads/ directory
# 確保GitLab能夠寫入public/uploads/目錄
chmod -R u+rwX  public/uploads

# Copy the example Unicorn config
# 複製Unicorn的示例配置文件
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb

# Enable cluster mode if you expect to have a high load instance
# Ex. change amount of workers to 3 for 2GB RAM server
# 啓用集羣模式若是你指望擁有一個高負載實例
# 附:修改worker的數量到3用於2GB內存的服務器
sudo -u git -H editor config/unicorn.rb

# Copy the example Rack attack config
# 複製Rack attack的示例配置文件
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

# Configure Git global settings for git user, useful when editing via web
# Edit user.email according to what is set in config/gitlab.yml
# 爲git用戶配置Git全局設定,當經過web修改時有用
# 修改user.email根據config/gitlab.yml中的設定
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "gitlab@localhost"
sudo -u git -H git config --global core.autocrlf input

數據庫配置

# MySQL only:
# 僅限MySQL:
sudo -u git cp config/database.yml.mysql config/database.yml

# MySQL and remote PostgreSQL only:
# Update username/password in config/database.yml.
# You only need to adapt the production settings (first part).
# If you followed the database guide then please do as follows:
# Change 'secure password' with the value you have given to $password
# You can keep the double quotes around the password
# 僅限MySQL和遠程PostgreSQL:
# 在config/database.yml中更新用戶名/密碼;
# 你只須要適配生產設定(第一部分);
# 若是你跟從數據庫嚮導,請按如下操做:
# 修改'secure password'使用你剛纔設定的$password;
# 你能夠保留密碼兩端的雙引號。
sudo -u git -H editor config/database.yml

# PostgreSQL and MySQL:
# Make config/database.yml readable to git only
# PostgreSQL和MySQL:
# 設置config/database.yml僅對git可讀。
sudo -u git -H chmod o-rwx config/database.yml

安裝 Gems

cd /home/git/gitlab

# For users from China mainland only
# 僅限中國大陸用戶
nano /home/git/gitlab/Gemfile
source "http://ruby.taobao.org" // 原始 source "https://rubygems.org/"

# For MySQL (note, the option says "without ... postgres")
sudo -u git -H bundle install --deployment --without development test postgres aws

Install GitLab shell

安裝GitLab Shell

GitLab Shell是一個專門爲GitLab開發的SSH訪問和源管理軟件。

# Go to the Gitlab installation folder:
# 轉到GitLab安裝目錄:
cd /home/git/gitlab

# For users from China mainland only
# 僅限中國大陸用戶
nano /home/git/gitlab/Gemfile
source "http://ruby.taobao.org" // 原始 source "https://rubygems.org/"

# Run the installation task for gitlab-shell (replace `REDIS_URL` if needed):
# 運行gitlab-shell的安裝任務(替換`REDIS_URL`若是有須要的話):
sudo -u git -H bundle exec rake gitlab:shell:install[v1.9.6] REDIS_URL=redis://localhost:6379 RAILS_ENV=production

# By default, the gitlab-shell config is generated from your main gitlab config.
# 默認的,gitlab-shell的配置文件是由你的gitlab主配置文件生成的。
#
# Note: When using GitLab with HTTPS please change the following:
# - Provide paths to the certificates under `ca_file` and `ca_path options.
# - The `gitlab_url` option must point to the https endpoint of GitLab.
# - In case you are using self signed certificate set `self_signed_cert` to `true`.
# See #using-https for all necessary details.
# 提示:當經過HTTPS使用GitLab時,請作出以下更改:
# - 提供證書的路徑在`ca_file`和`ca_path`選項;
# - `gitlab_url`選項必須指向GitLab的https端點;
# - 若是你使用自簽名的證書,設置`self-signed_cert`爲`true`。
# 全部必需的具體細節參見#using-https
#
# You can review (and modify) it as follows:
# 你能夠檢查(並修改該)經過如下方法:
sudo -u git -H editor /home/git/gitlab-shell/config.yml

# Ensure the correct SELinux contexts are set
# Read http://wiki.centos.org/HowTos/Network/SecuringSSH
# 確保正確的SELinux上下文被設置
# 閱讀http://wiki.centos.org/HowTos/Network/SecuringSSH
restorecon -Rv /home/git/.ssh

初始化數據庫和激活高級功能

sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
# Type 'yes' to create the database tables.
# When done you see 'Administrator account created:'

提示:你能夠設置管理員密碼經過在環境變量GITLAB_ROOT_PASSWORD中提供,例如:

sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=newpassword

安裝初始化腳本

下載初始化腳本(將放在/etc/init.d/gitlab):

sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
chmod +x /etc/init.d/gitlab
chkconfig --add gitlab

設置GitLab開機啓動:

chkconfig gitlab on

設置日誌翻轉

cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

檢查應用狀態

sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

編譯靜態文件

sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production

啓動實例

/etc/init.d/gitlab start
相關文章
相關標籤/搜索