安装gitlab
摘要 本文介紹了gitlab的安裝,給出來安裝過程中出現的問題和解決的方式,供大家參考。自動安裝gitlab的方法見http://my.oschina.net/u/1169607/blog/345833。
Gitlab是一個用Ruby?on?Rails開發的開源項目管理程序,可以通過WEB界面進行訪問公開的或者私人項目。它和Github有類似的功能,能夠瀏覽源代碼,管理缺陷和注釋。
下面介紹如何手動在Centos下搭建配置GitLab,自動安裝gitlab的方法見http://my.oschina.net/u/1169607/blog/345833。
1?安裝依賴
1.1?修改yum源
國內比較快的有163源、sohu源,這里以CentOS6.5中修改yum源為例子:
1.?cd?/etc/yum.repos.d
2.?mv?CentOS-Base.repo?CentOS-Base.repo.backup
3.?wget?http://mirrors.163.com/.help/CentOS6-Base-163.repo
4.?mv?CentOS6-Base-163.repo?CentOS-Base.repo
5.yum?clean?all
1.2?安裝epel源
Centos下官方倉庫的軟件比較老舊,推薦先添加epel源,centos6選6,5就選5:
32位系統選擇:
rpm?-ivh?http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm?-ivh?http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
64位系統選擇:
rpm?-ivh?http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm?-ivh?http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
導入key:
rpm?--import?/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
rpm?--import?/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-5
如果用比較新的軟件,用epel-test.repo這個文件就行了
另外還要安裝yum?install?yum-priorities
[root@localhost?yum.repos.d]#?ls?|grep?epel
epel.repo
epel-testing.repo
1.3?安裝依賴
sudo?yum?install?git?patch?gcc-c++?readline-devel?zlib-devel?libffi-devel?openssl-devel?make?autoconf?automake?libtool?bison?libxml2-devel?libxslt-devel?libyaml-devel?git?python?python-docutils?wget
2?安裝?Ruby?2.0
需要安裝Ruby2.0,軟件倉庫中的Ruby?1.8不支持,安裝命令如下:
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?--disable-install-rdoc
make
sudo?make?install
安裝Bundler?Gem:
sudo?gem?install?bundler?--no-ri?--no-rdoc
安裝過程中會出現下面的錯誤:
[root@h77?ruby-2.0.0-p353]#?gem?install?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/)替換官方鏡像,方法如下:
[root@h77?ruby-2.0.0-p353]#?gem?sources?--remove?https://rubygems.org/
https://rubygems.org/?removed?from?sources
[root@h77?ruby-2.0.0-p353]#?gem?sources?-a?https://ruby.taobao.org/
https://ruby.taobao.org/?added?to?sources
[root@h77?ruby-2.0.0-p353]#?gem?sources?-l
***?CURRENT?SOURCES?***
?
https://ruby.taobao.org/
[root@h77?ruby-2.0.0-p353]#?gem?install?bundler?--no-ri?--no-rdoc
Fetching:?bundler-1.7.6.gem?(100%)
Successfully?installed?bundler-1.7.6
1?gem?installed
3?配置gitlab-shell
創建git用戶:
sudo?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.3.0"??
su?-?git?-c?"cp?gitlab-shell/config.yml.example?gitlab-shell/config.yml"??
sed?-i?"s/localhost/{你自己的ip或主機名}/g"?/home/git/gitlab-shell/config.yml??
su?-?git?-c?"gitlab-shell/bin/install"
4?配置數據庫
Centos下使用如下命令:
sudo?yum?install?mysql-server?
sudo?chkconfig?mysqld?on
配置MySQL:
sudo?echo?"CREATE?DATABASE?IF?NOT?EXISTS?gitlabhq_production?DEFAULT?CHARACTER?SET?'utf8'?COLLATE?'utf8_unicode_ci';"?|?mysql?-u?root?-p
5?安裝redis服務
切換到root用戶,安裝Redis,確保按照前面步驟正確安裝epel源,執行下面語句:
yum?install?redis*??
安裝完成后,啟動redis服務,設置開機啟動,語句如下:
service?redis?start?????#啟動redis??
chkconfig?redis?on?????#設置開機啟動 ?
6?安裝配置?gitlab
su?-?git?-c?"git?clone?https://github.com/gitlabhq/gitlabhq.git?gitlab"??
su?-?git?-c?"cd?gitlab;git?checkout?5-1-stable"??
su?-?git?-c?"cp?config/gitlab.yml.example?config/gitlab.yml"??
su?-?git?-c?"mkdir?/home/git/gitlab-satellites"??
su?-?git?-c?"mkdir?public/uploads"??
su?-?git?-c?"mkdir?-p?tmp/sockets/"??
su?-?git?-c?"mkdir?-p?tmp/pids/"??
sed?-i?"s/?host:?localhost/?host:?{你自己的ip或主機名}/g"?config/gitlab.yml??
sed?-i?"s/from:?gitlab@localhost/from:?gitlab@{你自己的ip或主機名}/g"?config/gitlab.yml??
su?-?git?-c?"cp?config/puma.rb.example?config/puma.rb"??
su?-?git?-c?'git?config?--global?user.name?"GitLab"'??
su?-?git?-c?'git?config?--global?user.email?"gitlab@{你自己的ip或主機名}"'
配置數據庫連接:
sudo?su?git?-c?"cp?config/database.yml.mysql?config/database.yml"
sudo?sed?-i?"s/secure?password/mysql的root密碼/g"?config/database.yml
安裝MySQL需要的Gems
sudo?-u?git?-H?bundle?install?--deployment?--without?development?test?postgres?puma?aws
該步驟問題較多,具體如下所示:
1.?出現“sudo:?bundle:?command?not?found”的錯誤,解決方式用“su?git”進入git用戶,再執行“bundle?install?--deployment?--without?development?test?postgres?aws”命令;
2.?出現“Could?not?locate?Gemfile”的錯誤,解決方式執行“bundle?install?--deployment?--without?development?test?postgres?aws”命令必須在“/home/git/gitlab”目錄下,所以“cd??/home/git/gitlab”進入該目錄;
3.?出現“Fetching?source?index?from?https://rubygems.org/”長時間沒有響應,因為Gemfile中的源連接不上,更換源,將其中的"http://rubygems.org/"變成"http://ruby.taobao.org",具體如下:
source?"http://ruby.taobao.org"??#?舊?source?"https://rubygems.org/"?
4.?出現“Could?not?find?modernizr-2.6.2?in?any?of?the?sources”問題,因為官網和淘寶的ruby源都沒有這個包,解決辦法是先手動去下載?然后root用戶安裝wget?http://rubygems.org/gems/modernizr-2.6.2.gem??&&?gem?install?modernizr,再將gitlab目錄下的Gemfile文件和Gemfile.lock文件中的“modernizr”全部換成“modernizr-rails”,版本“2.6.2”全部換成“2.7.1”;
5.?出現“An?error?occurred?while?installing?charlock_holmes?(0.6.9),?and?Bundler?cannot?continue.”問題,因為charlock_holmes沒有安裝,用root用戶執行下面命令:gem?install?charlock_holmes?-v?'0.6.9'
6.?出現“Error?installing?charlock_holmes:?ERROR:?Failed?to?build?gem?native?
extension.”問題,因為缺少某些依賴包,執行下列語句:yum?install?libicu-devel?mysql-devel?pcre-devel?postfix
7.?出現“Error?connecting?to?Redis?on?localhost:6379?(ECONNREFUSED)”問題,因為redis服務沒有安裝,安裝見之前步驟介紹。
接下來執行初始化操作:
sudo?-u?git?-H?bundle?exec?rake?gitlab:setup?RAILS_ENV=production
如果看到如下信息:
Administrator?account?created:
?
login.........admin@local.host
password......5iveL!fe
表示已經成功安裝gitLab了,記下管理員的用戶名和密碼。
7?啟動?gitlab
接下來執行下列命令啟動gitlab:
[git@h79?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
[2014-11-13?21:15:30]?INFO??WEBrick?1.3.1
[2014-11-13?21:15:30]?INFO??ruby?2.0.0?(2013-11-22)?[x86_64-linux]
[2014-11-13?21:15:30]?INFO??WEBrick::HTTPServer#start:?pid=20972?port=3000
表示gitlab啟動成功,可以通過http://{gitlab的域名或IP}:3000訪問gitlab。第一訪問會比較慢,因為要編譯很多js和css。
另外3000端口可能受防火墻影響,關閉防火墻?chkconfig?iptables?off(重啟后永久性生效)service?iptables?stop(及時生效,重啟后失效)。
登陸頁面如下所示:
輸入管理用戶名和密碼后,登錄進去的頁面如下所示:
- 分類:gitlab
- 字數:1576
- 標簽: gitlab安裝 gitlab部署
- 點贊 (1)
- 收藏 (26)
- 分享
- 粉絲: 5 博客數: 40 共碼了 34979 字
總結
- 上一篇: centos 6.5安装GitLab全过
- 下一篇: Bundler 的作用及原理