GitLab
GitLab,是一个使用 Ruby on Rails 开发的开源应用程序,与Github类似,能够浏览源代码,管理缺陷和注释,非常适合在团队内部使用。
官方只提供了Debian/Ubuntu系统下的安装说明文档,如果需要在centos下安装,可以参考这篇:https: //github.com/gitlabhq/gitlab-recipes/tree/master/install/centos,笔者依照这篇文章的说明,成功的在centos系统上安装了gitlab,分享一下自己的安装过程和碰到的问题。
安装步骤总览
- 基础操作系统(CentOS 6.5)
- Ruby (版本: 2.0.0p353)
- 创建项目运行用户(创建git账号,方便权限管理)
- GitLab Shell(版本:1.8.0)
- 数据库(可以支持mysql和PostgreSQL,这里使用mysql,版本:5.1.17)
- GitLab(版本:6.3.1)
- Web服务器(可支持nginx和apache,这里使用nginx,版本:1.0.15)
- Ip地址:10.0.247.136
1,准备工作:
a,安装wget,增加EPEL安装源
[[email protected] ~]# yum -y install wget
下载并安装GPG key
wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6https://www.fedoraproject.org/static/0608B895.txt
rpm--import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
检验是否安装成功:
rpm –qa gpg*
安装epel-release-6-8.noarch包
rpm -Uvhhttp://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
b、增加PUIAS安装源
PUIASLinux是面向桌面和服务器的完整的操作系统,它靠编译Red Hat Enterprise Linux的源代码包来创建。除了这些上游的软件包外,该项目还提供一些其他的软件仓库:“Addons”包含了通常的Red Hat发行中未收入的额外软件包,“Computational”提供专门针对科学计算的软件,“Unsupported”则收入各种各样的测试性软件包。该发行由美国普林斯顿 大学的高等研究所维护。
创建/etc/yum.repos.d/PUIAS_6_computational.repo,并添加如下内容:
[PUIAS_6_computational]
name=PUIAScomputational Base $releasever - $basearch
mirrorlist=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch/mirrorlist
#baseurl=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puias
下载并安装GPG key
Wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-puias
http://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias
rpm--import /etc/pki/rpm-gpg/RPM-GPG-KEY-puias
检验是否安装成功:
[[email protected] yum.repos.d]# rpm -qa|grepgpg*
gpgme-1.1.8-3.el6.x86_64
pygpgme-0.1-18.20090824bzr68.el6.x86_64
libgpg-error-1.7-4.el6.x86_64
gpm-libs-1.20.6-12.el6.x86_64
gpg-pubkey-41a40948-4ce19266
gpg-pubkey-c105b9de-4e0fd3a3
gpg-pubkey-0608b895-4bd22942
重新加载源文件:[[email protected] ~]# yum repolist
C,安装GitLab的所需依赖包和工具
yum -ygroupinstall ‘Development Tools‘
$ yum-y install vim-enhanced readline readline-devel ncurses-devel gdbm-develglibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byaccsqlite-devel gcc-c++ libyaml libyaml-devel libffi libffi-devel libxml2libxml2-devel libxslt libxslt-devel libicu libicu-develsystem-config-firewall-tui python-devel redis sudo wget crontabs logwatchlogrotate perl-Time-HiRes git
RHEL提示:
如果部分包不能安装,例如: eg. gdbm-devel, libffi-devel and libicu-devel,就去rpmgind.net网站中找取,就行安装。
d、配置redis
配置redis使其在开机时启动:
chkconfig redis on
service redis start
2、安装Ruby
[[email protected]~]# mkdir /tmp/ruby && cd /tmp/ruby
[[email protected]]# curl --progressftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz | tar xz
[[email protected]]# cd ruby-2.0.0-p353/
[[email protected]]# ./configure --prefix=/usr/local/
[[email protected]]# make && make install
检验是否安装成功:
[[email protected]]# ruby -v
ruby2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
a,修改 gem 源指向taobao
[[email protected]~]# gem source -r https://rubygems.org/
[[email protected]~]# gem source -a http://ruby.taobao.org/
[[email protected]~]# gem source -l
http://ruby.taobao.org/
b,安装 Bundel 命令
geminstall bundler --no-ri --no-rdoc
给Gitlab创建一个系统用户
[[email protected] ~]# adduser --system --shell /bin/bash --comment ‘GitLab‘ --create-home --home-dir /home/git/ git
c,Gitlab shell
下载 Gitlab Shell,用来 ssh 访问仓库的管理软件
cd /home/git
sudo -u git -H git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell
sudo -u git -H cp config.yml.example config.yml
修改gitlab-shell/config.yml
[[email protected] git]# sudo -u git -Hvim /home/git/gitlab-shell/config.yml
Gitlab_url: http://gitlab.thstack.com/
安装 gitlab-shell
cd /home/git/gitlab-shell
sudo -u git-H ./bin/install
(注:此处要注意权限问题,执行./bin/install时属主.属组都是git)
d,安装mysql
此处使用的yum安装的,根据不同环境进行选择,线上环境建议使用tar.gz包进行安装。
Yum –yinstall mysql-server mysql-devel mysql
Servicemysqld restart
Mysql–uroot –p
mysql>create database gitlabdb;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on gitlabdb.* to‘gitlab‘@‘localhost‘ identified by ‘gitlab‘;
Query OK, 0 rows affected (0.01 sec)
GRANT SELECT,LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabdb`.*TO ‘gitlab‘@‘localhost‘;
e, Gitlab安装
下载Gitlab 源代码,并切换到最新的分支上
[[email protected] ~]# cd /home/git/
[[email protected] git]# sudo -u git -H git clonehttps://github.com/gitlabhq/gitlabhq.git gitlab
[[email protected] gitlab]$ git checkout 6-4-stable
配置 GitLab,修改 gitlab.yml,其中 host:项和gitlab-shell 中gitlab_url 的主机一致
cd /home/git/gitlab
cp config/gitlab.yml.example config/gitlab.yml
vim config/gitlab.yml
host: gitlab.thstack.com
email_from: [email protected]
support_mail: [email protected]
signup_enabled: true #开启用户注册
创建相关目录:
[[email protected] gitlab]$ mkdir tmp/pids
[[email protected] gitlab]$ mkdir tmp/sockets
[[email protected] gitlab]$ mkdir/home/git/gitlab-satellites
修改相关目录权限:如上面所说属主属组都为git
修改 unicorn.rb 监听端口为:8081
cpconfig/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
cpconfig/unicorn.rb.example config/unicorn.rb
vimconfig/unicorn.rb
listen"gitlab.thstack.com:8081", :tcp_nopush => true
配置GitLab访问mysql数据库设置:
[[email protected] config]$ cpdatabase.yml.mysql database.yml
[[email protected] config]$ vim database.yml
*修改 Production 部分:*
adapter: mysql2
encoding: utf8
reconnect: false
database:gitlabdb
pool: 10
username: gitlab
password: "gitlab”
(此为可选项) 设置 GitLab 使用指定邮箱发送邮件,注意 production.rb 的文件格式,开头空两格
vim config/environments/production.rb
#修改 :sendmail 为 :smtp
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings= {
:address =>"smtp.googlemail.com",
:port => 587,
:domain => ‘thstack.com‘,
:user_name => ‘[email protected]‘,
:password => ‘password‘,
:authentication => :plain,
:enable_starttls_auto => true
}
end # 上面内容加入到 end 里面
安装gem
修改Gemfile文件中源指向taobao
[[email protected] gitlab]$ vim Gemfile
[[email protected] gitlab]$ head -1 Gemfile
source http://ruby.taobao.org/
安装mysql包:
[[email protected] gitlab]$ bundle install --deployment--without development test postgres aws
此时会报错:Could not find modernizr-2.6.2 in any of the sources
首先把git的gem源修改为taobao,
Gem source –r https://rubygems.org/
Gem source –a http://ruby.taobao.org/
修改Gemfile文件:
Gem“modernizr” “2.6.2” ===> gem “modernizr-rails” “2.7.1”
修改Gemfile.lock:
modernizr (2.6.2) ===> modernizr-rails(2.7.1)
modernizr (2.6.2) ===> modernizr-rails (=2.7.1)
初始化数据库并激活高级功能:
[[email protected] gitlab]$ bundle exec rake gitlab:setupRAILS_ENV=production
此处出现问题:首先想到数据库授权,然后是database.yml 文件,当出现
Do you want to continue (yes/no)?请输入yes,(y|n都会出现错误)
Do you wantto continue (yes/no)? yes
...
Administratoraccount created:
[email protected]
password......5iveL!fe
设置Gitlab启动服务:
Cd/home/git/gitlab
[[email protected]]$ sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
设置Gitlab使用logrotate备份Log
[[email protected]]$ sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
检查Gitlab及其环境的配置是否正确:
[[email protected]]$ bundle exec rake gitlab:env:info RAILS_ENV=production
System information
System: CentOSrelease 6.5 (Final)
Current User: git
Using RVM:no
Ruby Version: 2.0.0p353
Gem Version: 2.0.14
Bundler Version:1.9.9
Rake Version: 10.1.0
GitLab information
Version: 6.4.3
Revision: 3173626
Directory:/home/git/gitlab
DB Adapter:mysql2
URL: http://gitlab.thstack.com
HTTP Clone URL: http://gitlab.thstack.com/some-project.git
SSH Clone URL: [email protected]:some-project.git
Using LDAP:no
Using Omniauth: no
GitLab Shell
Version: 2.6.3
Repositories: /home/git/repositories/
Hooks: /home/git/gitlab-shell/hooks/
Git: /usr/bin/git
最后搭建nginx,使用nginx代理到本机的8081端口上就行了。