centos 6.5安裝GitLab全過程和問題記錄

來源:互聯網
上載者:User

標籤:

GitLab,是一個使用 Ruby on Rails 開發的開源應用程式,與Github類似,能夠瀏覽原始碼,管理缺陷和注釋,非常適合在團隊內部使用。

官方只提供了Debian/Ubuntu系統下的安裝說明文檔,如果需要在centos下安裝,可以參考這篇:https://github.com/gitlabhq/gitlab-recipes/tree/master/install/centos,筆者依照這篇文章的說明,成功的在centos系統上安裝了gitlab,分享一下自己的安裝過程和碰到的問題。

安裝的英文文檔:centos-6-5-install-gitlab.zip

 

開始之前

在開始之前請先查看官方的剛需文檔: https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/requirements.md ,該文檔說明了系統,軟體和硬體等各方面的需求。詳細的瞭解這些,可以避免碰到很多怪異的問題。

安裝步驟總覽

  • 基礎作業系統(CentOS 6.4 Minimal,升級後為6.5)
  • Ruby (版本: 2.0.0p353)
  • 建立項目運行使用者(建立git帳號,方便許可權管理)
  • GitLab Shell(版本:1.8.0)
  • 資料庫(可以支援mysql和PostgreSQL,這裡使用mysql,版本:5.1.17)
  • GitLab(版本:6.3.1)
  • Web伺服器(可支援nginx和apache,這裡使用nginx,版本:1.0.15)
  • 防火牆(iptables)

1、安裝作業系統

這個比較簡單,安裝完成之後記的配置下網路,使其可以在啟動時自動連接。而後需要升級系統和安裝一些相應的軟體和依賴包,以下逐一說明。

Tips:如果不能串連國外的網路,經常出現網路錯誤或者couldn’t not resolve host這樣的錯誤,建議修改dns伺服器為8.8.8.8和8.8.4.4。

a、升級作業系統和安裝wget

$ sudo yum -y update$ sudo yum -y install wget

升級完成後,系統版本是6.5。

筆者註:和英文文檔不同,筆者這裡是先升級系統和安裝wget,不然後面的操作會提示wget命令找到。

b、增加EPEL安裝源

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

下載並安裝GPG key

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

檢驗下是否安裝成功

$ sudo rpm -qa gpg*

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

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

提示:不要在意x86_64,在i686的機器上一樣能使用。

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 - $basearchmirrorlist=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch/mirrorlist#baseurl=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearchgpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puias

下載並安裝GPG key

$ sudo wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-puias http://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias$ sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-puias

檢驗下是否安裝成功

$ sudo rpm -qa gpg*

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

$ sudo yum repolist

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

$ su -$ 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使其在開機時啟動:

$ sudo chkconfig redis on$ sudo service redis start

f、配置郵件伺服器

筆者註:這個過程筆者沒有配置,請參考英文文檔。

2、安裝Ruby

下載並編譯:

$ su -$ 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$ ruby -vruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]

安裝bundle:

$ sudo gem install bundler --no-ri --no-rdoc

如果提示sudo: gem: command not found,使用root帳號登入執行該命令即可。

3、系統使用者

建立使用者git

$ su -$ adduser --system --shell /bin/bash --comment ‘GitLab‘ --create-home --home-dir /home/git/ git

因為git使用者不需要登入,所以這裡不需要設定git的密碼。

轉寄所有郵件

筆者註:因為上面沒有配置發送郵件,這裡也省略。

4、配置GitLab shell

GitLab shell是專門為GitLab開發的提供ssh訪問和版本管理的軟體。

先使用root登入,而後切換成git

$ su -$ 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,關於PostgreSQL的安裝請參考原文檔。

安裝mysql並設定開機啟動:

$ su -$ yum install -y mysql-server mysql-devel$ chkconfig mysqld on$ service mysqld start

設定mysql root帳號的密碼:

$ /usr/bin/mysql_secure_installation

建立新使用者和資料庫給gitlab使用

# 登入資料庫$ mysql -u root -p# 輸入root密碼# 為gitlab建立使用使用者CREATE USER ‘gitlab‘@‘localhost‘ IDENTIFIED BY ‘gitlab帳號的密碼‘;# 建立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 -$ 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# 修改設定檔中的訪問網域名稱(your_domain_name為項目的訪問網域名稱)$ sed -i ‘s|localhost|your_domain_name|g‘ config/gitlab.yml# 設定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# 編輯unicorn配置(筆者這裡採用預設配置)$ vim config/unicorn.rb# 配置git的使用者和郵件$ git config --global user.name "GitLab"$ git config --global user.email "[email protected]_domain_name"$ 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: "gitlab"  # 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包

$ cd /home/git/gitlab/$ bundle install --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、安裝啟動指令碼

$ su -$ wget -O /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/init/sysvinit/centos/gitlab-unicorn$ chmod +x /etc/init.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和GitLab Shell的版本和其他資訊。

啟動GitLab執行個體

$ service gitlab start

h、查看應用更加詳細的資訊

$ su - git$ cd gitlab/$ bundle exec rake gitlab:check RAILS_ENV=production

這裡會提示一個Init script up-to-date的錯誤,如下:

Init script up-to-date? ... noTry fixing it:Redownload the init scriptFor more information see:doc/install/installation.md in section "Install Init Script"Please fix the error above and rerun the checks.

原文說明不用介意這個問題。

7、安裝web伺服器

筆者選擇的是nginx,關於apache方面的請參考原文檔

$ su -$ yum -y install nginx$ chkconfig nginx on$ mkdir /etc/nginx/sites-available$ mkdir /etc/nginx/sites-enabled$ wget -O /etc/nginx/sites-available/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/web-server/nginx/gitlab-ssl$ ln -sf /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab

編輯/etc/nginx/nginx.conf,將 include /etc/nginx/conf.d/*.conf; 替換成 include /etc/nginx/sites-enabled/*;,就是修改額外載入的設定檔目錄。

編輯/etc/nginx/sites-available/gitlab,將配置中server_name替換成實際訪問的網域名稱。

將nginx加入git使用者組

$ usermod -a -G git nginx$ chmod g+rx /home/git/

添加ssl認證或者自己產生一個

$ cd /etc/nginx$ openssl req -new -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key

啟動nginx

$ service nginx start

8、配置防火牆

配置iptables,使使用者可以訪問http、https和ssh的連接埠。

$ lokkit -s http -s https -s ssh

重新啟動防火牆

$ service iptables restart

至此就算安裝完成了。預設的帳號密碼:

[email protected]5iveL!fe

問題記錄

a、網站不能添加使用者和建立項目問題?

查了下日誌,發現是許可權的問題:

Errno::EACCES (Permission denied – /home/git/gitlab/log/application.log):

修改使用者和所屬使用者組為git就可以了。

b、無法push?

在上面安裝GitLab shell步驟時,一開始筆者是將配置中的gitlab_url設定成http://test.gitlab.com/,結果在push的時候出錯了,後來查看GitLab項目日誌,才發現GitLab shell和GitLab通訊的時候產生了一個301跳轉。這點通過GitLab的nginx配置也能看的出來。後來將http替換成https,self_signed_cert設定成true就OK了。

總結

安裝的過程比較長,其中大部分時間花在了包的下載上。筆者以前沒有接觸過ruby,安裝的過程中也瞭解了下Ruby、Gem、Bundle等軟體,受益匪淺。一般來講,照著上面的步驟安裝,如果系統,軟體等版本都一致的話,應該能成功安裝。如果出現問題,可以多查查日誌。GitLab項目的日誌在該項目的log目錄內。GitLab shell的日誌在GitLab shell項目中的gitlab-shell.log

感謝

在安裝的過程中多虧了朋友雷志偉的幫忙,少走了不少彎路。此外他現在正在漢化GitLab,英文不好的朋友有福了,有興趣的朋友也可以參與進來,也可以直接使用已經漢化好的檔案,地址:http://git.oschina.net/linxuix/Git-Lab-Zh。

 

centos 6.5安裝GitLab全過程和問題記錄

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.