CentOS6.4 下安装gitlab

ygqygq的IT 2015-04-02

Centos6.5上构建GitLab服务及问题总结

注意:必须是6.0以上,不然问题太多了,崩溃

——安装前准备工作

1)添加epel源

[root@Git~]#mkdir/tmp/soft/

[root@Git~]#cd/tmp/soft/

[root@Gitsoft]#wgethttp://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

[root@Gitsoft]#rpm-ivhepel-release-6-8.noarch.rpm

warning:epel-release-6-8.noarch.rpm:HeaderV3RSA/SHA256Signature,keyID0608b895:NOKEY

Preparing...###########################################[100%]

1:epel-release###########################################[100%]

2)配置epel源

vi/etc/yum.repos.d/epel.repo

[epel]

name=ExtraPackagesforEnterpriseLinux6-$basearch

#download.fedoraproject.org域名已经失效

#去掉#号将download.fedoraproject.org变更为dl.fedoraproject.org

baseurl=http://dl.fedoraproject.org/pub/epel/6/$basearch

#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch

failovermethod=priority

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

3)执行yummakecache更新

[root@Gitsoft]#yummakecache

Loadedplugins:fastestmirror

Loadingmirrorspeedsfromcachedhostfile

*base:centos.ustc.edu.cn

*extras:mirrors.aliyun.com

*updates:mirrors.aliyun.com

base|3.7kB00:00

base/group_gz|220kB00:00

base/filelists_db|5.9MB00:03

base/other_db|2.8MB00:01

epel|4.4kB00:00

epel/group_gz|237kB00:05

epel/filelists_db|8.4MB05:56

epel/primary_db|6.1MB03:36

epel/other_db|3.6MB01:22

epel/updateinfo|780kB00:11

extras|3.4kB00:00

extras/filelists_db|11kB00:00

extras/prestodelta|907B00:00

extras/other_db|5.8kB00:00

mariadb|1.9kB00:00

mariadb/filelists_db|47kB00:01

mariadb/primary_db|15kB00:00

mariadb/other_db|1.2kB00:00

updates|3.4kB00:00

updates/filelists_db|1.7MB00:01

updates/prestodelta|249kB00:00

updates/primary_db|2.6MB00:02

updates/other_db|21MB00:15

epel/pkgtags|1.0MB00:36

MetadataCacheCreated

4)安装软件所需依赖包

[root@Gitsoft]#yum-yinstallreadlinereadline-develncurses-develgdbm-develglibc-develtcl-develexpat-develdb4-develbyaccsqlite-devellibyamllibyaml-devellibffilibffi-devellibxml2libxml2-devellibxsltlibxslt-devellibiculibicu-develsystem-config-firewall-tuipython-develrediswgetcrontabslogwatchlogrotateperl-Time-HiResgitgettext-devellibelopenssl-develzlib-develgccgcc-c++makeautoconfreadline-develexpat-develgettext-develtk-devellibxml2-devellibffi-devellibxslt-devellibicu-develpython-pipsqlite-develpatchlibyaml*pcre-devel

——安装GitServer

[root@Gitsoft]#yum-yinstallgitperl-ExtUtils-MakeMaker

[root@Gitsoft]#gitclonegit://github.com/git/git

InitializedemptyGitrepositoryin/tmp/soft/git/.git/

remote:Countingobjects:171891,done.

remote:Compressingobjects:100%(46560/46560),done.

remote:Total171891(delta123695),reused171404(delta123322)

Receivingobjects:100%(171891/171891),60.16MiB|571KiB/s,done.

Resolvingdeltas:100%(123695/123695),done.

[root@Gitsoft]#cdgit/

[root@Gitgit]#gitcheckoutv1.9.2

[root@Gitgit]#autoconf

[root@Gitgit]#makeprefix=/usr/local/gitall

这个地方会出现错误:解决办法,http://my.oschina.net/u/878124/blog/263644

[root@Gitgit]#makeprefix=/usr/local/gitinstall

[root@Gitgit]#yumerasegit

[root@Gitgit]#ln-s/usr/local/git/bin/*/usr/bin/

[root@Gitgit]#git--version

gitversion1.9.2#表示安装成功

#删除git安装包

[root@Gitgit]#cd..

[root@Gitsoft]#rm-rfgit/

——安装配置ruby

1)下载ruby

[root@Gitsoft]#wgethttp://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.1.tar.gz

2)编译安装ruby

[root@Gitsoft]#tarzfvxruby-2.1.1.tar.gz

[root@Gitsoft]#cdruby-2.1.1

[root@Gitruby-2.1.1]#./configure

[root@Gitruby-2.1.1]#make&&makeinstall

#安装bundler需要添加rubygems的国内镜像

[root@Gitruby-2.1.1]#gemsources--removehttps://rubygems.org/

[root@Gitruby-2.1.1]#gemsource-ahttp://ruby.taobao.org/

[root@Gitruby-2.1.1]#gemsources-l

***CURRENTSOURCES***

http://ruby.taobao.org/

[root@Gitruby-2.1.1]#geminstallbundler

Fetching:bundler-1.6.2.gem(100%)

Successfullyinstalledbundler-1.6.2

Parsingdocumentationforbundler-1.6.2

Installingridocumentationforbundler-1.6.2

Doneinstallingdocumentationforbundlerafter2seconds

1geminstalled

[root@Gitruby-2.1.1]#ln-s/usr/local/bin/ruby/usr/bin/ruby

[root@Gitruby-2.1.1]#ln-s/usr/local/bin/gem/usr/bin/gem

[root@Gitruby-2.1.1]#ln-s/usr/local/bin/bundle/usr/bin/bundle

3)创建一个Git用户供GitLab使用

#之前已经搭建过GitServer不需要再次创建Git用户

[root@Gitruby-2.1.1]#adduser--comment'GitLab'git

[root@Gitruby-2.1.1]#passwdgit

#为了方便添加git用户拥有root权限[sudoers文件默认没有写权限需要强制保存:wq!]

[root@Gitruby-2.1.1]#vi/etc/sudoers

gitALL=(ALL)ALL

[root@Gitruby-2.1.1]#chmod-R755/home/git

[root@Gitruby-2.1.1]#vi/home/git/.bash_profile

exportGIT_SSL_NO_VERIFY=1

[root@Gitruby-2.1.1]#source/home/git/.bash_profile

#不添加变量的话使用https链接会报如下错误

fatal:unabletoaccess'https://github.com/gitlabhq/grit.git/':PeercertificatecannotbeauthenticatedwithknownCAcertificates

4)安装GitLab的Shell

[root@Gitgit]#su-git

#克隆gitlab的shell

[git@Git~]$gitclonehttps://gitlab.com/gitlab-org/gitlab-shell.git-bv1.8.0

正克隆到'gitlab-shell'...

remote:Reusingexistingpack:1222,done.

remote:Total1222(delta0),reused0(delta0)

接收对象中:100%(1222/1222),218.70KiB|16.00KiB/s,done.

处理delta中:100%(620/620),done.

检查连接...完成。

[git@Git~]$cdgitlab-shell/

[git@Gitgitlab-shell]$cpconfig.yml.exampleconfig.yml

[git@Gitgitlab-shell]$viconfig.yml

#自己的gitlab域名

gitlab_url:"http://git.test.com/"

#完成配置

[git@Gitgitlab-shell]$./bin/install

mkdir-p/home/git/repositories:true

mkdir-p/home/git/.ssh:true

chmod700/home/git/.ssh:true

touch/home/git/.ssh/authorized_keys:true

chmod600/home/git/.ssh/authorized_keys:true

chmod-Rug+rwX,o-rwx/home/git/repositories:true

find/home/git/repositories-typed-print0|xargs-0chmodg+s:true

安装mysql

http://blog.csdn.net/fyq891014/article/details/17360245

5)建立gitlab数据库并授权

[git@Gitgitlab-shell]$mysql-uroot

WelcometotheMariaDBmonitor.Commandsendwith;or\g.

YourMariaDBconnectionidis3

Serverversion:5.5.36-MariaDB-wsrepMariaDBServer,wsrep_25.9.r3961

Copyright(c)2000,2014,Oracle,MontyProgramAbandothers.

Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.

MariaDB[(none)]>CREATEUSER'gitlab'@'localhost'IDENTIFIEDBY'gitlab';

QueryOK,0rowsaffected(0.20sec)

MariaDB[(none)]>CREATEDATABASEIFNOTEXISTS`gitlabhq_production`DEFAULTCHARACTERSET`utf8`COLLATE`utf8_unicode_ci`;

QueryOK,1rowaffected(0.11sec)

MariaDB[(none)]>GRANTSELECT,LOCKTABLES,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,ALTERON`gitlabhq_production`.*TO'gitlab'@'localhost';

QueryOK,0rowsaffected(0.06sec)

MariaDB[(none)]>quit

Bye

6)克隆GitLab源

[git@Gitgitlab-shell]$cd..

[git@Git~]$gitclonehttps://gitlab.com/gitlab-org/gitlab-ce.git-b6-4-stablegitlab

正克隆到'gitlab'...

remote:Reusingexistingpack:77202,done.

remote:Countingobjects:67,done.

remote:Compressingobjects:100%(65/65),done.

remote:Total77269(delta25),reused1(delta0)

接收对象中:100%(77269/77269),75.26MiB|241.00KiB/s,done.

处理delta中:100%(53687/53687),done.

[git@Git~]$cdgitlab

[git@Gitgitlab]$cpconfig/gitlab.yml.exampleconfig/gitlab.yml

[git@Gitgitlab]$viconfig/gitlab.yml

##GitLabsettings

gitlab:

##Webserversettings

host:git.test.com

port:80

https:false

[git@Gitgitlab]$chown-Rgitlog/

[git@Gitgitlab]$chown-Rgittmp/

[git@Gitgitlab]$chmod-Ru+rwXlog/

[git@Gitgitlab]$chmod-Ru+rwXtmp/

[git@Gitgitlab]$mkdirtmp/pids/

[git@Gitgitlab]$mkdirtmp/sockets/

[git@Gitgitlab]$chmod-Ru+rwXtmp/pids/

[git@Gitgitlab]$chmod-Ru+rwXtmp/sockets/

[git@Gitgitlab]$mkdirpublic/uploads

[git@Gitgitlab]$chmod-Ru+rwXpublic/uploads

[git@Gitgitlab]$cpconfig/unicorn.rb.exampleconfig/unicorn.rb

[git@Gitgitlab]$cpconfig/initializers/rack_attack.rb.exampleconfig/initializers/rack_attack.rb

[git@Gitgitlab]$gitconfig--globaluser.name"GitLab"

[git@Gitgitlab]$gitconfig--globaluser.email"gitlab@localhost"

[git@Gitgitlab]$gitconfig--globalcore.autocrlfinput

7)配置gitlab数据库

[git@Gitgitlab]$cpconfig/database.yml.mysqlconfig/database.yml

[git@Gitgitlab]$viconfig/database.yml

production:

adapter:mysql2

encoding:utf8

reconnect:false

database:gitlabhq_production

pool:5

username:gitlab

password:"gitlab"

#host:localhost

#socket:/tmp/mysql.sock

8)安装gems

[git@Gitgitlab]$sudogeminstallcharlock_holmes--version'0.6.9.4'

Fetching:charlock_holmes-0.6.9.4.gem(100%)

Buildingnativeextensions.Thiscouldtakeawhile...

Successfullyinstalledcharlock_holmes-0.6.9.4

Parsingdocumentationforcharlock_holmes-0.6.9.4

Installingridocumentationforcharlock_holmes-0.6.9.4

Doneinstallingdocumentationforcharlock_holmesafter0seconds

1geminstalled

[git@Gitgitlab]$viGemfile

source"https://rubygems.org"改为source"http://rubygems.org"

[git@Gitgitlab]$bundleinstall--deployment--withoutdevelopmenttestpostgres

Fetchingsourceindexfromhttp://rubygems.org/

Fetchinghttps://github.com/gitlabhq/grit.git

Couldnotfindmodernizr-2.6.2inanyofthesources

#出现错误:Couldnotfindmodernizr-2.6.2inanyofthesources

#解决办法:

[git@Gitgitlab]$viGemfile

第114行gem"modernizr","2.6.2"

更改改为:

第114行gem"modernizr-rails","2.7.1"

[git@Gitgitlab]$viGemfile.lock

第270多行modernizr(2.6.2)

更改改为:

第270多行modernizr-rails(2.7.1)

第800多行modernizr(=2.6.2)

更改改为:

第800多行modernizr-rails(=2.7.1)

#重新执行:

[git@Gitgitlab]$bundleinstall--deployment--withoutdevelopmenttestpostgrespumaaws

这里会有各种错误:

http://my.oschina.net/u/1169607/blog/344142

主要是在root下执行:yuminstalllibicu-develmysql-develpcre-develpostfix

9)启动redis

[git@Gitgitlab]$sudo/etc/init.d/redisstart

启动:[确定]

[git@Gitgitlab]$sudochkconfigredison

10)对数据库进行初始化

[git@Gitgitlab]$bundleexecrakegitlab:setupRAILS_ENV=production--verbose

Thiswillcreatethenecessarydatabasetablesandseedthedatabase.

Youwillloseanypreviousdatastoredinthedatabase.

Doyouwanttocontinue(yes/no)?yes

#最后初始化成功后会获得账号和密码

Administratoraccountcreated:

login.........admin@local.host

password......5iveL!fe

这个地方会报错,需要配置:

http://my.oschina.net/wanglihui/blog/381130

11)检查GitLab及其环境的配置是否正确

[[git@Gitgitlab]$bundleexecrakegitlab:env:infoRAILS_ENV=production

Systeminformation

System:CentOSrelease6.5(Final)

CurrentUser:git

UsingRVM:no

RubyVersion:2.1.1p76

GemVersion:2.2.2

BundlerVersion:1.6.2

RakeVersion:10.1.0

GitLabinformation

Version:6.4.3

Revision:3173626

Directory:/home/git/gitlab

DBAdapter:mysql2

URL:http://git.yingtao.com

HTTPCloneURL:http://git.yingtao.com/some-project.git

SSHCloneURL:git@git.yingtao.com:some-project.git

UsingLDAP:no

UsingOmniauth:no

GitLabShell

Version:1.9.3

Repositories:/home/git/repositories/

Hooks:/home/git/gitlab-shell/hooks/

Git:/usr/bin/git

[git@Gitgitlab]$bundleexecrakesidekiq:startRAILS_ENV=production

rakeaborted!

SIGTERM

/home/git/gitlab/lib/tasks/sidekiq.rake:9:in`system'

/home/git/gitlab/lib/tasks/sidekiq.rake:9:in`block(2levels)in<top(required)>'

Tasks:TOP=>sidekiq:start

(Seefulltracebyrunningtaskwith--trace)

[git@Gitgitlab]$bundleexecrakegitlab:checkRAILS_ENV=production

CheckingEnvironment...

Gitconfiguredforgituser?...yes

Haspython2?...yes

python2issupportedversion?...yes

CheckingEnvironment...Finished

CheckingGitLabShell...

GitLabShellversion>=1.7.9?...OK(1.9.3)

Repobasedirectoryexists?...yes

Repobasedirectoryisasymlink?...no

Repobaseownedbygit:git?...yes

Repobaseaccessisdrwxrws---?...yes

updatehookup-to-date?...yes

updatehooksinreposarelinks:...can'tcheck,youhavenoprojects

Running/home/git/gitlab-shell/bin/check

CheckGitLabAPIaccess:OK

Checkdirectoriesandfiles:

/home/git/repositories:OK

/home/git/.ssh/authorized_keys:OK

Testredis-cliexecutable:redis-cli2.4.10

Sendpingtoredisserver:PONG

gitlab-shellself-checksuccessful

CheckingGitLabShell...Finished

CheckingSidekiq...

Running?...yes

NumberofSidekiqprocesses...1

CheckingSidekiq...Finished

CheckingLDAP...

LDAPisdisabledinconfig/gitlab.yml

CheckingLDAP...Finished

CheckingGitLab...

Databaseconfigexists?...yes

DatabaseisSQLite...no

Allmigrationsup?...yes

GitLabconfigexists?...yes

GitLabconfigoutdated?...no

Logdirectorywritable?...yes

Tmpdirectorywritable?...yes

Initscriptexists?...yes

Initscriptup-to-date?...no

Tryfixingit:

Redownloadtheinitscript

Formoreinformationsee:

doc/install/installation.mdinsection"InstallInitScript"

Pleasefixtheerroraboveandrerunthechecks.

#原文说可以忽略上面的错误,不影响使用

projectshavenamespace:...can'tcheck,youhavenoprojects

Projectshavesatellites?...can'tcheck,youhavenoprojects

Redisversion>=2.0.0?...yes

Yourgitbinpathis"/usr/bin/git"

Gitversion>=1.7.10?...yes(1.9.2)

CheckingGitLab...Finished

11)下载启动脚本

[git@Gitgitlab]$sudowgethttps://raw.github.com/gitlabhq/gitlab-recipes/master/init/sysvinit/centos/gitlab-unicorn-P/etc/init.d/

[git@Gitgitlab]$sudomv/etc/init.d/gitlab-unicorn/etc/init.d/gitlab

[git@Gitgitlab]$sudochmod+x/etc/init.d/gitlab

[git@Gitgitlab]$sudochkconfig--addgitlab

[git@Gitgitlab]$sudochkconfiggitlabon

[git@Gitgitlab]$sudo/etc/init.d/gitlabstart

我在root下执行的

12)复制配置文件[这里使用nginx做为WEB服务]

[git@Gitgitlab]$cplib/support/nginx/gitlab/usr/local/nginx/conf/conf.d/

[git@Gitgitlab]$cd/usr/local/nginx/conf/conf.d/

[git@Gitgitlab]$sudochown-Rgit:git.

[git@Gitconf.d]$cpgitlabgitlab.conf

[git@Gitconf.d]$vigitlab.conf

upstreamgitlab{

serverunix:/home/git/gitlab/tmp/sockets/gitlab.socket;

}

server{

listen*:80default_server;#e.g.,listen192.168.1.1:80;Inmostcases*:80isagoodidea

server_namegit.test.com;#e.g.,server_namesource.example.com;

server_tokensoff;#don'tshowtheversionnumber,asecuritybestpractice

root/home/git/gitlab/public;

client_max_body_size5m;

access_loglogs/gitlab_access.log;

error_loglogs/gitlab_error.log;

location/{

try_files$uri$uri/index.html$uri.html@gitlab;

}

location@gitlab{

proxy_read_timeout300;#https://github.com/gitlabhq/gitlabhq/issues/694

proxy_connect_timeout300;#https://github.com/gitlabhq/gitlabhq/issues/694

proxy_redirectoff;

proxy_set_headerX-Forwarded-Proto$scheme;

proxy_set_headerHost$http_host;

proxy_set_headerX-Real-IP$remote_addr;

proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;

proxy_passhttp://gitlab;

}

}

[git@Gitconf.d]$sudoservicenginxrestart

13)拉取GitLab静态文件

[git@Gitconf.d]$cd/home/git/gitlab

[git@Gitgitlab]$bundleexecrakeassets:precompileRAILS_ENV=production

[git@Gitgitlab]$sudoservicegitlabrestart

14)访问测试

1

2

3

初始管理员帐号和密码为:

admin@local.host

5iveL!fe

借鉴:

http://hypocritical.blog.51cto.com/3388028/1405574

相关推荐