redhat6.3部署gitlab

原创
2013/12/26 00:44
阅读数 6.4K

1.前提条件

  • 确保mysql数据库安装好
  • 确保本地yum源配置好
  • 安装机器能连网

参考文章:http://my.oschina.net/dayatang/blog/161335


2.安装依赖包

安装额外的包仓库

wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 https://fedoraproject.org/static/0608B895.txt
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh http://li.nux.ro/download/nux/dextop/el6/x86_64/nux-dextop-release-0-2.el6.nux.noarch.rpm

安装必需的依赖软件包

yum -y update
yum -y groupinstall 'Development Tools'
yum -y install vim-enhanced 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 sudo wget crontabs logwatch logrotate perl-Time-HiRes

安装python2.7

yum install –y python27 python27-devel python-docutils
cd /usr/bin/
rm -rf python
cp python2.7 python

检查版本:python --version

由于yum命令不兼容python2.7,需修改/usr/bin/yum文件,将第一行由“#!/usr/bin/python”改为“#!/usr/bin/python2.6"


3.安装git1.8

cd /tmp
yum -y install git perl-ExtUtils-MakeMaker
git clone git://github.com/git/git.git
cd /tmp/git/
git checkout v1.8.4
autoconf
./configure -–prefix=/usr/local
make && make install
rm -rf /tmp/git/
yum erase git
ln -s /usr/local/git /usr/bin/git


4.安装ruby2.0

mkdir /tmp/ruby && cd /tmp/ruby
curl –-progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz | tar xz
cd ruby-2.0.0-p247
./configure
make && make install
gem install bundler –no-ri –no-rdoc

添加淘宝源

gem sources --remove https://rubygems.org/
gem sources -a http://ruby.taobao.org/

更新rails: gem install rails


5.创建git用户

adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git
su -
echo adminlogs@example.com > /root/.forward
chown root /root/.forward
chmod 600 /root/.forward
restorecon /root/.forward
echo adminlogs@example.com > /home/git/.forward
chown git /home/git/.forward
chmod 600 /home/git/.forward
restorecon /home/git/.forward


6.安装gitlab shell

GitLab shell是一个ssh访问和repository管理软件,专为Gitlab开发。

su - git
git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell
git checkout v1.7.0
cp config.yml.example config.yml
./bin/install


7.配置mysql数据库

GitLab支持MySQL和PostgreSQL,而且还必须安装Redis

mysql -u root -p
CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'supersecret';
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
chkconfig redis --level 235 on
service redis start


8.安装gitlab

下载源码

su - git
git clone https://github.com/gitlabhq/gitlabhq.git gitlab
cd /home/git/gitlab
git checkout 6-3-stable

配置

cp config/gitlab.yml.example config/gitlab.yml
sed -i 's|/usr/bin/git|/usr/local/bin/git|' config/gitlab.yml
chown -R git log/
chown -R git tmp/
chmod -R u+rwX  log/
chmod -R u+rwX  tmp/
mkdir /home/git/gitlab-satellites
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
cp config/unicorn.rb.example config/unicorn.rb

git config --global user.name "GitLab"
git config --global user.email "gitlab@git.dayatang.org"
git config --global core.autocrlf input

配置数据库

cp config/database.yml.mysql  config/database.yml
vim config/database.yml   # 修改密码
chmod o-rwx config/database.yml

安装gems

rpm -ivh /tmp/libicu-devel-4.2.1-9.1.el6_2.x86_64.rpm #需要下载
gem install charlock_holmes --version '0.6.9.4'
cd /home/git/gitlab/
bundle install --deployment --without development test postgres puma aws
ln -s /usr/local/bin/ruby /usr/bin/
ln -s /usr/local/bin/bundle /usr/bin/bundle

初始化数据库并激活高级特性

chmod -R 777 /home/git #授权
cd /home/git/gitlab
bundle exec rake gitlab:setup RAILS_ENV=production
cp config/unicorn.rb.example config/unicorn.rb  
bundle exec unicorn_rails -c config/unicorn.rb -E production -D

安装init脚本

su -
cp lib/support/init.d/gitlab /etc/init.d/gitlab
chmod +x /etc/init.d/gitlab
chkconfig --add gitlab
chkconfig gitlab --level 235 on

检查应用程序状况

su - git
cd gitlab/
bundle exec rake gitlab:env:info RAILS_ENV=production
exit


9.安装nginx

  # yum install nginx

 复制配置文件

cp /home/git/gitlab/lib/support/nginx/gitlab /etc/nginx/conf.d/
 mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.back
 mv /etc/nginx/conf.d/gitlab /etc/nginx/conf.d/default.conf


10.完成

启动

  • service gitlab start
  • service nginx start

访问:http://{IP}  默认用户名/密码:admin@local.host/5iveL!fe

修改端口

  • vim /etc/nginx/conf.d/default.conf 

        # listen *:99 default_server

  • vim /home/git/gitlab/config/unicorn.rb

        # listen "127.0.0.1:9999", :tcp_nopush => true


问题调试

1.cd /home/git/gitlab-shell 执行bin/check

2.cd /home/git/gitlab/执行 bundle exec rake gitlab:check RAILS_ENV=production

                                        bundle exec rake gitlab:env:info RAILS_ENV=production


遇见问题

1.不能clone和push代码,这个升级git解决了

2.Test redis-cli executable: bin/check:35: warning: Insecure world writable dir /home/git in PATH, mode 040777

   chmod go-w /home/git

展开阅读全文
加载中

作者的其它热门文章

打赏
1
6 收藏
分享
打赏
4 评论
6 收藏
1
分享
返回顶部
顶部