> CentOS > CentOS教程 >

centos 6中安装gitlab方法

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


因为项目中要求系统为ubuntu ,公司的服务器系统为Centos,所以安装方法有些不同。
 总的分为下面几个步骤
 安装依赖包
 创建系统账户
 安装Ruby
安装Gitlab shell
搭建数据库环境
 安装GitLab
搭建Nginx



 1.安装依赖包
 首先需要添加Epel源
[root@localhost~]rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
然后安装依赖包
[root@localhost~] yum -y groupinstall 'Development Tools' 'Additional Development' 
 [root@localhost~] yum -y install readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc gitolite 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 
启动redis server数据库库服务
[root@localhost~]service redis start


将服务添加到启动项
[root@localhost~]chkconfig --levels 2345 redis on
创建系统帐户
[root@localhost~] mkdir -p /data/apps/
 [root@localhost~] adduser sa_gitlab --home-dir=/data/apps/sa_gitlab
 [root@localhost~] passwd sa_gitlab
切换到sa_gitlab用户,创建私有key
 [root@localhost~] su - sa_gitlab
 [sa_gitlab@localhost~] mkdir -p /data/apps/sa_gitlab/.ssh
 [sa_gitlab@localhost~] chmod -R 700 /data/apps/sa_gitlab/.ssh
 [sa_gitlab@localhost~] echo "" > /data/apps/sa_gitlab/.ssh/authorized_keys
 [sa_gitlab@localhost~] chmod -R 600 /data/apps/sa_gitlab/.ssh/authorized_keys
  [sa_gitlab@localhost~] ssh-keygen -q -N '' -t rsa -f /data/apps/sa_gitlab/.ssh/id_rsa
 [sa_gitlab@localhost~] cat /data/apps/sa_gitlab/.ssh/id_rsa.pub >> /data/apps/sa_gitlab/.ssh/authorized_keys



安装ruby

 Centos 6系统中缺省的ruby版本过低,需要手动编译安装。
[sa_gitlab@localhost~] mkdir temp
 [sa_gitlab@localhost~] mkdir ruby
 [sa_gitlab@localhost~] cd temp
 [sa_gitlab@localhost~] wget -c "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz"
 [sa_gitlab@localhost~] tar -xf ruby-1.9.3-p392.tar.gz
 [sa_gitlab@localhost~] cd ruby-1.9.3-p392
 [sa_gitlab@localhost~] ./configure --prefix=/data/apps/sa_gitlab/ruby
 [sa_gitlab@localhost~] make
 [sa_gitlab@localhost~] make install



设置sa_gitlab用户变量
[sa_gitlab@localhost~] vim ~/.bash_profile




修改$PATH变量为


PATH=$HOME/ruby/bin:$PATH:$HOME/bin;
保存文件退出。
[sa_gitlab@localhost~] vim ~/.bashrc



添加$PATH变量路径
PATH=$HOME/ruby/bin:$PATH:$HOME/bin;

保存并关闭文件。


[sa_gitlab@localhost~] PATH=$HOME/ruby/bin:$PATH:$HOME/bin;


确认ruby路径与版本是否为最新


[sa_gitlab@localhost~] which ruby
 ~/ruby/bin/ruby
 [sa_gitlab@localhost~] ruby --version
 ruby 1.9.3p392 (2013-02-22) [x86_64-linux]



安装bundler
 [sa_gitlab@localhost~] gem install bundler




 4. 安装gitlab shell
 [sa_gitlab@localhost~] cd ~/
 [sa_gitlab@localhost~] mkdir gitlab-shell
 [sa_gitlab@localhost~] git clone https://github.com/gitlabhq/gitlab-shell.git gitlab-shell/ 
 Configure gitlab-shell and install it
 [sa_gitlab@localhost~] cd gitlab-shell/
 [sa_gitlab@localhost gitlab-shell] git checkout v1.2.0
 [sa_gitlab@localhost gitlab-shell] cp config.yml.example config.yml
 [sa_gitlab@localhost gitlab-shell] vim config.yml
修改文件中的变量值为下面的值
     user: sa_gitlab
     gitlab_url: "http://www.yourdomain.com/"
     repos_path: "/data/apps/sa_gitlab/repositories"
  auth_file: "/data/apps/sa_gitlab/.ssh/authorized_keys"
安装gitlab shell
 [sa_gitlab@localhost gitlab-shell]./bin/install





 5.搭建Mysql数据库环境

[root@localhost~]yum -y install mysql mysql-server mysql-devel
 [root@localhost~]service mysqld start
 [root@localhost~]mysql_secure_installation  设置用户密码
mysql-uroot-p
 # 创建用户密码
mysql>CREATEUSER'gitlab'@'localhost' IDENTIFIED BY 'gitlab';
 # 创建数据库gitlabhq_production
 mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
 # 设置用户gitlab访问数据库权限。
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
 # 退出mysql
 mysql>\q
安装gitlab
 [sa_gitlab@localhost~] cd ~/
 [sa_gitlab@localhost~] mkdir gitlab
 [sa_gitlab@localhost~] git clone https://github.com/gitlabhq/gitlabhq.git gitlab
 [sa_gitlab@localhost~] cd gitlab
 [sa_gitlab@localhost gitlab] git checkout 5-0-stable
编辑gitlab配置文件
[sa_gitlab@localhost~] cp config/gitlab.yml.example config/gitlab.yml
 [sa_gitlab@localhost~] vim config/gitlab.yml
修改文件中的变量
 host: git.yourdomain.com
  port: 80
  https: false
  user: sa_gitlab
  email_from: gitlab-noreply@git.yourdomain.com
  support_email: you@yourdomain.com
 path: /data/apps/sa_gitlab/gitlab-satellites/
 repos_path: /data/apps/sa_gitlab/repositories/
 hooks_path: /data/apps/sa_gitlab/gitlab-shell/hooks/
保存关闭文件。




 设置文件夹的访问权限

[sa_gitlab@localhost~] chown -R sa_gitlab log/
 [sa_gitlab@localhost~] chown -R sa_gitlab tmp/
 [sa_gitlab@localhost~] chmod -R u+rwX  log/
 [sa_gitlab@localhost~] chmod -R u+rwX  tmp/
创建satellites 文件夹并修改配置文件
[sa_gitlab@localhost~] mkdir /data/apps/sa_gitlab/gitlab-satellites/
 [sa_gitlab@localhost~] mkdir tmp/pids/
 [sa_gitlab@localhost~] chmod -R u+rwX  tmp/pids/
 [sa_gitlab@localhost~] cp config/unicorn.rb.example config/unicorn.rb
 [sa_gitlab@localhost~] vim config/unicorn.rb
编辑文件中的变量值
listen "127.0.0.1:65527"  # listen to port 8080 on the loopback interface


配置数据库连接文件
[sa_gitlab@localhost~] cp config/database.yml.mysql config/database.yml
将用户名密码修改为上面mysql配置中的用户密码
 安装gitlab依赖库charlocks_holmes
 [sa_gitlab@localhost~] cd ~/gitlab
 [sa_gitlab@localhost gitlab] gem install charlock_holmes --version '0.6.9'
 [sa_gitlab@localhost gitlab]  vi Gemfile

替换source "https://rubygems.org" 为 source "http://rubygems.org" 保存文件退出


[sa_gitlab@localhost gitlab] /data/apps/sa_gitlab/ruby/bin/bundle install --deployment --without development test postgres
 [sa_gitlab@localhost gitlab] /data/apps/sa_gitlab/ruby/bin/bundle exec rake gitlab:setup RAILS_ENV=production
 [sa_gitlab@localhost gitlab] /data/apps/sa_gitlab/ruby/bin/bundle exec rake db:seed_fu RAILS_ENV=production


下载gitlab启动脚本并修改配置

[root@localhost~] curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/5-0-stable/init.d/gitlab
 [root@localhost~] chmod +x /etc/init.d/gitlab
 [root@localhost~] vim /etc/init.d/gitlab
 APP_ROOT修改为 APP_ROOT="/data/apps/sa_gitlab/gitlab"

添加一行 APP_USER="sa_gitlab"

搜索与替换sudo -u git -H bash 为 sudo -u $APP_USER -H bash

保存启动脚本

 启动gitlab

 [root@localhost~] /etc/init.d/gitlab start
 [root@localhost~] /etc/init.d/gitlab status
 Gitlab service / Unicorn with PID 19988 is running.
 Gitlab service / Sidekiq with PID 20031 is running.

 [root@localhost~] chkconfig --add gitlab
 [root@localhost~] chkconfig --levels 345 gitlab on

切换用户与检查安装是否有错误

[root@localhost~] su - sa_gitlab
 [sa_gitlab@localhost~] cd gitlab
 [sa_gitlab@localhost~] git config --global user.name  "GitLab"
 [sa_gitlab@localhost~] git config --global user.email "gitlab-noreply@git.yourdomain.com"
 [sa_gitlab@localhost~] bundle exec rake gitlab:env:info RAILS_ENV=production
 # 检查错误
 [sa_gitlab@localhost~] bundle exec rake gitlab:check RAILS_ENV=production





 6. 安装nginx
 [root@localhost~] wget http://nginx.org/packages/centos/5/noarch/RPMS/nginx-release-centos-5-0.el5.ngx.noarch.rpm
 [root@localhost~] rpm -U nginx-release-centos-5-0.el5.ngx.noarch.rpm
 [root@localhost~] yum update
 [root@localhost~] yum install nginx
 # 下载nginx配置文件
curl --output /etc/nginx/conf.d/gitlab.conf https://raw.github.com/gitlabhq/gitlab-recipes/master/nginx/gitlab
 vim /etc/nginx/conf.d/gitlab.conf
修改变量YOUR_SERVER_IP 为你的服务器IP 地址
proxy_pass http://gitlab; 修改为proxy_pass http://IP:65527;
保存文件,重启nginx
访问http://IP 即可使用gitlab 系统
Gitlab系统中初始用户为 admin@local.host  密码为 5iveL!fe

(责任编辑:IT)