Centos下gitlab安装指南[原创]

最后一次更新时间:2013-05-29

https://github.com/gitlabhq/gitlabhq

gitlab 5.2.0
centos6.3 i686
Redis 2.6.13
nginx-1.4.1
mysql-5.5.31-linux2.6-i686.tar.gz

这里与官方的教程有些不一样,主要是一些软件如mysql nginx redis之类的以前是手动编译安装的.

网上也有提供一键安装包工具:http://bitnami.com/stack/gitlab

gitlab中文使用指南:GitLab使用介绍

首先我们选择比较快的yum源,不然安装速度会非常的慢的.这里使用中国科技大学的yum源http://lug.ustc.edu.cn/wiki/mirrors/help/centos更换yum源方法参考:http://blog.haohtml.com/archives/5669,

说明:
默认安装的git版本可能会低一些,需要升级到最新版本才可以.

1. Packages / Dependencies

yum -y install readline-devel gdbm-devel ncurses-devel openssl-devel zlib-devel gcc gcc-c++ make autoconf curl-devel expat-devel gettext-devel tk-devel libxml2-devel libffi-devel libxslt-devel libicu-devel git-all python-devel vim sudo

 

python2 --version

要求为3以下的python版本,但要高于2.5版本,如果版本过低,请升级Python版本.参考:http://blog.haohtml.com/archives/13959.这里我们使用 2.5.6版本的,测试的2.7版本好像也不支持的.换成2.5.6版本就正常了.
安装libyaml库

wget -c http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
tar xzvf yaml-0.1.4.tar.gz
cd yaml-0.1.4
./configure --prefix=/usr/local
make;make install
cd ../

2. Ruby
Remove old 1.8 ruby if present

#sudo apt-get remove ruby1.8
Download and compile it:

mkdir /tmp/ruby 
cd /tmp/ruby
curl --progress http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz | tar xz
cd ruby-1.9.3-p392
./configure
make
make install
cd ../

Install the Bundler Gem:

gem install bundler

3. System Users

Create a git user for Gitlab:

groupadd git
adduser git -g git

4. GitLab shell
GitLab Shell is a ssh access and repository management software developed specially for GitLab.

# Login as git

su git

# Go to home directory

cd /home/git

# Clone gitlab shell

git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell

# switch to right version

git checkout v1.4.0

 

cp config.yml.example config.yml

# Edit config and replace gitlab_url
# with something like 'http://domain.com/'

vim config.yml

# Do setup

./bin/install
cd ../

gitlab要使用redis-server软件,redis的安装参考:http://www.cnblogs.com/hb_cattle/archive/2011/10/22/2220907.html

5. Database
mysql安装教程参考 http://blog.haohtml.com/archives/12473
安装Mysql数据库,gitlab数据库配置:To setup the MySQL/PostgreSQL database and dependencies please see doc/install/databases.md.

6. GitLab
# We'll install GitLab into home directory of the user "git"

cd /home/git

Clone the Source

# Clone GitLab repository

sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab

# Go to gitlab dir

cd /home/git/gitlab

# Checkout to stable release

sudo -u git -H git checkout 5-2-stable

Note: You can change 5-2-stable to master if you want the bleeding edge version, but do so with caution!

Configure it

cd /home/git/gitlab

# Copy the example GitLab config

sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

# Make sure to change "localhost" to the fully-qualified domain name of your
# host serving GitLab where necessary

sudo -u git -H vim config/gitlab.yml

# Make sure GitLab can write to the log/ and tmp/ directories

sudo chown -R git log/<br />sudo chown -R git tmp/<br />sudo chmod -R u+rwX  log/<br />sudo chmod -R u+rwX  tmp/

# Create directory for satellites

sudo -u git -H mkdir /home/git/gitlab-satellites

# Create directories for sockets/pids and make sure GitLab can write to them

sudo -u git -H mkdir tmp/pids/<br />sudo -u git -H mkdir tmp/sockets/<br />sudo chmod -R u+rwX  tmp/pids/<br />sudo chmod -R u+rwX  tmp/sockets/

# Create public/uploads directory otherwise backup will fail

sudo -u git -H mkdir public/uploads<br />sudo chmod -R u+rwX  public/uploads

# Copy the example Puma config

sudo -u git -H cp config/puma.rb.example config/puma.rb

# Configure Git global settings for git user, useful when editing via web
# Edit user.email according to what is set in gitlab.yml

sudo -u git -H git config --global user.name "GitLab"<br />sudo -u git -H git config --global user.email "gitlab@localhost"

Important Note: Make sure to edit both gitlab.yml and puma.rb to match your setup.

Configure GitLab DB settings

# Mysql(我们使用mysql)

sudo -u git cp config/database.yml.mysql config/database.yml

# PostgreSQL(这里不使用这个数据库,所有不用执行)

sudo -u git cp config/database.yml.postgresql config/database.yml

Make sure to update username/password in config/database.yml.

Install Gems

su root<br />cd /home/git/gitlab<br />gem install charlock_holmes --version '0.6.9.4'

# For MySQL (note, the option says "without")

bundle install --deployment --without development test postgres

# Or for PostgreSQL

bundle install --deployment --without development test mysql

Initialize Database and Activate Advanced Features

bundle exec rake gitlab:setup RAILS_ENV=production

Install Init Script

Download the init script (will be /etc/init.d/gitlab):

cp lib/support/init.d/gitlab /etc/init.d/gitlab<br />chmod +x /etc/init.d/gitlab

Make GitLab start on boot:

chkconfig gitlab on

Check Application Status

Check if GitLab and its environment are configured correctly:

bundle exec rake gitlab:env:info RAILS_ENV=production

Start Your GitLab Instance

service gitlab start

# or

/etc/init.d/gitlab restart

启用服务时,如何提示:

bash: bundle: command not found
GitLab service started

错误信息,说明用户的环境变量不合适,先whereis bundle 命令查看出来bundle命令所在的位置,然后添加到 /etc/profile 里就可以了.
在export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL下面添加一行
export PATH=$PATH:/usr/local/bin
参考:http://blog.haohtml.com/archives/9765

Double-check Application Status

To make sure you didn't miss anything run a more thorough check with:

su git<br />bundle exec rake gitlab:check RAILS_ENV=production

If all items are green, then congratulations on successfully installing GitLab! However there are still a few steps left.

这里可能会提示git的版本过低的问题(上面的git-all),只需要重新安装一下git,参考:http://blog.haohtml.com/archives/10093 然后在配置文件config/gitlab.yml里git的bin_path路径就可以了, 这里我将git安装在/usr/local/目录里了.命令在 /usr/local/bin/git 位置,所以配置为(bin_path: /usr/local/bin/git).
可能还会提示需要执行一次下面的命令

bundle exec rake sidekiq:start RAILS_ENV=production

7. Nginx

Installation
Nginx安装教程可参考:http://blog.haohtml.com/archives/12473
Note: If you can't or don't want to use Nginx as your web server, have a look at the Advanced Setup Tips section.

Site Configuration

Download an example site config:

cd /home/git/gitlab<br />cp lib/support/nginx/gitlab /usr/local/nginx/conf/gitlab<br />vim /usr/local/nginx/conf/nginx.conf

在server段中添加 include gitlab; 一行

修改配置文件gitlab,注意日志路径

vim /usr/local/nginx/conf/gitlab

Make sure to edit the config file to match your setup:

# **YOUR_SERVER_FQDN** to the fully-qualified
# domain name of your host serving GitLab. Also, replace
# the 'listen' line with the following:
# listen 80 default_server; # e.g., listen 192.168.1.1:80;

测试nginx配置是否正确

/usr/local/nginx/sbin/nginx -t

重启Nginx

/usr/local/nginx/sbin/nginx -s reload

Done!
Visit YOUR_SERVER for your first GitLab login. The setup has created an admin account for you. You can use it to log in:

admin@local.host
5iveL!fe

Important Note: Please go over to your profile page and immediately change the password, so nobody can access your GitLab by using this login information later on.

注意关闭防火墙

service iptables stop

参考官方文档:https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md

注意nginx的运行用户权限问题.gitlab使用的是git:git用户,而nginx运行使用的www:www用户.这种情况会导致一些权限问题,可能会出现nginx 502错误,这里为了方便,要修改一下nginx的运行用户修改为 git,重启nginx就可以了.根据自己的自行设置权限.

One thought on “Centos下gitlab安装指南[原创]

  1. Pingback: centos5.1安装gitlabFred 学习小站

Comments are closed.