天天看點

centos6安裝gitlab

#剛玩部落格還不會排版,其實這是我寫的一鍵腳本,不小心給自己點個贊(汗!)

#谷歌你最好的老師沒有之二

#gitlab基于ruby開發模仿Github的版本控制軟體,因為是開源的,,但是我們确實有這樣的需求,相比Gtihub來說可以減少很多成本.

#從安裝ruby、git、資料庫、web、和gitlab到通路,一定要有耐心.

#安裝環境:

##[root@localhost config]# uname -r

##2.6.32-279.el6.x86_64

##[root@localhost config]# cat /etc/redhat-release

##CentOS release 6.3 (Final)

一.安裝依賴

## 安裝epel-release

yum -y install http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

#安裝ruby依賴包

## packages (from rvm install message):

yum -y install libicu-devel patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make autoconf automake libtool bison libxml2-devel libxslt-devel libyaml-devel mysql-devel

#安裝或者更新git

yum -y remove git

yum -y install zlib-devel openssl-devel cpio expat-devel gettext-devel curl-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker

wget http://git-core.googlecode.com/files/git-1.8.3.4.tar.gz

tar -zxf git-1.8.3.4.tar.gz

cd git-1.8.3.4

make prefix=/usr all

make prefix=/usr install

cd ..

#安裝前版本

[root@gitlab ~]# git --version

git version 1.7.1

#安裝後版本

git version 1.8.3.4

二.安裝RVM

#RVM工具

curl -L get.rvm.io | bash -s stable

 #出現以下資訊為安裝成功  

# Administrator,

#

#   Thank you for using RVM!

#   We sincerely hope that RVM helps to make your life easier and more enjoyable!!!

# ~Wayne, Michal & team.

#加載RVM,改名(使用淘寶源)

source /etc/profile.d/rvm.sh

cp /usr/local/rvm/config/db  /usr/local/rvm/config/db.bk

sed -i 's#ftp.ruby-lang.org/pub/ruby#ruby.taobao.org/mirrors/ruby#' /usr/local/rvm/config/db

sed -i 's#cache.ruby-lang.org/pub/ruby#ruby.taobao.org/mirrors/ruby#' /usr/local/rvm/config/db

#安裝libyaml(防止後期報錯,可不裝)

rvm pkg install libyaml

三.安裝ruby

#安裝ruby

#rvm install 2.0.0-p247 --with-libyaml-dir=/usr/local/rvm/usr

#rvm --default use 2.0.0-p247

rvm install 2.0.0-p353 --with-libyaml-dir=/usr/local/rvm/usr

rvm --default use 2.0.0-p353

#引用淘寶ruby源

gem sources --remove https://rubygems.org/

gem sources -a http://ruby.taobao.org/

gem sources -l

#安裝bundler

gem install bundler --no-ri --no-rdoc

四.安裝gitlab-shell

#建立使用者git

adduser --system --create-home --comment 'GitLab' git

#複制gitlab-shell到本地

su - git -c "git clone https://github.com/gitlabhq/gitlab-shell.git"

su - git -c "cd gitlab-shell;git checkout v1.7.0"

##修改配置檔案

su - git -c "cp gitlab-shell/config.yml.example gitlab-shell/config.yml"

##安裝

su - git -c "gitlab-shell/bin/install"

五.安裝Redis和mysql

#安裝Redis,據說進階特性需要

yum -y install redis ;service redis start ; chkconfig redis on

#安裝mysql

#安裝Mysql資料庫.略過,以及資料庫操作

##yum install -y mysql-server mysql-devel ; chkconfig mysqld on ; service mysqld start

#編譯安裝宣告下變量

##export PATH="/opt/mysql/bin:$PATH"

##echo "export PATH="/opt/mysql/bin:$PATH"">>/etc/profile

##修改root密碼

#echo "UPDATE mysql.user SET Password=PASSWORD('$MYSQL_ROOT_PW') WHERE User='root'; FLUSH PRIVILEGES;" | mysql -u root

##建立gitlab資料庫

#echo "CREATE DATABASE IF NOT EXISTS gitlabhq_production DEFAULT CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';" | mysql -u root

CREATE DATABASE IF NOT EXISTS gitlabhq_production DEFAULT CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';

##建立連接配接資料庫使用者

grant  all on  gitlabhq_production.* to gitlab@localhost identified by '123456';

六.安裝gitlab

#複制GitLab到本地

su - git -c "git clone https://github.com/gitlabhq/gitlabhq.git gitlab"

## 檢查

su - git -c "cd gitlab;git checkout 5-4-stable"

#以下操作在/home/git/gitlab

cd /home/git/gitlab

### 複制配置檔案

su git -c "cp config/gitlab.yml.example config/gitlab.yml"

### 修改配置檔案主機名(可以不做)

sed -i "s/  host: localhost/  host: gitlab.test/g" config/gitlab.yml

### 修改郵件位址

sed -i "s/from: gitlab@localhost/from: [email protected]/g" config/gitlab.yml

#修改puma.rb檔案

su git -c "cp config/puma.rb.example config/puma.rb"

sed -i "s/0.0.0.0:9292/127.0.0.1:3000/g" /home/git/gitlab/config/puma.rb

sed -i "s/# bind/bind/g" /home/git/gitlab/config/puma.rb

#為git使用者授權

su git -c "chown -R git /home/git/gitlab/log/;chmod -R u+rwx /home/git/gitlab/log/;chown -R git /home/git/gitlab/tmp/;chmod -R u+rwx /home/git/gitlab/tmp/;mkdir /home/git/gitlab-satellites;mkdir /home/git/gitlab/tmp/pids/;chmod -R u+rwx /home/git/gitlab/tmp/pids/;mkdir /home/git/gitlab/tmp/sockets/;chmod -R u+rwx /home/git/gitlab/tmp/sockets/;mkdir /home/git/gitlab/public/uploads;chmod -R u+rwX /home/git/gitlab/public/uploads"

### 複制資料配置檔案

su git -c "cp config/database.yml.mysql config/database.yml"

### 設定mysql使用者和密碼

sed -i "s/root/gitlab/g" config/database.yml

sed -i "s/secure password/123456/g" config/database.yml

### 配置git使用者

su git -c 'git config --global user.name  "GitLab"'

su git -c 'git config --global user.email "gitlab@$GL_HOSTNAME"'

七.安裝 Gems

## 安裝

gem install charlock_holmes --version '0.6.9'

#bundle使用淘寶源,并且安裝(時間長.)

sed -i '1s/https/http/g' /home/git/gitlab/Gemfile

sed -i '1s/rubygems/ruby.taobao/g' /home/git/gitlab/Gemfile

#安裝bundle

su git -c "bundle install --deployment --without development test postgres"

八.初始化資料庫

#初始化資料庫

export force=yes

su git -c "bundle exec rake gitlab:start RAILS_ENV=production"

su git -c "bundle exec rake gitlab:setup RAILS_ENV=production"

#初始化在資料庫裡添加資料,最後後會出現:

#使用者名:[email protected]

#密  碼:5iveL!fe

#su git -c "bundle exec rake gitlab:env:info RAILS_ENV=production"

九.啟動腳本

#curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab-centos

#chmod +x /etc/init.d/gitlab

curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/5-1-stable/init.d/gitlab

chmod +x /etc/init.d/gitlab

#在17行後添加2行内容

sed -i "17 a source /etc/profile.d/rvm.sh\nrvm use 1.9.3-p448" /etc/init.d/gitlab

#或者複制

##cp /home/git/gitlab/lib/support/init.d/gitlab   /etc/init.d/

#添加到開機啟動項

chkconfig gitlab on

#啟動

/etc/init.d/gitlab start

十.配置web站點

#配置nginx

#安裝nginx,(編譯安裝和rpm都能實作)

# yum -y install nginx

#下載下傳nginx下的gitlab.conf檔案

curl --output /etc/nginx/conf.d/gitlab.conf https://raw.github.com/gitlabhq/gitlab-recipes/5-1-stable/nginx/gitlab

#修改下server标簽監聽端口和域名

vim /etc/nginx/conf.d/gitlab.conf  

server {

listen 80;  

server_name gitlab.wine.cn;

#..略..

}

更改安裝目錄權限

# chown -R git:git /etc/nginx

#更改nginx所屬使用者

#注意:

#需要nginx使用者改為git,否則會出現502通路錯誤.

vim /etc/nginx/nginx.conf

#user              nginx;

user              git;

/etc/init.d/nginx start

#然後通路

gitlab.wine.cn

#####以下是報錯環節,沒怎麼整理很亂###################

[root@gitlab init.d]# sh gitlab start

Could not find mysql2-0.3.11 in any of the sources

Run `bundle install` to install missing gems.

#解決

yum install mysql-devel

gem install mysql2 -v '0.3.11'

-------------------------------------

#檢查

[root@gitlab gitlab]# /home/git/gitlab-shell/bin/check

Check GitLab API access: FAILED. code: 502

Check directories and files:

       /home/git/repositories: OK

       /home/git/.ssh/authorized_keys: OK

#解決:nginx與gitlab之間權限問題

------------------------

--------------------------------------------

#su git -c "bundle install --deployment --without development test postgres"

/usr/bin/ld: /usr/local/lib/libz.a(crc32.o): relocation R_X86_64_32 against .rodata' can not be used when making a shared object; recompile with -fPIC

/usr/local/lib/libz.a: could not read symbols: Bad value

collect2: ld 傳回 1

make: *** [nokogiri.so] 錯誤 1

make failed, exit code 2

Gem files will remain installed in /home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/nokogiri-1.5.9 for inspection.

Results logged to /home/git/gitlab/vendor/bundle/ruby/2.0.0/extensions/x86_64-linux/2.0.0/nokogiri-1.5.9/gem_make.out

An error occurred while installing nokogiri (1.5.9), and Bundler cannot continue.

Make sure that `gem install nokogiri -v '1.5.9'` succeeds before bundling.

#安裝gem install nokogiri -v '1.5.9'

linking shared-object nokogiri/nokogiri.so

/usr/bin/ld: /usr/local/lib/libz.a(crc32.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC

collect2: ld returned 1 exit status

make: *** [nokogiri.so] Error 1

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.0.0-p247/gems/nokogiri-1.5.9 for inspection.

Results logged to /usr/local/rvm/gems/ruby-2.0.0-p247/extensions/x86_64-linux/2.0.0/nokogiri-1.5.9/gem_make.out

#yum後還報錯

[root@gitlab gitlab]# gem install nokogiri -v '1.5.9'

ERROR:  While executing gem ... (Zlib::DataError)

   invalid stored block lengths

安裝zlib

cd zlib

CFLAGS="-O3 -fPIC" ./configure

make&&make install

#然後在安裝

gem install nokogiri -v '1.5.9'

----------------------------

###

[root@gitlab init.d]# bundle exec rake gitlab:env:info RAILS_ENV=production

(in /home/git/gitlab)

rake aborted!

Cant connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `connect`

/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in initialize

#使用下面,然後就不報了

#ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock

-------------------------------------------

相關資料網站:

https://gitlab.com/gitlab-org/gitlab-recipes/tree/master/install/centos

https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md

http://linuxblind.blog.51cto.com/7616603/1277018

http://www.chenshake.com/centos-6-4-installing-and-using-gitlab/#Gitlab

繼續閱讀