在 CentOS 上部署 GitLab (自托管的Git项目仓库)

在 CentOS 上部署 GitLab (自托管的Git项目仓库)


参考资料
https://github.com/mattias-ohlsson/gitlab-installer/blob/master/gitlab-install-el6.shhtml

环境准备
OS: CentOS 6.3 x86_64node

1.初识GitLab
GitLab是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可经过Web界面进行访问公开的或者私人项目。
它拥有与Github相似的功能,可以浏览源代码,管理缺陷和注释。能够管理团队对仓库的访问,它很是易于浏览提交过的版本并提供一个文件历史库。团队成员能够利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片断收集功能能够轻松实现代码复用,便于往后有须要的时候进行查找。 mysql

GitLab 要求服务器端采用 Gitolite 搭建,5.0版本之后对于ssh服务,GitLab再也不使用 Gitolite ,采用本身开发的 gitlab-shell 来实现。linux

在GitHub上托管代码,私人项目是须要付费的,而且对于企业而言,仍是将Git服务器放在内部要更加安全一些。所以,若是喜欢GitHub这种简洁风格的Git服务器,在本地搭建一个GitLab是一个很是不错的选择。
另外,若是须要对代码进行Review,推荐使用Gerrit,要复杂一些,可是功能很是强大。c++

2.安装部署GitLab
2.1 若是有条件,提供一台全新的Server,仅仅只安装了一些系统的软件包,能够直接使用一键安装的脚原本搭建,很是容易,具体步骤以下:git

2.1.1 安装EPEL扩展源
切换到root用户
$ sudo -i
# rpm -ivh http://fr2.rpmfind.net/linux/epel/6/x86_64/epel-release-6-8.noarch.rpmgithub

2.1.2 安装git
# yum install gitredis

2.1.3 下载gitlab-installer.sh安装脚本
# git clone https://github.com/mattias-ohlsson/gitlab-installer.gitsql

2.1.4 执行安装脚本
# cd gitlab-installer/
# ./gitlab-install-el6.shshell

等待脚本执行完毕后,会提示以下信息(好比Server主机名为:heydevops-node-2):

### Done ########################################
#
# You have your MySQL root password in this file:
# /config/database.yml
#
# Point your browser to:
http://heydevops-node-2 (or: http://[host-ip])
# Default admin username: admin@local.host
# Default admin password: 5iveL!fe
#
#################################################

2.1.5 将脚本的Ruby版本指向到ruby-1.9.3-p392
# vim /home/git/gitlab-shell/bin/gitlab-shell

#!/usr/local/rvm/bin/ruby-1.9.3-p392

2.1.6 使用GitLab
接着,就能够经过 http://[host-ip] ([host-ip]是Server的IP)来访问GitHub了。
首先,会看到以下所示的登录界面:

经过上面提示信息内的帐号密码登录,登录事后首先新增一个Project:

添加Project事后,会有一个配置向导,提供了很是详细的本地Git配置步骤:

在进行这些本地配置以前,首先要在本地生成SSH-Keygen,并将Public Key添加到GitLab中:

# ssh-keygen -t rsa
# cat .ssh/id_rsa.pub

而后将所查看到的信息,都添加到GitLab的 MyProfile - SSH Key - Add New 中:

接着,就能够再本地按照图片中所示的步骤进行操做并使用GitLab了。

2.2 上面的部署步骤,主要是采用了脚本gitlab-install-el6.sh来实现的,里面其实包含了不少的配置步骤,若是本地不是一个全新的环境,那么咱们最好按照如下步骤来进行手动配置:

2.2.1 安装EPEL扩展源
切换到root用户
$ sudo -i

# rpm -ivh http://fr2.rpmfind.net/linux/epel/6/x86_64/epel-release-6-8.noarch.rpm

2.2.2 安装git
# yum install git

2.2.3 安装系统依赖
# yum -y install patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make autoconf automake libtool bison libxml2-devel libxslt-devel libyaml-devel

2.2.4 安装rvm
# curl -L get.rvm.io | sudo bash -s stable

# source /etc/profile.d/rvm.sh
# rvm pkg install libyaml
# rvm use 1.9.3-p392
# gem install bundler

2.2.5 建立git用户
# adduser --system --create-home --comment 'GitLab' git

2.2.6 配置gitlab-shell(好比Server主机名为:heydevops-node-2)
# su - git -c "git clone https://github.com/gitlabhq/gitlab-shell.git"
# su - git -c "cp gitlab-shell/config.yml.example gitlab-shell/config.yml"
# sed -i "s/localhost/heydevops-node-2/g" /home/git/gitlab-shell/config.yml

# su - git -c "rvm use 1.9.3-p392;gitlab-shell/bin/install"

# chmod 600 /home/git/.ssh/authorized_keys
# chmod 700 /home/git/.ssh

2.2.7 安装Redis
# yum -y install redis
# service redis start
# chkconfig redis on

2.2.8 安装配置MySQL
# yum install -y mysql-server
# chkconfig mysqld on

# echo "CREATE DATABASE IF NOT EXISTS gitlabhq_production DEFAULT CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';" | mysql -u root
# echo "UPDATE mysql.user SET Password=PASSWORD('gitlab') WHERE User='root'; FLUSH PRIVILEGES;" | mysql -u root

2.2.9 安装配置GitLab
# su - git -c "git clone https://github.com/gitlabhq/gitlabhq.git gitlab"
# su - git -c "cd gitlab;git checkout 5-0-stable"

# cd /home/git/gitlab
# su git -c "cp config/gitlab.yml.example config/gitlab.yml"
# sed -i "s/ host: localhost/ host: heydevops-node-2/g" config/gitlab.yml
# sed -i "s/from: gitlab@localhost/from: gitlab@heydevops-node-2/g" config/gitlab.yml

2.2.10 建立Unicorn配置文件
# su git -c "cp config/unicorn.rb.example config/unicorn.rb"

# sed -i "s/^listen/#listen/g" /home/git/gitlab/config/unicorn.rb
# sed -i "s/#listen \"127.0.0.1:8080\"/listen \"127.0.0.1:3000\"/g" /home/git/gitlab/config/unicorn.rb

# su git -c "cp config/database.yml.mysql config/database.yml"
# sed -i "s/secure password/gitlab/g" config/database.yml

2.2.10 安装Gems
# yum -y install libicu-devel
# gem install charlock_holmes --version '0.6.9'

# yum -y install mysql-devel
# su git -c "bundle install --deployment --without development test postgres"

# su git -c "bundle exec rake gitlab:setup RAILS_ENV=production"

# curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab-centos
# chmod +x /etc/init.d/gitlab

# sed -i "17 a source /etc/profile.d/rvm.sh\nrvm use 1.9.3-p392" /etc/init.d/gitlab

# chkconfig gitlab on
# service gitlab start

2.2.11 安装Apache
# yum -y install httpd
# chkconfig httpd on

# vim /etc/httpd/conf.d/gitlab.conf

ProxyPass / http://127.0.0.1:3000/
ProxyPa***everse / http://127.0.0.1:3000/
ProxyPreserveHost On

# setenforce 0

# service httpd start

2.2.12 中止iptables
# service iptables stop

2.2.13 修复gitlab-shell
# vim /home/git/gitlab-shell/bin/gitlab-shell
将脚本的Ruby版本指向到ruby-1.9.3-p392

#!/usr/local/rvm/bin/ruby-1.9.3-p392

2.2.14 完成,剩下的GitLab使用步骤与2.1.6相同。

相关文章
相关标签/搜索