CentOS7安裝gitlab中文版

1.安裝軟件包及解決依賴項

yum groupinstall "Development tools"
yum install gcc autoconf cmake unzip vim libcurl-devel zlib-devel curl-devel expat-devel gettext-devel openssl-devel perl-devel nodejs libicu-devel  wget curl

安裝git
若是已經用yum安裝過git,而且版本低於2.7.4,要先卸載掉舊的版本前端

yum remove git

使用源碼編譯安裝gitnode

mkdir /tmp/git && cd /tmp/git
curl -O --progress https://www.kernel.org/pub/software/scm/git/git-2.10.0.tar.gz
tar -xzf git-2.10.0.tar.gz
cd git-2.10.0
./configure
make prefix=/usr/local all
# 安裝到/usr/local/bin
make prefix=/usr/local install
# 驗證git版本號
git --version
#查看git安裝路徑
which git

# 編輯 config/gitlab.yml (第5步中), 修改 git 路徑爲 /usr/local/bin/git

2.添加系統用戶

咱們添加一個用來管理運行Gitlab的用戶gitmysql

adduser -c 'Gitlab' -s /bin/bash git
# 修改git用戶的環境變量PATH,以root用戶運行
visudo
# 找到下面一行
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin
#修改成
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:

3.安裝ruby環境

在Gitlab生產環境使用Ruby版本管理工具RVM,rbenv或者chruby經常會帶來不少疑難雜症.好比Gitlab-shell版本管 理器調用OpenSSH的功能以防止越過ssh對倉庫進行pull和push操做.而前面提到的三個版本管理器不支持這樣的功能,因此咱們強烈建議你們按 照下面的方式來安裝Ruby.linux

  1. 若是系統上存在舊的Ruby1.8,先刪除掉
    yum remove ruby

     

  2. 下載Ruby源碼,編譯安裝:
    mkdir /tmp/ruby && cd /tmp/ruby
    curl -O --progress https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz
    tar xzf ruby-2.3.1.tar.gz
    cd ruby-2.3.1
    ./configure --disable-install-rdoc
    make && make install

     

  3. 國內使用Ruby的Gem和Bundler必需要作的事情:
    # 修改git用戶gem安裝源爲中科大源
    $  gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
    # 確保git用戶當前gems源爲中科大源
    $  gem sources -l
    *** CURRENT SOURCES ***
    
    https://gems.ruby-china.org/

     

  4. 安裝bundle包
    gem install bundler --no-ri --no-rdoc
    # 修改bundler的源爲中科大源
    sudo -u git -H bundle config mirror.https://rubygems.org https://gems.ruby-china.org/

     

4.安裝GO

從Gitlab8.0開始,Git的HTTP請求由gitlab-git-http-server來處理.咱們須要Go編譯器來安裝gitlab-git-http-server.下面一系列的指令都將假定你用的是64位的Linux系統.你也能夠在GoLang官方網站下載其餘平臺的Go編譯器.nginx

$ mkdir /tmp/go && cd /tmp/go
$ curl -O --progress http://www.golangtc.com/static/go/1.6.2/go1.6.2.linux-amd64.tar.gz
$ tar -C /usr/local -xzf go1.6.2.linux-amd64.tar.gz
$ sudo ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/
$ rm go1.6.2.linux-amd64.tar.gz
#驗證go是否安裝正確
$ go version
go version go1.6.2 linux/amd64

5.安裝數據庫

Gitlab官方建議咱們用PostgreSQL數據庫.若是喜歡用Mysql請前往Gitlab使用Mysql數據庫的安裝說明.git

略過golang

6.Redis

版本要求: redis版本不低於2.8.web

添加redis用戶和組redis

groupadd redis && useradd -g redis redis -s /sbin/nologin
  1. 編譯安裝redis
    mkdir /tmp/redis && cd /tmp/redis
    #這裏是最新的
    curl -O --progress http://download.redis.io/releases/redis-stable.tar.gz
    tar zxf redis-stable.tar.gz
    cd redis-stable
    make && make install
    mkdir -p /etc/redis
    cp redis.conf /etc/redis

     

  2. 修改redis配置
    cp /etc/redis/redis.conf /etc/redis/redis.conf.orig
    # 把'post'設置爲0以禁止監聽TCP端口
    sed 's/^port .*/port 0/' /etc/redis/redis.conf.orig | sudo tee /etc/redis/redis.conf
    # 讓redis以socket方式啓動
    echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis/redis.conf
    # 啓動守護進程
    sed -i 's/daemonize no/daemonize yes/g' /etc/redis/redis.conf
    # 建立存放socket的目錄
    mkdir /var/run/redis
    sudo chown redis:redis /var/run/redis
    sudo chmod 755 /var/run/redis
    # Persist the directory which contains the socket, if applicable
    if [ -d /etc/tmpfiles.d ]; then
      echo 'd  /var/run/redis  0755  redis  redis  10d  -' | sudo tee -a /etc/tmpfiles.d/redis.conf
    fi
    # 把git用戶加入redis組
    sudo usermod -aG redis git
    # 下載redis init 腳本
    $ curl -L http://packages.gitlab.cc/install/init-script/redis/cenots6/redis-server -o /etc/init.d/redis-server
    $ chmod +x /etc/init.d/redis-server

     

  3. 啓動Redis
    # 啓動redis服務
    $ service redis-server start
    # 將redis加入自啓動
    $ chkconfig redis-server on

     

7.安裝GitLab

# 咱們將gitlab安裝到git用戶的HOME目錄
cd /home/git

克隆gitlab源碼

sudo -u git -H git clone https://gitlab.com/larryli/gitlab.git -b 8-8-zh gitlab

Note: 你能夠直接克隆,這樣就能夠體驗到最新的中文版本sql

配置GitLab

# 進入gitlab目錄
cd /home/git/gitlab

# 複製gitlab.yml(Gitlab的主配置文件)
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

# 修改gitlab.yml
sudo -u git -H vim config/gitlab.yml
####修改第32行 host: localhost爲 host: 你的域名或者ip
####修改第435行 bin_path: /usr/bin/git 爲bin_path: /usr/local/bin/git

# 複製 secrets 文件
sudo -u git -H cp config/secrets.yml.example config/secrets.yml
sudo -u git -H chmod 0600 config/secrets.yml

# 修改 log/ 和 tmp/ 文件夾權限
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX,go-w log/
sudo chmod -R u+rwX tmp/

# 修改 tmp/pids/ 個 tmp/sockets/ 文件夾權限
sudo chmod -R u+rwX tmp/pids/
sudo chmod -R u+rwX tmp/sockets/

# 建立 public/uploads/ 文件夾
sudo -u git -H mkdir public/uploads/

# 修改 public/uploads/ 文件夾權限,只有git用戶有訪問權限
# now that files in public/uploads are served by gitlab-workhorse
sudo chmod 0700 public/uploads

# 修改 CI build traces are stored 文件夾的權限
sudo chmod -R u+rwX builds/

# 修改 CI artifacts are stored 文件夾的權限
sudo chmod -R u+rwX shared/artifacts/

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

# 查詢CPU核心數
nproc

# 若是你想搭建一個高負載的Gitlab實例,可啓用集羣模式.
# 修改'worker_processes'參數,至少要跟cpu核心數同樣.
# 舉例:2G RAM的服務器修改workers數量爲3
sudo -u git -H vim config/unicorn.rb

# 複製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
# 'autocrlf' is needed for the web editor
sudo -u git -H git config --global core.autocrlf input

# Disable 'git gc --auto' because GitLab already runs 'git gc' when needed
sudo -u git -H git config --global gc.auto 0

# 複製 Redis 鏈接配置文件
sudo -u git -H cp config/resque.yml.example config/resque.yml

# 若是以前修改過redis socket的路徑,在這個配置文件裏面修改成當前的路徑.
sudo -u git -H vim config/resque.yml

修改GitLab DB 設置

# 此命令僅針對PostgreSQl:
sudo -u git cp config/database.yml.postgresql config/database.yml
# 若是使用Mysql,執行下面命令
sudo -u git cp config/database.yml.mysql config/database.yml


#host,socket有必要能夠本身修改
# 如下修改針對MySQL和遠程PostgreSQL:
# 修改username/password.
# 生產環境只須要修改第一部分便可.
# 修改'secure password' 爲你設置的密碼
# 密碼字段可使用"雙引號" 
sudo -u git -H vim config/database.yml

# PostgreSQL MySQL都適用:
# 修改database.yml的權限,確保git用戶能夠讀取該文件.
sudo -u git -H chmod o-rwx config/database.yml

安裝Gems包

這個步驟是不少新手頭疼的問題,不過你只要嚴格按照本文關於Ruby環境的搭建來作.仍是能夠保證你順利的安裝下來的.

Note: 自bundler1.5.2起,你可使用bundle install -jN(N就是cpu核心數)安裝Gems,速度比以前要快大約60%.詳細的內容能夠點此處查看.不過首先要確保你的bundler版本>=1.5.2(運行bundle -v查看).

#若是是mysql首先執行
yum install mysql-devel
####必定要注意選擇本身用的數據庫的命令
#  PostgreSQL (note, the option says "without ... mysql")
sudo -u git -H bundle install --deployment --without development test mysql aws kerberos

# 若是使用 MySQL,執行下面的命令 (note, the option says "without ... postgres")
sudo -u git -H bundle install --deployment --without development test postgres aws kerberos

#這裏可能中間會出錯,多執行幾回就能夠了

安裝Gitlab-shell

GitLab Shell是專爲GitLab開發的ssh訪問和倉庫管理的軟件.

# 修改gitlab 安裝 gitlab-shell的rake任務腳本
sudo -u git -H sed -i 's/https:\/\/gitlab.com\/gitlab-org\/gitlab-shell.git/https:\/\/git.oschina.net\/qiai365\/gitlab-shell.git/g'  /home/git/gitlab/lib/tasks/gitlab/shell.rake

# 運行安裝gitlab shell的任務 (根據本身的redis安裝狀況修改`REDIS_URL`),這裏若是你事先沒有clone gitlab-shell的倉庫,就會自動clone官方的倉庫進行安裝:
sudo -u git -H bundle exec rake gitlab:shell:install REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production

# 默認狀況下,gitlab-shell的配置是根據Gitlab的配置生產的.
# 你能夠運行下面的命令查看和修改gitlab-shell的配置:
sudo -u git -H vim /home/git/gitlab-shell/config.yml

Note: Make sure your hostname can be resolved on the machine itself by either a proper DNS record or an additional line in /etc/hosts (「127.0.0.1 hostname」). This might be necessary for example if you set up GitLab behind a reverse proxy. If the hostname cannot be resolved, the final installation check will fail with 「Check GitLab API access: FAILED. code: 401」 and pushing commits will be rejected with 「[remote rejected] master -> master (hook declined)」.

安裝成功如圖所示:

安裝gitlab-workhorse

cd /home/git
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-workhorse.git
cd gitlab-workhorse
sudo -u git -H git checkout 0.7.2
sudo -u git -H make

初始化數據庫,激活高級特性

cd /home/git/gitlab

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

# 輸入 'yes' 以建立數據庫表

# 當看到 'Administrator account created:' 表示已經安裝完成

#在執行時可能最後會出錯
#You have 1 pending migration:
#  20160516174813 AddSendUserConfirmationEmailToApplicationSettings
#Run `rake db:migrate` to update your database then try again.
此能夠執行下面語句

sudo -u git -H bundle exec rake db:migrate RAILS_ENV=production
而後再從新執行
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
#這裏注意redis.socket權限問題

安全設置 secrets.yml

secrets.yml文件爲每一個會話和安全變量存儲密鑰.把這個文件備份到別的地方,可是不要和數據庫備份放在一塊,不然你的數據庫備份損壞會致使這個文件丟失.

安裝Gitlab init腳本

sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab

#複製下面這個配置文件,若是你的gitlab不是安裝在/home/git/gitlab目錄,根據本身狀況修改這個文件。

sudo cp lib/support/init.d/gitlab.default.example /etc/default/gitlab

設置GItlab爲自啓動

chkconfig gitlab on

安裝Logrotate

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

檢查GitLab環境配置

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

效果如圖

生成GitLab前端資源

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

啓動GitLab

sudo service gitlab start
# 或者
sudo /etc/init.d/gitlab restart

再檢查一次Gitlab的全部組件

sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
# 若是上面的檢查有錯誤,按照提示修復下,再重啓GitLab便可

經過修改/home/git/gitlab/config/unicorn.rb的listen端口,而後重啓gitlab服務,就能夠直接訪問服務器ip加端口來訪問gitlab了

 

使用nginx代理gitlab-workhorse.socket,並綁定域名訪問GitLab

# 複製gitlab的nginx配置文件到nginx的conf.d目錄
cp /home/git/gitlab/lib/support/nginx/gitlab /etc/nginx/conf.d/gitlab.conf

#修改gitlab的nginx配置文件
vim /etc/nginx/conf.d/gitlab.conf
找到server_name YOUR_SERVER_FQDN,將YOUR_SERVER_FQDN修改成你的域名,如demo.gitlab,cc;
# 修改/home/git/目錄的權限
sudo chmod 755 /home/git/
相關文章
相關標籤/搜索