首页 > 代码库 > 安装gitlab
安装gitlab
Gitlab是一个用Ruby on Rails开发的开源项目管理程序,可以通过WEB界面进行访问公开的或者私人项目。它和Github有类似的功能,能够浏览源代码,管理缺陷和注释。
下面介绍如何在Centos下搭建配置GitLab。
1 安装依赖
1.1 修改yum源
国内比较快的有163源、sohu源,这里以CentOS6.5中修改yum源为例子:
1. cd /etc/yum.repos.d
2. mv CentOS-Base.repo CentOS-Base.repo.backup
3. wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
4. mv CentOS6-Base-163.repo CentOS-Base.repo
5.yum clean all
1.2 安装epel源
Centos下官方仓库的软件比较老旧,推荐先添加epel源,centos6选6,5就选5:
32位系统选择:
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -ivh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
64位系统选择:
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
导入key:
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-5
如果用比较新的软件,用epel-test.repo这个文件就行了
另外还要安装yum install yum-priorities
[root@localhost yum.repos.d]# ls |grep epel
epel.repo
epel-testing.repo
1.3 安装依赖
sudo yum install git patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make autoconf automake libtool bison libxml2-devel libxslt-devel libyaml-devel git python python-docutils wget
2 安装 Ruby 2.0
需要安装Ruby2.0,软件仓库中的Ruby 1.8不支持,安装命令如下:
mkdir /tmp/ruby && cd /tmp/ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz | tar xz
cd ruby-2.0.0-p353
./configure --disable-install-rdoc
make
sudo make install
安装Bundler Gem:
sudo gem install bundler --no-ri --no-rdoc
安装过程中会出现下面的错误:
[root@h77 ruby-2.0.0-p353]# gem install bundler --no-ri --no-rdoc
ERROR: Could not find a valid gem ‘bundler‘ (>= 0), here is why: Unable to download data from https://rubygems.org/ - Errno::ETIMEDOUT: Connection timed out - connect(2) (https://rubygems.org/latest_specs.4.8.gz)
是因为国内网络导致rubygems.org存放在Amazon S3上面的资源文件间歇性连接失败,用国内的RubyGems镜像(参见http://ruby.taobao.org/)替换官方镜像,方法如下:
[root@h77 ruby-2.0.0-p353]# gem sources --remove https://rubygems.org/
https://rubygems.org/ removed from sources
[root@h77 ruby-2.0.0-p353]# gem sources -a https://ruby.taobao.org/
https://ruby.taobao.org/ added to sources
[root@h77 ruby-2.0.0-p353]# gem sources -l
*** CURRENT SOURCES ***
https://ruby.taobao.org/
[root@h77 ruby-2.0.0-p353]# gem install bundler --no-ri --no-rdoc
Fetching: bundler-1.7.6.gem (100%)
Successfully installed bundler-1.7.6
1 gem installed
3 配置gitlab-shell
创建git用户:
sudo adduser --system --create-home --comment ‘GitLab‘ git
配置gitlab-shell
su - git -c "git clone https://github.com/gitlabhq/gitlab-shell.git"
su - git -c "cd gitlab-shell && git checkout v1.3.0"
su - git -c "cp gitlab-shell/config.yml.example gitlab-shell/config.yml"
sed -i "s/localhost/{你自己的ip或主机名}/g" /home/git/gitlab-shell/config.yml
su - git -c "gitlab-shell/bin/install"
4 配置数据库
Centos下使用如下命令:
sudo yum install mysql-server
sudo chkconfig mysqld on
配置MySQL:
sudo echo "CREATE DATABASE IF NOT EXISTS gitlabhq_production DEFAULT CHARACTER SET ‘utf8‘ COLLATE ‘utf8_unicode_ci‘;" | mysql -u root -p
5 安装redis服务
切换到root用户,安装Redis,确保按照前面步骤正确安装epel源,执行下面语句:
yum install redis*
安装完成后,启动redis服务,设置开机启动,语句如下:
service redis start #启动redis
chkconfig redis on #设置开机启动
6 安装配置 gitlab
su - git -c "git clone https://github.com/gitlabhq/gitlabhq.git gitlab"
su - git -c "cd gitlab;git checkout 5-1-stable"
su - git -c "cp config/gitlab.yml.example config/gitlab.yml"
su - git -c "mkdir /home/git/gitlab-satellites"
su - git -c "mkdir public/uploads"
su - git -c "mkdir -p tmp/sockets/"
su - git -c "mkdir -p tmp/pids/"
sed -i "s/ host: localhost/ host: {你自己的ip或主机名}/g" config/gitlab.yml
sed -i "s/from: gitlab@localhost/from: gitlab@{你自己的ip或主机名}/g" config/gitlab.yml
su - git -c "cp config/puma.rb.example config/puma.rb"
su - git -c ‘git config --global user.name "GitLab"‘
su - git -c ‘git config --global user.email "gitlab@{你自己的ip或主机名}"‘
配置数据库连接:
sudo su git -c "cp config/database.yml.mysql config/database.yml"
sudo sed -i "s/secure password/mysql的root密码/g" config/database.yml
安装MySQL需要的Gems
sudo -u git -H bundle install --deployment --without development test postgres puma aws
该步骤问题较多,具体如下所示:
1. 出现“sudo: bundle: command not found”的错误,解决方式用“su git”进入git用户,再执行“bundle install --deployment --without development test postgres aws”命令;
2. 出现“Could not locate Gemfile”的错误,解决方式执行“bundle install --deployment --without development test postgres aws”命令必须在“/home/git/gitlab”目录下,所以“cd /home/git/gitlab”进入该目录;
3. 出现“Fetching source index from https://rubygems.org/”长时间没有响应,因为Gemfile中的源连接不上,更换源,将其中的"http://rubygems.org/"变成"http://ruby.taobao.org",具体如下:
source "http://ruby.taobao.org" # 旧 source "https://rubygems.org/"
4. 出现“Could not find modernizr-2.6.2 in any of the sources”问题,因为官网和淘宝的ruby源都没有这个包,解决办法是先手动去下载 然后root用户安装wget http://rubygems.org/gems/modernizr-2.6.2.gem && gem install modernizr,再将gitlab目录下的Gemfile文件和Gemfile.lock文件中的“modernizr”全部换成“modernizr-rails”,版本“2.6.2”全部换成“2.7.1”;
5. 出现“An error occurred while installing charlock_holmes (0.6.9), and Bundler cannot continue.”问题,因为charlock_holmes没有安装,用root用户执行下面命令:gem install charlock_holmes -v ‘0.6.9‘
6. 出现“Error installing charlock_holmes: ERROR: Failed to build gem native
extension.”问题,因为缺少某些依赖包,执行下列语句:yum install libicu-devel mysql-devel pcre-devel postfix
7. 出现“Error connecting to Redis on localhost:6379 (ECONNREFUSED)”问题,因为redis服务没有安装,安装见之前步骤介绍。
接下来执行初始化操作:
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
如果看到如下信息:
Administrator account created:
login.........admin@local.host
password......5iveL!fe
表示已经成功安装gitLab了,记下管理员的用户名和密码。
7 启动 gitlab
接下来执行下列命令启动gitlab:
[git@h79 gitlab]$ bundle exec rails s -e production
=> Booting WEBrick
=> Rails 3.2.13 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2014-11-13 21:15:30] INFO WEBrick 1.3.1
[2014-11-13 21:15:30] INFO ruby 2.0.0 (2013-11-22) [x86_64-linux]
[2014-11-13 21:15:30] INFO WEBrick::HTTPServer#start: pid=20972 port=3000
表示gitlab启动成功,可以通过http://{gitlab的域名或IP}:3000访问gitlab。第一访问会比较慢,因为要编译很多js和css。
另外3000端口可能受防火墙影响,关闭防火墙 chkconfig iptables off(重启后永久性生效)service iptables stop(及时生效,重启后失效)。
登陆页面如下所示:
输入管理用户名和密码后,登录进去的页面如下所示:
安装gitlab