分享 在 CentOS6.4 上配置 GitLab5.4 服务

zenz · August 07, 2013 · Last by zenz replied at February 28, 2014 · 5320 hits

分享一下吧

安装 CentOS6.4 系统,选择 minimal 安装即可。设置好网卡之后重启再进系统,运行系统更新命令:

#yum update

添加 rpmforge 及 epel 源,以便获得更多的应用支持并更新系统。

#rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt #rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm #rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

编辑/etc/yum.repos.d/rpmforge.repo 文件,把里面关于 extra 段的 enabled 设为 1 后保存,为后续操作做准备。

安装 RVM

#curl -L https://get.rvm.io | bash -s stable

载入 RVM 环境并获取需要的支持安装包

#source /etc/profile.d/rvm.sh #rvm requirements

在执行下面的编译安装 Ruby 工作之前,先把源替换到别的源上上,这样速度会快很多,而且不用担心被墙。

切换到 ruby.taobao.org 的源 #sed -i 's!ftp.ruby-lang.org/pub/ruby!ruby.taobao.org/mirrors/ruby!' $rvm_path/config/db 也可以切换为 ibiblio.org 的源 #sed -i 's!ftp.ruby-lang.org/pub/ruby!mirrors.ibiblio.org/ruby!' $rvm_path/config/db

安装 ruby 1.9.3,并设为默认

#rvm install 1.9.3 #rvm use 1.9.3 --default

注意,在安装过程中的 install 之后可能会没有了反应,那是因为 GFW 把 rubygem 给封了,这个时候要自己手动 ctrl+c 中断,自己手动修改 gem 源:

#gem source -r http://rubygems.org/ #gem source -a http://ruby.taobao.org

修改/root/.gemrc,添加两行,以避免安装帮助文档(服务器上要来没有用)

install: --no-ri --no-rdoc update: --no-ri --no-rdoc

装 bundle 工具

#gem install bundler

安装配置 gitlab 需要用到的 mysql 数据库支持

#yum install mysql-server mysql-devel #/etc/rc.d/init.d/mysqld start #chkconfig mysqld on

配置 root 用户,设置密码访问限制。

#mysql -u root mysql set password for root@localhost=password('password'); set password for root@'127.0.0.1'=password('password'); set password for root@'your.domain.com'=password('password'); delete from mysql.user where user=''; exit;

添加 GitLab 需要用到的数据库及用户。

#mysql -u root -p create user gitlab@localhost identified by 'password'; create database if not exists gitlab_production default character set utf8 collate utf8_unicode_ci; grant select, lock tables, insert, update, delete, create, drop, index, alter on gitlab_production.* to gitlab@localhost; exit;

安装 git 工具

#yum install git

添加 gitlab 需要的用户

#adduser --system --create-home --comment 'GitLab' git

切换到 git 用户并进入用户目录,用 git 获取 gitlab-shell 最新源代码并安装

#su - git $cd $git clone https://github.com/gitlabhq/gitlab-shell.git $cd gitlab-shell $git checkout v1.5.0 $cp config.yml.example config.yml

编辑 config.yml,把里面的 gitlab_url: "http://localhost/"换成实际的地址,并执行

$./bin/install

返回 git 用户目录并获取 gitlab 源代码

$cd /home/git $git clone https://github.com/gitlabhq/gitlabhq.git gitlab $cd /home/git/gitlab $git checkout 5-4-stable

配置 gitlab

$cp config/gitlab.yml.example config/gitlab.yml

编辑 config/gitlab.yml 文件,把 localhost 都改成有效的实际域名

确保目录对 git 用户有效可读写

$chown -R git log/ $chown -R git tmp/ $chmod -R u+rwX log/ $chmod -R u+rwX tmp/ $mkdir tmp/pids/ $mkdir tmp/sockets/ $chmod -R u+rwX tmp/pids $chmod -R u+rwX tmp/sockets $mkdir public/uploads $chmod -R u+rwX public/uploads

建立 satellites 目录

$mkdir /home/git/gitlab-satellites

复制 puma.rb 文件

$cp config/puma.rb.example config/puma.rb

修改 puma.rb 把 threads 更改为 threads 8,16 把 workers 设为 4,把 daemonized true 注释掉。

设置 git 用户的信息,与上面 gitlab.yml 中修改的要一致。

$git config --global user.name "GitLab" $git config --global user.email "[email protected]"

复制并配置数据库配置文件,设置安全权限。

$cp config/database.yml.mysql config/database.yml $chmod o-rwx config/database.yml $vi config/database.yml

确认里面的 production 栏里的各个项目的配置跟 mysql 设置时一致

安装需要用到的应用包

$exit #yum install libxml2-devel libxslt-devel libicu-devel

安装 gems,我们这里需要修改 Gemfile,把 gem 源指向http://ruby.taobao.org ,然后执行

#su - git $cd gitlab $bundle install --path vendor/bundle --deployment --without development test postgres unicorn asw

安装并启动 redis 服务

$exit #yum install redis #service redis start #chkconfig redis on

数据库初始化并生成管理员账号,到提示的时候输入 yes

#su - git $cd gitlab $bundle exec rake gitlab:setup RAILS_ENV=production $exit

建立/etc/yum.repos.d/nginx.repo,内容如下:

[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/6/$basearch/ gpgcheck=0 enabled=1

安装 nginx,并把 nginx 用户添加到 git 组,修改/home/git 的读写权限

#yum install nginx #usermod -a -G git nginx #chmod 750 /home/git

建立/etc/init/gitlab-puma.conf 启动脚本

# /etc/init/gitlab-puma.conf - gitlab puma config

description "GitLab puma service"

# no "start on", we don't want to automatically start start on runlevel [2345] stop on runlevel [06]

# change apps to match your deployment user if you want to use this as a less privileged user (recommended!) #setuid www #setgid www # not compatible with CentOS

respawn respawn limit 3 30

script exec /bin/bash <<EOT export HOME=/home/git source /etc/profile.d/rvm.sh cd /home/git/gitlab su git -c "bundle exec puma -C config/puma.rb" EOT end script

建立/etc/init/gitlab-sidekiq.conf 启动脚本

# /etc/init/gitlab-sidekiq.conf - gitlab sidekiq config

description "GitLab sidekiq service"

start on runlevel [2345] stop on runlevel [06]

post-start script exec /bin/bash <<EOT export HOME=/home/git source /etc/profile.d/rvm.sh cd /home/git/gitlab su git -c "RAILS_ENV=production bundle exec rake sidekiq:start" EOT end script

post-stop script exec /bin/bash <<EOT export HOME=/home/git source /etc/profile.d/rvm.sh cd /home/git/gitlab su git -c "RAILS_ENV=production bundle exec rake sidekiq:stop" EOT end script

启动 gitlab-puma 和 gitlab-sidekiq

start gitlab-puma start gitlab-sidekiq

复制 nginx 启动脚本到/etc/nginx/conf.d

#cp /home/git/gitlab/lib/support/nginx/gitlab /etc/nginx/conf.d/gitlab.conf

修改 gitlab.conf 文件以满足 gitlab 的需要,主要是域名。另外,要修改/etc/nginx/nginx.conf 文件,把 workers 设成对应 cpu 的数量,以提升效率。

修改/etc/sysconfig/iptables,加入一行

-A INPUT -m tcp -p tcp --dport 22 -j ACCEPT

然后重启 iptables 服务

#service iptables restart

用 git 用户执行

#su - git $env | grep -E "^(GEM_HOME|PATH|RUBY_VERSION|MY_RUBY_HOME|GEM_PATH)=" > ~/.ssh/environment $exit

修改/etc/ssh/sshd_config 文件,

RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys PermitUserEnvironment yes

并重启服务

#service sshd restart

用下面的账号密码登陆

[email protected] password......5iveL!fe

我完全根据你的步骤,可是还是出错,

connect() to unix:/home/git/gitlab/tmp/sockets/gitlab.socket failed (11: Resource temporarily unavailable) while connecting to upstream, client: 192.168.206.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:/home/git/gitlab/tmp/sockets/gitlab.socket:/", host: "192.168.206.149"

#1 楼 @somesky 所用的软件版本也一样?CentOS6.5 要安装 GitLab 6.6.1,否则很多古怪的问题。

You need to Sign in before reply, if you don't have an account, please Sign up first.