GitLab,是一個使用 Ruby on Rails 開發的開源應用程序,與Github相似,可以瀏覽源代碼,管理缺陷和註釋,很是適合在團隊內部使用。html
安裝步驟node
n升級系統並及關閉selinux和iptablespython
n安裝Rubymysql
n建立項目運行用戶(建立git帳號,方便權限管理)linux
nGitLab Shellnginx
n數據庫(能夠支持mysql和PostgreSQL,這裏使用mysql)c++
nGitLab(版本:6.3.1)git
nWeb服務器(可支持nginx和apache,這裏使用nginx)github
# vi /etc/selinux/config # 設置SELINUX=disabled
# setup #將Firewall 選項取消
# 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
檢驗下是否安裝成功
# rpm -qa gpg*
安裝epel-release-6-8.noarch包
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
建立/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-puias http://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-pui
檢測源
# yum repolist
# 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
# chkconfig redis on
# service redis start
# 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
安裝bundle
# gem install bundler --no-ri --no-rdoc
# adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git
克隆gitlab shell
# su - git
$ git clone https://github.com/gitlabhq/gitlab-shell.git
$ cd gitlab-shell
$ git checkout v1.8.0 #切換版本
$ cp config.yml.example config.yml
$ vi config.yml
gitlab_url修改爲gitlab的訪問域名。形如:http://test.gitlab.com/
若是gitlab是使用https訪問,則需將http替換成https,配置文件中的self_signed_cert要修改爲true,不然會出錯。
安裝
$ ./bin/install
$ su -
$ yum install -y mysql-server mysql-devel
$ chkconfig mysqld on
$ service mysqld start
設置mysql root帳號的密碼
/usr/bin/mysql_secure_installation
建立新用戶和數據庫給gitlab使用
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab帳號的密碼';
# 建立gitlaba使用的數據庫
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
# 給予gitlab用戶權限
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
$ su - git
$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab
$ cd /home/git/gitlab
$ git checkout 6-3-stable
# 複製配置文件
$ 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 "gitlab@your_domain_name"
$ git config --global core.autocrlf input
$ 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就能夠了
確保該文件只有git帳號有權限讀取
$ chmod o-rwx config/database.yml
因爲國外gem源訪問很是慢,建議更換國內gem源。
# vi Gemfile
編輯Gemfile文件,將gem源更換爲ruby.taobao.org
#source"https://rubygems.org"
sourcehttp://ruby.taobao.org
修改Gemfile文件,將gem "modernizr", "2.6.2"修改成gem"modernizr-rails", "2.7.1"。
修改Gemfile.lock文件,將modernizr (2.6.2)修改成modernizr-rails (2.7.1)。
不然沒法正確安裝。
# gem install charlock_holmes --version '0.6.9.4'
$ cd /home/git/gitlab/
$ bundle install --deployment --without development test postgres puma aws
$ cd /home/git/gitlab
$ bundle exec rake gitlab:setup RAILS_ENV=production
$ bundle exec rake assets:precompile RAILS_ENV=production
這步完成後,會生一個默認的管理員帳號:
admin@local.host
5iveL!fe
$ 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
$ su - git
$ cd gitlab/
$ bundle exec rake gitlab:env:info RAILS_ENV=production
$ exit
能夠查看到系統、Ruby、GitLab和GitLab Shell的版本和其餘信息。
啓動GitLab實例
$ service gitlab start
查看應用更加詳細的信息
$ su - git
$ cd gitlab/
$ bundle exec rake gitlab:check RAILS_ENV=production
$ 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
登陸
Gitlab
以下圖所示:
詳情請查看官網:https://www.gitlab.com/downloads/
啓動gitlab
# /opt/gitlab/bin/gitlab-ctl start
ok: run: nginx: (pid 2505) 0s
ok: run: postgresql: (pid 2509) 1s
ok: run: redis: (pid 2518) 0s
ok: run: sidekiq: (pid 2523) 1s
ok: run: unicorn: (pid 2528) 0s
參考文檔
http://www.01happy.com/centos-6-5-install-gitlab/
http://www.it165.net/os/html/201405/8123.html