centos 6.5安裝GitLab安裝

centos 6.5安裝GitLab安裝

1、安裝操作系統

a、安裝wget(系統版本是6.5

#yum -y install wget

b、增加EPEL安裝源

EPEL,即Extra Packages for Enterprise Linux,這個軟件倉庫裏有很多非常常用的軟件,而且是專門針對RHEL設計的,對RHEL標準yum源是一個很好的補充,完全免費使用,由 Fedora項目維護,所以如果你使用的是RHEL,或者CentOS,Scientific等RHEL系的linux,可以非常放心的使用EPEL的 yum源。

下載並安裝GPG key

#wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 https://www.fedoraproject.org/static/0608B895.txt
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

安裝epel-release-6-8.noarch包


# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

c、增加PUIAS安裝源

PUIAS Linux是面向桌面和服務器的完整的操作系統,它靠編譯Red Hat Enterprise Linux的源代碼包來創建。除了這些上游的軟件包外,該項目還提供一些其他的軟件倉庫:“Addons”包含了通常的Red Hat發行中未收入的額外軟件包,“Computational”提供專門針對科學計算的軟件,“Unsupported”則收入各種各樣的測試性軟件 包。該發行由美國普林斯頓 大學的高等研究所維護。

創建/etc/yum.repos.d/PUIAS_6_computational.repo,並添加如下內容:

[PUIAS_6_computational]
name=PUIAS computational Base $releasever - $basearch
mirrorlist=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch/mirrorlist
#baseurl=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puias

下載並安裝GPG key

#wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-puiashttp://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias

#rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-puias

檢驗下是否安裝成功

# rpm -qa gpg*

Tips:安裝完EPEL和PUIAS兩個源後,可以檢測下:

#yum repolist

d、安裝GitLab的所需依賴包和工具

# yum -y groupinstall 'Development Tools'
# yum -y install vim-enhanced readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel gcc-c++ libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui python-devel redis sudo wget crontabs logwatch logrotate perl-Time-HiRes git
RHEL提示
如果部分包不能安裝,例如: eg. gdbm-devel, libffi-devel and libicu-devel,那麼增加rhel6的安裝源。
# yum-config-manager --enable rhel-6-server-optional-rpms
e、配置redis(redis安裝見備註)
備註:
#tar zxvf redis-3.0.0.tar.gz
#cd redis-3.0.0
#make && make install

配置redis使其在開機時啓動:
# sudo chkconfig redis on
# sudo service redis start
f、配置郵件服務器(這裏不做設置)
2、安裝Ruby
下載並編譯:
# mkdir /tmp/ruby && cd /tmp/ruby
# curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz | tar xz
# cd ruby-2.0.0-p353
# ./configure --prefix=/usr/local/
# make && make install
安裝完成後,重新登錄終端確保$PATH生效,檢測ruby的安裝成功與否:
# which ruby
/usr/local/bin/ruby
# cd /usr/local/bin/
# ruby -v
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
安裝bundle:
# sudo gem install bundler --no-ri --no-rdoc
如果提示sudo: gem: command notfound,使用root賬號登錄執行該命令即可。
安裝過程中會出現下面的錯誤.解決方法:
[[email protected]]# geminstall bundler --no-ri --no-rdoc
ERROR:  Could not find a valid gem 'bundler' (>=0), here is why: Unable to download data from https://rubygems.org/ -Errno::ETIMEDOUT: Connection timed out - connect(2)(https://rubygems.org/latest_specs.4.8.gz)
是因爲國內網絡導致rubygems.org存放在Amazon S3上面的資源文件間歇性連接失敗,用國內的RubyGems鏡像(參見http://ruby.taobao.org/)替換官方鏡像,方法如下:
[[email protected]]# gemsources --remove https://rubygems.org/
https://rubygems.org/removed from sources
[[email protected]]# gemsources -a https://ruby.taobao.org/
https://ruby.taobao.org/added to sources
[[email protected]]# gemsources -l
*** CURRENT SOURCES***
https://ruby.taobao.org/
[[email protected]]# geminstall bundler --no-ri --no-rdoc
Fetching:bundler-1.7.6.gem (100%)
Successfullyinstalled bundler-1.7.6
1 gem installed

3、系統用戶
創建用戶git
#adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git
因爲git用戶不需要登錄,所以這裏不需要設置git的密碼。
4、配置GitLab shell
GitLabshell是專門爲GitLab開發的提供ssh訪問和版本管理的軟件。
先使用root登錄,而後切換成git
# su - git
克隆gitlab shell
$ git clone https://github.com/gitlabhq/gitlab-shell.git
$ cd gitlab-shell
切換成1.8.0版本,並編輯配置
$ git checkout v1.8.0
$ cp config.yml.example config.yml
這裏最重要的是將gitlab_url修改成gitlab的訪問域名。形如:http://test.gitlab.com/
筆者注:如果gitlab是使用https訪問,則需將http替換成https,配置文件中的self_signed_cert要修改成true,否則 gitlab shell在通過api和gitlab進行通信的時候就會出現錯誤,導致項目push出錯。因爲後面配置web服務器的時候是使用ssl,所以這裏要按照 ssl的方式配置。
Tips:另外如果使用的域名是測試域名,不要忘記在系統的/etc/hosts做域名映射。
安裝一些需要的目錄和文件
$ ./bin/install
5、安裝數據庫
這裏使用的是msyql,(cmake+mysql見備註)
備註:
cmake安裝
#tar zxvf cmake-3.0.0.tar.gz
#cd cmake-3.0.0
#./configure --prefix=/usr/local/cmake
#make && make install
設置環境變量
#vi /etc/profile
添加以下
PATH=/usr/local/cmake/bin:$PATH
wq!
使配置生效:
#source /etc/profile
mysql安裝
#groupadd mysql
#useradd -g mysql mysql -s /bin/false
#mkdir -p /data/mysql
#chown -R mysql:mysql /data/mysql
#mkdir -p /usr/local/mysql
#tar zxvf mysql-5.5.17.tar.gz
#cd mysql-5.5.17
#cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc
#make && make install
#cp -r /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
#sed -i '25a datadir = /data/mysql' /etc/my.cnf
#cd /usr/local/mysql/
#./scripts/mysql_install_db --user=mysql
#cp -r /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
#sed -i "46s#basedir=#basedir=/usr/local/mysql#g" /etc/rc.d/init.d/mysqld
#sed -i "47s#datadir=#datadir=/data/mysql#g" /etc/rc.d/init.d/mysqld
#chmod 755 /etc/init.d/mysqld
#chkconfig mysqld on
#echo -e "export PATH=\$PATH:/usr/local/mysql/bin" >> /etc/profile
#ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
#ln -s /usr/local/mysql/include/mysql /usr/include/mysql
#service mysqld start
# chkconfig mysqld on
# service mysqld start
設置mysql root賬號的密碼:
# mysqladmin -u root password '123456'

創建新用戶和數據庫給gitlab使用
# 登錄數據庫
# mysql -u root -p
# 輸入root密碼
# 爲gitlab創建使用用戶
CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '123456';

# 創建gitlaba使用的數據庫
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;

# 給予gitlab用戶權限
GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';

# 登出數據庫
\q
6、安裝GitLab
將GitLab安裝在git的家目錄下:
#su - git
a、克隆GitLab並切換分支到6-3-stable
# 克隆GitLab
$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab
# 進入gitlab目錄
$ cd /home/git/gitlab
# 切換到6-3-stable分支
$ git checkout 6-3-stable
b、配置項目
複製配置文件
$ cp config/gitlab.yml.example config/gitlab.yml
修改配置文件中
$ sed -i 's|localhost|192.169.1.171|g' config/gitlab.yml

備註:192.168.1.171是我要安裝的機器
設定log和tmp目錄所有者和權限
$ chown -R git log/
$ chown -R git tmp/
$ chmod -R u+rwX log/
$ chmod -R u+rwX tmp/
創建gitlab-satellites目錄
$ mkdir /home/git/gitlab-satellites
創建tmp/pids/和tmp/sockets/目錄,確保gitlab有相應的權限
$ mkdir tmp/pids/
$ mkdir tmp/sockets/
$ chmod -R u+rwX tmp/pids/
$ chmod -R u+rwX tmp/sockets/
創建public/uploads目錄
$ mkdir public/uploads
$ chmod -R u+rwX public/uploads
複製unicorn配置
$ cp config/unicorn.rb.example config/unicorn.rb
編輯resque.yml配置
$ vim config/resque.yml
development: redis://192.168.1.171:6379
test: redis://192.168.1.171:6379
production: redis://192.168.1.171:6379
配置git的用戶和郵件
$ git config --global user.name "GitLab"
$ git config --global user.email "[email protected]"(以你真實的域名填寫)
$ git config --global core.autocrlf input
c、配置數據庫訪問文件
$ cp config/database.yml.mysql config/database.yml
編輯config/database.yml,設置其中連接數據庫的賬號密碼,筆者的配置部分如下:
# PRODUCTION
#
production:
 adapter: mysql2
 encoding: utf8
 reconnect: false
 database: gitlabhq_production
 pool: 10
 username: gitlab
 password: "123456"
 # host: localhost
 # socket: /tmp/mysql.sock
修改其中username和password就可以了,其中密碼就是上面數據庫步驟中創建gitlab用戶的密碼。
確保該文件只有git賬號有權限讀取。
$ chmod o-rwx config/database.yml
d、安裝Gems
$ su -
# gem install charlock_holmes --version '0.6.9.4'
# exit
安裝mysql包
$ su - git
$ cd /home/git/gitlab/
$ bundle install --deployment --without development test postgres puma aws
備註:
[轉]Could not find modernizr-2.6.2 in any of the sources 解決辦法:

[git@Git gitlab]$ vi Gemfile
source "https://rubygems.org"改爲source "http://rubygems.org"
[git@Git gitlab]$ bundle install --deployment--without development test postgres
Fetching source indexfrom http://rubygems.org/
Fetchinghttps://github.com/gitlabhq/grit.git
Could not findmodernizr-2.6.2 in any of the sources
#出現錯誤:Could not find modernizr-2.6.2 in any of thesources
#解決辦法:
[git@Git gitlab]$ vi Gemfile
第114行   gem"modernizr",       "2.6.2"
更改改爲:
第114行   gem "modernizr-rails",  "2.7.1"
[git@Git gitlab]$ vi Gemfile.lock
第252行     modernizr (2.6.2)
更改改爲:
第252行     modernizr-rails (2.7.1)
第523行   modernizr (= 2.6.2)
更改改爲:
第523行   modernizr-rails (= 2.7.1)
#重新執行:
[git@Git gitlab]$ bundleinstall --deployment --without development test postgres puma aws

e、初始化數據和激活高級功能
$ cd /home/git/gitlab
$ bundle exec rake gitlab:setup RAILS_ENV=production
這步完成後,會生一個默認的管理員賬號:
[email protected]
5iveL!fe
f、安裝啓動腳本
# cd /home/git/gitlab    
# cp lib/support/init.d/gitlab /etc/init.d/    
# chmod +x /etc/init.d/gitlab
設置logarate
# cd /home/git/gitlab
# cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
# chkconfig --add gitlab
開機時啓動
# chkconfig gitlab on
g、檢測應用程序狀態
$ su - git
$ cd gitlab/
$ bundle exec rake gitlab:env:info RAILS_ENV=production
$ exit
可以查看到系統、Ruby、GitLab和GitLabShell的版本和其他信息。
啓動GitLab實例
$ service gitlab start
h、查看應用更加詳細的信息
$ su - git
$ cd gitlab/
$ bundle exec rake gitlab:check RAILS_ENV=production
7、安裝web服務器
選擇的是nginx,
$ su -
# yum -y install nginx
# chkconfig nginx on
# mkdir /etc/nginx/sites-available
# mkdir /etc/nginx/sites-enabled
#cd /home/git/gitlab# cp lib/support/nginx/gitlab /etc/nginx/sites-available/
# ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab    
  修改域名
vim /etc/nginx/sites-enabled/gitlab
server_name 192.168.1.171;
修改nginx配置文件其中
   # Load configfiles from the /etc/nginx/conf.d directory
   # The defaultserver is in conf.d/default.conf
#    include/etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}
重啓服務
#/etc/init.d/nginx restart
8 測試
訪問:
http://192.168.1.171/














發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章