1. 程式人生 > >GitLab安裝過程及安裝過程所遇問題解疑(安裝過程參照光子CI之旅)

GitLab安裝過程及安裝過程所遇問題解疑(安裝過程參照光子CI之旅)

本文主要參考文件:https://github.com/gitlabhq/gitlabhq/blob/5-0-stable/doc/install/installation.md

Debian/Ubuntu主要參考https://github.com/gitlabhq/gitlabhq/blob/5-0-stable/doc/install/installation.md

Centos主要參考下文內容,輔助參考https://github.com/gitlabhq/gitlabhq/blob/5-0-stable/doc/install/installation.md


安裝步驟總覽

1.安裝依賴包

2.安裝Ruby

3.建立Git使用者

4.安裝GitLab-Shell

5.配置資料庫

6.安裝GitLab

7.啟動GitLab

1.安裝依賴庫

yum install -y wget curl gcc checkinstall libxml2-dev libxslt-dev sqlite3 libsqlite3-dev libcurl4-openssl-dev libreadline6-dev libc6-dev libssl-dev libmysql++-dev make build-essential zlib1g-dev libicu-dev redis-server openssh-server git-core python-dev python-pip libyaml-dev postfix


yum install libicu-devel mysql-devel pcre-devel

安裝python,官方要求版本必須在2.5以上,而且不支援3.0。

yum install python
安裝完檢視下版本
python --version
還要確保python2命令有效
python2 --version
如果提示 bash: python2: 未找到命令 ,那你需要link一下
sudo ln -s /usr/bin/python /usr/bin/python2

系統自帶舊版本python被嚴重依賴時,就不要解除安裝舊版本python,直接安裝新版本python即可。

wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
tar zxvf Python-2.7.6.tgz
cd Python-2.7.6
./configure --prefix=/usr/bin/python2.7
make
make install
檢視python是否正常
/usr/bin/python2.7/bin/python2.7 -V

建立一個連線是系統預設python變為python2.7

ln -s /usr/bin/python2.7/bin/python2.7 /usr/bin/python



2.安裝Ruby

!!!注意:

在安裝Ruby之前需要先安裝libyaml,如果沒先安裝libyaml,後期執行 bundle exec rake

gitlab:setup RAILS_ENV=production ,會報 can't dump anonymous class Class 錯誤。

安裝 libyaml

wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
tar xzvf yaml-0.1.4.tar.gz
cd yaml-0.1.4
./configure --prefix=/usr/local
make
make install
安裝 Ruby 1.9.3-p0
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.gz
tar xzvf ruby-1.9.3-p0.tar.gz
cd ruby-1.9.3-p0
./configure --prefix=/usr/local --enable-shared --disable-install-doc --with-opt-dir=/usr/local/lib
make
make install

!!!注意:

Ruby 1.9.3-p0執行 make 時,會出現 ossl_pkey_ec.c 錯誤,

解決方法:

vi ext/openssl/ossl_pkey_ec.c  #此檔案放置在ruby-1.9.3-p0目錄下

#在method = EC_GFp_nist_method();下一行新增 #if !defined(OPENSSL_NO_EC2M)
#在method =  EC_GFp_simple_method();下一行新增 #endif

            if (id == s_GFp_simple) {
                method = EC_GFp_simple_method();
            } else if (id == s_GFp_mont) {
                method = EC_GFp_mont_method();
            } else if (id == s_GFp_nist) {
                method = EC_GFp_nist_method();
#if !defined(OPENSSL_NO_EC2M)
            } else if (id == s_GF2m_simple) {
                method = EC_GF2m_simple_method();
#endif
            }

#在new_curve = EC_GROUP_new_curve_GFp;下一行新增 #if !defined(OPENSSL_NO_EC2M)
#在new_curve = EC_GROUP_new_curve_GF2m;下一行新增 #endif

            if (id == s_GFp) {
                new_curve = EC_GROUP_new_curve_GFp;
#if !defined(OPENSSL_NO_EC2M)
            } else if (id == s_GF2m) {
                new_curve = EC_GROUP_new_curve_GF2m;
#endif
            } else {
                ossl_raise(rb_eArgError, "unknown symbol, must be :GFp or :GF2m");
            }

安裝完成後,執行 ruby -v 檢視ruby版本,執行gem -v 檢視gem版本(執行完畢如果只出現版本而不是提示需要安裝libyaml,證明libyaml安裝成功)

安裝 Bundler

sudo gem install bundler

3.建立Git使用者

建立一個 git 使用者供GitLab使用

adduser --comment 'GitLab' git

讓git使用者無密碼登陸

sudo chmod 644 /etc/shadow vim /etc/shadow

這裡感覺 664 許可權不夠用那就改為 777 許可權

去掉使用者的感嘆號

git:!!:15814:0:99999:7::: 修改為 git::15814:0:99999:7:::

加入sudo組

chmod u+w /etc/sudoers
vim /etc/sudoers

## Allow root to run any commands anywhere
root ALL=(ALL) ALL
git ALL=(ALL) ALL #加入這行

4.安裝GitLab-Shell

切換到git使用者

su - git 
cd ~/

克隆GitLab-Shell

git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell
切換到最新的分支
git checkout v1.2.0 
生成配置檔案
cp config.yml.example config.yml
更改配置資訊,一般就改下你部署的域名地址gitlab_url
vim config.yml

# Url to gitlab instance. Used for api calls. Should be ends with slash.
gitlab_url: "http://localhost/" #改成你的域名或者IP
安裝
./bin/install

5.配置資料庫

gitlab支援mysql和postgresql,這裡以mysql為例,postgresql會比較麻煩!

切換回root使用者

su - root

沒安裝過mysql及開發包的情況

安裝mysql及開發包

yum install -y mysql-server mysql mysql-devel

安裝過mysql及開發包的情況,省略上邊的mysq安裝。

啟動資料庫

service mysqld start    #或 /etc/init.d/mysql.server start等
初始化GitLab資料庫

!!!注意:

注意1,執行 mysql -u root -p Enter password:時報ERROR 2002 (HY000): Can’t connect to

local MySQL server through socket ‘/var/lib/mysql/mysql.sock錯誤

因為sock檔案存放有時不是指向 /var/lib/mysql目錄下的(安裝方式不同,sock檔案存放位置不同),

使用  ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock 加個連線。

注意2,建立使用者後,想修改使用者的密碼,

如,建立使用者user01,CREATE USER [email protected]'localhost' IDENTIFIED BY 'password1';  修改使用者

user01密碼,SET PASSWORD FOR 'user01'@'localhost' = PASSWORD('password2');

初始化GitLab資料庫

mysql -u root -p
Enter password:
Welcome to the MySQL monitor.
Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.30 MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names

may be trademarks of their respective owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab';
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8`
COLLATE `utf8_unicode_ci`;
Query OK, 1 row affected (0.00 sec)

mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON
`gitlabhq_production`.* TO 'gitlab'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> \q
Bye
測試gitlab使用者連線mysql
sudo -u git -H mysql -u gitlab -p -D gitlabhq_production

!!!注意:

這裡可能報  sudo: /etc/sudoers is mode 0640, should be 0440 錯誤

解決方法:root使用者 chmod 0440 /etc/sudoers

6.安裝GitLab

終於到GitLab的安裝了,進入git使用者
su - git
cd ~/
克隆GitLab
sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab
cd gitlab
切換到5.0穩定分支
sudo -u git -H git checkout 5-0-stable
配置
cd /home/git/gitlab 

# 用樣例配置生成gitlab配置 

sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml 
# 更改域名 
sudo -u git -H vim config/gitlab.yml 

# 確保gitlab對 log/ 和 tmp/ 目錄有寫許可權

sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX log/
sudo chmod -R u+rwX tmp/ 
# 建立附屬目錄 
sudo -u git -H mkdir /home/git/gitlab-satellites 

# 建立pids目錄並確保對gitlab可寫

sudo -u git -H mkdir tmp/pids/
sudo chmod -R u+rwX tmp/pids/ 
# 生成Unicorn配置 
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
配置GitLab DB設定
# Mysql
sudo -u git cp config/database.yml.mysql config/database.yml
安裝Gems
cd /home/git/gitlab
sudo gem install charlock_holmes --version '0.6.9'

# For MySQL (note, the option says "without")
bundle install --deployment --without development test postgres

!!!注意:

安裝Gems中執行 bundle install --deployment --without development test postgres ,會卡住很長時間,幾個小時甚至更多,

原因,gem sources 是 https://rubygems.org/ ,解決,gem sources 改為 http://ruby.taobao.org/

!!!注意:

執行 bundle install --deployment --without development test postgres 命令時會出現各種匪夷所思的錯誤,到時候彆著急,慢慢來。

先整體看看此命令執行後顯示(非常重要),有可能是庫缺失,如出現

An error occurred while installing nokogiri (1.6.0), and Bundler cannot continue.Make sure that `gem install nokogiri -v '1.6.0'` succeeds before bundling.

可能就是libxml2、libxslt庫缺失,顯示會有libxml2  is missing libxslt is missing等

sudo yum install -y gcc ruby-devel libxml2 libxml2-devel libxslt libxslt-devel
  1. yum  install patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make autoconf automake libtool bison libxml2-devel libxslt-devel libyaml-devel 

這裡關鍵是不要慌,看完執行後全部顯示。

修改方式 ,

vi /home/git/gitlab/Gemfile

source "http://ruby.taobao.org"  // 舊 source "http://rubygems.org/"
初始化資料並激活高階特性

首先編輯/home/git/gitlab/config/database.yml

#
# PRODUCTION
#
production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: gitlabhq_production
  pool: 5
  username: root
  password: "secure password" #更改為你mysql的root使用者密碼
# host: localhost
# socket: /tmp/mysql.sock
#

執行rake

bundle exec rake gitlab:setup RAILS_ENV=production
!!!注意:

報錯,提示 can't dump anonymous class Class,檢查第二步 Ruby 時,libyaml是否優先安裝

報錯,提示 rake aborted! getaddrinfo: Name or service not known,檢查你的hosts, /etc/hosts 中 127.0.0.1 對應是否有localhost

報錯,提示Error connecting to Redis on localhost:6379 (ECONNREFUSED)

解決辦法,切換到root,安裝Redis

安裝epel

rpm -ivhhttp://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

別忘了安裝yum install yum-priorities

yum install redis*

#啟動redis
service redis start 
重新執行rake
bundle exec rake gitlab:setup RAILS_ENV=production

!!!注意:

如果你安裝最新版可能會報 /home/git/repositories/root 目錄找不到,手工建上即可!

如果你看到如下資訊:

...
Administrator account created:

[email protected]
password......5iveL!fe
恭喜你!你已經成功安裝GitLab了!別忘了記錄輸出的管理使用者名稱和密碼!

7.啟動GitLab

bundle exec rails s -e production
=> Booting WEBrick
=> Rails 3.2.13 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2013-04-19 15:04:41] INFO WEBrick 1.3.1
[2013-04-19 15:04:41] INFO ruby 1.9.3 (2013-02-22)
[x86_64-linux] [2013-04-19 15:04:41] INFO WEBrick::HTTPServer#start: pid=11488 port=3000

Ok,你現在可以訪問GitLab了,預設埠是 @[email protected], 訪問 http://你的域名或IP:3000

第一訪問會比較慢,因為要編譯很多js和css.

!!!注意:

3000埠可能受防火牆影響,關閉防火牆 chkconfig iptables off(重啟後永久性生效)service

iptables stop(及時生效,重啟後失效),或修改/etc/sysconfig/iptables檔案

新增 -A RH-Firewall-1-INPUT -m state ——state NEW -m tcp -p tcp ——dport 3000 -j ACCEPT

登陸頁面


輸入管理使用者名稱和密碼!




GitLab安裝過程中一些錯誤可以參照 https://github.com/gitlabhq/gitlab-public-wiki/wiki/Trouble-Shooting-Guide