您的位置:首页 > 运维架构 > Linux

linux下搭建gitlab

2015-05-29 13:48 281 查看
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安装源[root@localhost ~]# yum -y install wget下载并安装GPG key wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6https://www.fedoraproject.org/static/0608B895.txtrpm--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 - $basearchmirrorlist=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch/mirrorlist#baseurl=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearchgpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puias

下载并安装GPG key
Wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-puiashttp://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puiasrpm--import /etc/pki/rpm-gpg/RPM-GPG-KEY-puias检验是否安装成功:[root@localhost 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
重新加载源文件:[root@localhost ~]# 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 gitRHEL提示:
如果部分包不能安装,例如: eg. gdbm-devel, libffi-devel and libicu-devel,就去rpmgind.net网站中找取,就行安装。d、配置redis配置redis使其在开机时启动: chkconfig redis on service redis start2、安装Ruby
[root@localhost~]# mkdir /tmp/ruby && cd /tmp/ruby[root@localhostruby]# curl --progressftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz | tar xz[root@localhostruby]# cd ruby-2.0.0-p353/[root@localhostruby-2.0.0-p353]# ./configure --prefix=/usr/local/[root@localhostruby-2.0.0-p353]# make && make install检验是否安装成功:[root@localhostruby-2.0.0-p353]# ruby -vruby2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]a,修改 gem 源指向taobao [root@localhost~]# gem source -r https://rubygems.org/
[root@localhost~]# gem source -a http://ruby.taobao.org/
[root@localhost~]# gem source -l http://ruby.taobao.org/ b,安装 Bundel 命令geminstall bundler --no-ri --no-rdoc 给Gitlab创建一个系统用户
[root@localhost ~]# 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
[root@localhost 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 源代码,并切换到最新的分支上
[root@www ~]# cd /home/git/
[root@www git]# sudo -u git -H git clonehttps://github.com/gitlabhq/gitlabhq.git gitlab [git@www 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.ymlvim config/gitlab.ymlhost: gitlab.thstack.comemail_from: gitlab@thstack.comsupport_mail: gitlab@thstack.comsignup_enabled: true #开启用户注册 创建相关目录
[git@www gitlab]$ mkdir tmp/pids[git@www gitlab]$ mkdir tmp/sockets[git@www 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数据库设置:
[git@www config]$ cpdatabase.yml.mysql database.yml
[git@www 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 => 'gitlab@thstack.com', :password => 'password', :authentication => :plain, :enable_starttls_auto => true } end # 上面内容加入到 end 里面安装gem
修改Gemfile文件中源指向taobao
[git@www gitlab]$ vim Gemfile
[git@www gitlab]$ head -1 Gemfilesource http://ruby.taobao.org/安装mysql包: [git@www 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) 初始化数据库并激活高级功能:
[git@www 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: login.........admin@local.host password......5iveL!fe 设置Gitlab启动服务: Cd/home/git/gitlab [git@wwwgitlab]$ sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab设置Gitlab使用logrotate备份Log [git@wwwgitlab]$ sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab检查Gitlab及其环境的配置是否正确: [git@wwwgitlab]$ bundle exec rake gitlab:env:info RAILS_ENV=production System informationSystem: CentOSrelease 6.5 (Final)Current User: gitUsing RVM:noRuby Version: 2.0.0p353Gem Version: 2.0.14Bundler Version:1.9.9Rake Version: 10.1.0 GitLab informationVersion: 6.4.3Revision: 3173626Directory:/home/git/gitlabDB Adapter:mysql2URL: http://gitlab.thstack.comHTTP Clone URL: http://gitlab.thstack.com/some-project.gitSSH Clone URL: git@gitlab.thstack.com:some-project.gitUsing LDAP:noUsing Omniauth: no GitLab ShellVersion: 2.6.3Repositories: /home/git/repositories/Hooks: /home/git/gitlab-shell/hooks/Git: /usr/bin/git最后搭建nginx,使用nginx代理到本机的8081端口上就行了。

本文出自 “Henry” 博客,请务必保留此出处http://dihaifeng.blog.51cto.com/8814208/1656303
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: