CentOS上安裝GitLab

來源:互聯網
上載者:User

標籤:gitlab   centos   git   

description: 之前在公司因為工作需要,需要搭建一個基於的git的專案管理平台,最好能夠比較貼近GitHub的管理方式,從網上找到了GitLab這個開源項目,無論是從介面上還是從功能上都還不錯,結果公司的伺服器是win的…

之前在公司因為工作需要,需要搭建一個基於的git的專案管理平台,最好能夠比較貼近GitHub的管理方式,從網上找到了GitLab這個開源項目,無論是從介面上還是從功能上都還不錯,結果公司的伺服器是win的…就在自己的VPS上搭建了,我的伺服器系統版本是Ubuntu 10.04 lts的,很方便地就升級到了12.04 lts,現在的Ubuntu確實很好用,感覺各方面做的都好了很多。不過按照官方的文檔搭建GitLab的時候還是遇到了一些問題,主要涉及到的都是軟體版本、檔案許可權等比較蛋疼的配置問題,當然這也和我自己沒怎麼做過後台有關。這次是在項目組的伺服器上搭建GitLab,伺服器的系統版本是CentOS,安裝的過程和Ubuntu大同小異,這裡本著補充後台知識的角度寫這篇教程,也希望給別人帶來方便(Ubuntu的就直接參照官方的吧,官方有個CentOS的一鍵安裝指令碼,不過你要是敢用就用吧)。

安裝EPEL和依賴庫

首先安裝第三方的軟體庫EPEL和編譯的依賴庫,EPEL直接安裝RPM包就可以了。

¥ rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm$ yum -y update$ yum -y install gcc gcc-c++ make autoconf libyaml-devel gdbm-devel ncurses-devel openssl-devel zlib-devel readline-devel curl-devel expat-devel gettext-devel  tk-devel libxml2-devel libffi-devel libxslt-devel libicu-devel sendmail patch libyaml* pcre-devel sqlite-devel vim
Python2.7+
$ mkdir /tmp/gitlab && cd /tmp/gitlab$ curl --progress http://python.org/ftp/python/2.7.5/Python-2.7.5.tgz | tar xvf$ cd Python-2.7.5$ ./configure --prefix=/usr/local$ make && make install

安裝好了以後需要注意的就是使用ln命令來建立串連,這樣系統預設的PATH定址的時候就能找到最新的版本(預設路徑/usr/local/bin)。

$ sudo ln -s /usr/local/bin/python2.7 /usr/local/bin/python
Ruby2.0
$ cd /tmp/gitlab$ curl --progress http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz | tar xz$ cd ruby-2.0.0-p247$ ./configure$ make$ make install

ruby2.0已經內建了gem(管理Ruby庫和程式的標準包),所以只需要安裝bundler(影像處理的一個源碼庫,這個不知道是幹嘛用的)。

$ gem install bundler

如果你出現了Network Connected Error之類的網路問題(你懂得),rubygems.org存放在Amazon S3上的資源檔會間歇性地串連失敗,(http://ruby.taobao.org/) 這個鏡像源還是挺不錯的,把GemFile中的地址修改為這個即可,然後繼續添加串連。

$ ln -s /usr/local/bin/ruby /usr/bin/ruby$ ln -s /usr/local/bin/gem /usr/bin/gem$ ln -s /usr/local/bin/bundle /usr/bin/bundle
Git和Gitolite

如果系統的已經安裝Git,一定要保證版本大於1.7.10,GitHub和許多Git服務依賴的git版本都不能低於這個版本,但是CentOS 6.4預設的epel安裝的版本偏偏是低於這個版本的,這裡可以通過rpmforge源(和EPEL一樣也是個第三方YUM源)的二進位包來更新。

// 安裝rpmforge源$ wget ‘http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm‘$ rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt$ rpm -i ‘http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm‘$ yum clean all// change the enabled=0 flag to enabled=1 in the section labelled [rpmforge-extras].$ cd /etc/yum.repos.d$ vim (or whatever) rpmforge.repo// 安裝新版本Git$ yum  update$ yum provides git$ yum install git-1.7.11.3-1.el6.rfx.x86_64$ yum -y install git-all gitolite
MySql和Redis

GitLab支援MySQL和PostgreSQL,而且還必須安裝Redis(有點悔恨當年資料庫的課沒好好學,然後現在有時還得自學)。

$ yum -y install mysql mysql-devel mysql-server redis$ service mysqld start$ mysql -u root$ mysql> CREATE USER ‘gitlab‘@‘localhost‘ IDENTIFIED BY ‘gitlab‘;$ mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;$ mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO ‘gitlab‘@‘localhost‘;$ mysql> \q$ service redis start
Nginx

GtiLab當然也支援Apache,但畢竟Nginx的效能要好太多了(據相關測試,高並發串連的情況下,Nginx的效能能勝過10倍的Apache)。

$ yum -y install nginx $ service nginx start

至此,主要的軟體包都已經安裝完畢,下面就要進行配置了。

GitLab Uesr
$ useradd -c ‘GitLab‘ git$ passwd -l git$ su git

後面就直接切換到git賬戶下操作,可以省去檔案許可權的一些問題,如果還是出出現了Permission的一些問題,直接使用chown命令進行修改就可以了。

GitLab Shell
$ cd /home/git$ git clone https://github.com/gitlabhq/gitlab-shell.git$ cd gitlab-shell

通過git tag來查看最新的版本並切換

$ git checkout v1.7.9

修改設定檔,添加自己domain後安裝即可。

$ vi config.yml$ ./bin/install
GitLab
$ cd /home/git$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab$ cd /home/git/gitlab$ git checkout 6-3-stable$ cd /home/git/gitlab$ cp config.yml{.example,}$ vi config/gitlab.yml$ mkdir tmp/pids/$ mkdir tmp/sockets/$ chown -R git log/$ chown -R git tmp/$ chmod -R u+rwX log/$ chmod -R u+rwX tmp/$ chmod -R u+rwX tmp/pids/$ chmod -R u+rwX tmp/sockets/

建立satellites目錄,儲存各個使用者的倉庫。

$ mkdir /home/git/gitlab-satellites$ mkdir public/uploads$ chmod -R u+rwX  public/uploads

修改unicorn設定檔:

$ cd /home/git/gitlab$ cp config/unicorn.rb{.example,}$ vi config/unicorn.rb

設定git的全域配置參數:

$ git config --global user.name "GitLab"$ git config --global user.email "[email protected]"$ git config --global core.autocrlf input

設定GitLab的資料庫:

$ cp config/database.yml{.mysql,}$ vi config/database.yml$ chmod o-rwx config/database.yml

安裝相關Ruby Gems依賴包;

$ cd /home/git/gitlab$ [sudo] gem install charlock_holmes --version ‘0.6.9.4‘$ bundle install --deployment --without development test postgres aws// 初始化資料庫資料$ bundle exec rake gitlab:setup RAILS_ENV=production

設定init指令碼:

$ sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab$ sudo chmod +x /etc/init.d/gitlab
GitLab Check
$ bundle exec rake gitlab:env:info RAILS_ENV=production$ sudo service gitlab start$ bundle exec rake gitlab:check RAILS_ENV=production

一定要通過最後一項的check,注意切換到git賬戶進行check,特別是進行IP地址和連接埠修改的時候需要重新進行check。

配置Nginx

這裡需要注意的是Ubuntu下預設的下載的Nginx版本和CentOS是不同的,發行版不同配置結構是有一定差異的。

$ mkdir -p /etc/nginx/sites-available/$ mkdir -p /etc/nginx/sites-enabled/$ cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab$ ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab

在載入設定檔的時候,確定nginx.conf索引的設定檔在哪個目錄,包括如果你想修改連接埠的話(nginx和apaache的80連接埠衝突了)也是要注意Nginx發布載入的設定檔是監聽哪個連接埠的。我所使用的Nginx的版本是1.0.15,修改了default.conf連接埠監聽和nginx.conf來載入自己的設定檔。

$ http {$ …$ # Load config files from the /etc/nginx/conf.d directory$ # The default server is in conf.d/default.conf$ include /etc/nginx/conf.d/*.conf;$ include /etc/nginx/sites-enabled/*;$ …$ }

重啟各項服務:

$ sudo service nginx restart$ sudo service gitlab restart

如果Nginx無法重啟,提示80連接埠佔用,說明的連接埠修改還是不正確的。

Done

現在訪問自己的domain就可以看到GitLab的登陸介面了,為了加快網域名稱解析的速度可以配置下hosts檔案。

$ echo "127.0.0.1 YOUR_DOMAIN" >> /etc/hosts

預設的使用者名稱和密碼:

[email protected]5iveL!fe
修改連接埠

修改HTTP伺服器unicorn的佔用連接埠:

$ vi /home/git/gitlab/config/unicorn.rb# listen "127.0.0.1:9292", :tcp_nopush => true

修改GitLab的發布連接埠:

$ vi /etc/nginx/sites-enabled/gitlab# listen *:888 default_server;$ vi /home/git/gitlab/config/gitlab.yml# port: 888$ vi /home/git/gitlab-shell/config.yml# gitlab_url: "http://mygitdomain.com:888"
添加SSL

假設我們準備好了伺服器的密鑰 server.key 和認證 server.crt 和根憑證 ca.crt (如何獲得認證參考 ssl認證產生 ), 且將這些檔案放在/etc/nginx/sites-available/下面。

# 將以下內容添加到 /etc/nginx/sites-available/gitlab 最後。# 替換 server_name 指定的網域名稱server {    listen *:443;    ssl                  on;    ssl_certificate      /etc/nginx/sites-available/server.crt;    ssl_certificate_key  /etc/nginx/sites-available/server.key;    server_name mygitdomain.com;    #ubuntu1204-dell source.cml.com;     # e.g., server_name source.example.com;    root /home/gitlab/gitlab/public;    # individual nginx logs for this gitlab vhost    access_log  /var/log/nginx/gitlab_ssl_access.log;    error_log   /var/log/nginx/gitlab_ssl_error.log;    location / {    # serve static files from defined root folder;.      # @gitlab is a named location for the upstream fallback, see below      try_files $uri $uri/index.html       $uri.html @gitlab;    }    # if a file, which is not found in the root folder is requested,    # then the proxy pass the request to the upsteam (gitlab unicorn)    location @gitlab {    proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694    proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694    proxy_redirect     off;    proxy_set_header   X-Forwarded-Proto $scheme;      proxy_set_header   Host              $http_host;      proxy_set_header   X-Real-IP         $remote_addr;    proxy_pass http://gitlab;  }}

CentOS上安裝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.