CentOS 6 上安装 gitlab
Page content
安装系统依赖
# yum -y groupinstall 'Development Tools' 'Additional Development'
# yum -y install 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
安装ruby
# curl -O http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.gz
# tar xzvf ruby-1.9.3-p0.tar.gz
# cd ruby-1.9.3-p0
# ./configure --disable-install-doc
由于安装文档非常慢,这里禁止安装文档。 可选配置:
# ./configure --disable-install-doc --enable-shared --disable-pthread
编译安装:
# ./configure --disable-install-doc
编译前,如果可以的话,可以选择安装qt
# yum install qt-devel qtwebkit-devel
# export PATH=$PATH:/usr/lib64/qt4/bin
更新gem & 安装rails
新版ruby已经自带gem了,如果版本太低,可以更新下:
# gem update --system
# gem update
# gem install rails
安装gitolite
创建git & gitlab用户 同时加入同组
# adduser --system --shell /bin/bash --comment 'gitolite' --create-home --home-dir /home/git git
# adduser --shell /bin/bash --create-home --home-dir /home/gitlab gitlab
# usermod -a -G git gitlab
# usermod -a -G gitlab git
# sudo -H -u gitlab ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa
# cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub
# chmod 0444 /home/git/gitlab.pub
fork源码,并安装
sudo -H -u git git clone -b gl-v304 https://github.com/gitlabhq/gitolite.git /home/git/gitolite
以下操作在git用户下进行
# su git
$ cd /home/git
$ git clone -b gl-v304 https://github.com/gitlabhq/gitolite.git /home/git/gitolite
$ mkdir bin
$ gitolite/install -ln /home/git/bin
$ bin/gitolite setup -pk /home/git/gitlab.pub
修正权限
# chmod -R g+rwX /home/git/repositories/
# chown -R git:git /home/git/repositories/
# chmod 750 /home/git
770铁定不行啊!!!!害我一直错误!!! 最后权限可以是750!!!
检测权限是否生效
# sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin
如果没有错误,删除clone下来的临时文件
# rm -rf /tmp/gitolite-admin
安装 pygments与bundle
在rhel以及centos下需要解决pygments问题
# curl http://python-distribute.org/distribute_setup.py | python
# easy_install pip
# pip install pygments
# gem install bundler
安装补充依赖
# gem install ruby-debug19
# gem install charlock_holmes
安装gitlabhq
下载gitlabhq:
# su gitlab
$ cd /home/gitlab
$ git clone -b stable https://github.com/gitlabhq/gitlabhq.git gitlab
修改配置
$ cd /home/gitlab/gitlab/config
$ cp gitlab.yml.example gitlab.yml
$ cp database.yml.mysql database.yml
$ cp unicorn.rb.example unicorn.rb
注意修改三个配置文件里面的相关参数
现在安装一些依赖
# cd /home/gitlab/gitlab
# sudo -u gitlab -H bundle install --without development test sqlite postgres --deployment
配置gitlab的git用户信息
# sudo -u gitlab -H git config --global user.email "gitlab@localhost"
# sudo -u gitlab -H git config --global user.name "Gitlab"
安装、初始化程序
# sudo gitlab
$ cd /home/gitlab/gitlab
$ RAILS_ENV=production rake db:setup
$ RAILS_ENV=production rake db:seed_fu
运行&大功告成
$ bundle exec rails s -e production
如果要后台运行
$ nohup bundle exec rails s -e production > /home/gitlab/gitlab.log 2>&1 &
访问地址:
http://127.0.0.1:3000
默认的管理员和密码
user: admin@local.host
pass: 5iveL!fe
nginx配置
从gitlabhq下载nginx的配置脚本:https://github.com/gitlabhq/gitlab-recipes/blob/master/nginx/gitlab
需要注意的是nginx的启动用户(nginx.conf)必须修改为gitlab
#user nginx;
user gitlab root;
启动脚本
从gitlabhq下载启动脚本:https://github.com/gitlabhq/gitlab-recipes/blob/master/init.d/gitlab-centos
根据需要修改其中的参数,通常默认参数就能工作很好。
将脚本放在/etc/init.d中,然后加入自动启动列表:
# chkconfig --add gitlab
# chkconfig --levels 2345 gitlab on
# chkconfig --list|grep gitlab
最后的最后运行下列命令启动即可:
# service gitlabhq start
或者
# /etc/init.d/gitlab start