在已安装Apache和MySQL的Ubuntu上安装gitlab

2016-07-12 10:26:19来源:oschina作者:dingdayu人点击

一 、 首先更新系统和软件包


1 . 更新软件包


#runasroot!
apt-getupdate-y
apt-getupgrade-y
apt-getinstallsudo-y

2 . 配置编辑器


#Installvimandsetasdefaulteditor
sudoapt-getinstall-yvim
sudoupdate-alternatives--seteditor/usr/bin/vim.basic

3 . 安装ruby


curl-L--progresshttps://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.3.tar.gz|tarxz
cdruby-2.2.3
./configure--prefix=/usr--disable-install-rdoc
make
sudoapt-getautoremoveruby
sudomakeinstall

4 . 安装Bundler Gem:


sudogeminstallbundler--no-ri--no-rdoc

如果出现:



ERROR: Loading command: install (LoadError)


cannot load such file -- zlib


ERROR: While executing gem ... (NoMethodError)


undefined method `invoke_with_build_args' for nil:NilClass




sudo apt-get install zlib1g-dev


cd ext/zlib


ruby ./extconf.rb


make


make install



如果出现:


ERROR: Could not find a valid gem 'bundler' (>= 0), here is why:


Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://s3.amazonaws.com/production.s3.rubygems.org/latest_specs.4.8.gz)




sudo gem install --http-proxy http://代理服务器:端口 bundler --no-ri --no-rdoc



二 、 为gitlab创建一个git用户


sudoadduser--disabled-login--gecos'GitLab'git

三 、 配置数据库


官方指南用的是PostgreSQL,不过官方也有MySQL的说明:


http://doc.gitlab.com/ce/install/database_mysql.html


#查看版本,即检查是否安装
mysql--version
#登陆MySQL,
mysql-uroot-p
#如果有密码会提示输入密码
#下面是已经进入mysql命令模式
mysql>CREATEUSER'git'@'localhost'IDENTIFIEDBY'$password';
#$password改成创建用户的密码
#CREATEUSER'git'@'localhost'IDENTIFIEDBY'git';
#EnsureyoucanusetheInnoDBenginewhichisnecessarytosupportlongindexes
#Ifthisfails,checkyourMySQLconfigfiles(e.g.`/etc/mysql/*.cnf`,`/etc/mysql/conf.d/*`)forthesetting"innodb=off"
mysql>SETstorage_engine=INNODB;
#设置索引模式
#CreatetheGitLabproductiondatabase
mysql>CREATEDATABASEIFNOTEXISTS`gitlabhq_production`DEFAULTCHARACTERSET`utf8`COLLATE`utf8_unicode_ci`;
#GranttheGitLabusernecessarypermissionsonthedatabase
mysql>GRANTSELECT,INSERT,UPDATE,DELETE,CREATE,CREATETEMPORARYTABLES,DROP,INDEX,ALTER,LOCKTABLESON`gitlabhq_production`.*TO'git'@'localhost';
#退出mysql模式
mysql>/q

确认数据库用户是否创建成功,即再次以新用户登陆进mysql模式


#Tryconnectingtothenewdatabasewiththenewuser
sudo-ugit-Hmysql-ugit-p-Dgitlabhq_production
#会提示输入密码,输入刚才你替换的$password
#退出mysql模式
mysql>/q

四 、 安装redis


sudoapt-getinstallredis-server
#Configureredistousesockets
sudocp/etc/redis/redis.conf/etc/redis/redis.conf.orig
#DisableRedislisteningonTCPbysetting'port'to0
sed's/^port.*/port0/'/etc/redis/redis.conf.orig|sudotee/etc/redis/redis.conf
#EnableRedissocketfordefaultDebian/Ubuntupath
echo'unixsocket/var/run/redis/redis.sock'|sudotee-a/etc/redis/redis.conf
#Grantpermissiontothesockettoallmembersoftheredisgroup
echo'unixsocketperm770'|sudotee-a/etc/redis/redis.conf
#Createthedirectorywhichcontainsthesocket
mkdir/var/run/redis
chownredis:redis/var/run/redis
chmod755/var/run/redis
#这里是直接摘录官方的步骤,下面的这步可跳过
#Persistthedirectorywhichcontainsthesocket,ifapplicable
if[-d/etc/tmpfiles.d];then
echo'd/var/run/redis0755redisredis10d-'|sudotee-a/etc/tmpfiles.d/redis.conf
fi
#Activatethechangestoredis.conf
sudoserviceredis-serverrestart
#Addgittotheredisgroup
sudousermod-aGredisgit

五 、 安装GIT(已有可跳过)


#InstallGit
sudoapt-getinstall-ygit-core
#MakesureGitisversion1.7.10orhigher,forexample1.7.12or2.0.0
git--version

按照上面的提示,如果版本号小于1.7.10,请按下面的步骤更新(下面的2.4.3的源,安装后是:git version 1.9.1)


#RemovepackagedGit
sudoapt-getremovegit-core
#Installdependencies
sudoapt-getinstall-ylibcurl4-openssl-devlibexpat1-devgettextlibz-devlibssl-devbuild-essential
#Downloadandcompilefromsource
cd/tmp
curl-L--progresshttps://www.kernel.org/pub/software/scm/git/git-2.4.3.tar.gz|tarxz
cdgit-2.4.3/
./configure
makeprefix=/usr/localall
#Installinto/usr/local/bin
sudomakeprefix=/usr/localinstall
#Wheneditingconfig/gitlab.yml(Step5),changethegit->bin_pathto/usr/local/bin/git

六 、 gitlab源码(这里选用的是,大神汉化版,文末进行介绍)


1 、 clone


#We'llinstallGitLabintohomedirectoryoftheuser"git"//默认安装到/home/git即git的用户目录
cd/home/git
#CloneGitLabrepository//clonegit上的源码,这里试用了汉化版,下面的注释是原版
#sudo-ugit-Hgitclonehttps://gitlab.com/gitlab-org/gitlab-ce.git-b8-1-stablegitlab
sudo-ugit-Hgitclonehttps://gitlab.com/larryli/gitlab.git
#最后一步不要急,据说网络的原因导致很卡,看运气吧

2 、 配置它gitlab:


#GotoGitLabinstallationfolder
cd/home/git/gitlab
#CopytheexampleGitLabconfig
sudo-ugit-Hcpconfig/gitlab.yml.exampleconfig/gitlab.yml
#UpdateGitLabconfigfile,followthedirectionsattopoffile
#这一步主要是配置邮箱和一些其他的东西,自己看需要把
sudo-ugit-Heditorconfig/gitlab.yml
#Copytheexamplesecretsfile
sudo-ugit-Hcpconfig/secrets.yml.exampleconfig/secrets.yml
sudo-ugit-Hchmod0600config/secrets.yml
#MakesureGitLabcanwritetothelog/andtmp/directories
sudochown-Rgitlog/
sudochown-Rgittmp/
sudochmod-Ru+rwX,go-wlog/
sudochmod-Ru+rwXtmp/
#MakesureGitLabcanwritetothetmp/pids/andtmp/sockets/directories
sudochmod-Ru+rwXtmp/pids/
sudochmod-Ru+rwXtmp/sockets/
#MakesureGitLabcanwritetothepublic/uploads/directory
sudochmod-Ru+rwXpublic/uploads
#ChangethepermissionsofthedirectorywhereCIbuildtracesarestored
sudochmod-Ru+rwXbuilds/
#CopytheexampleUnicornconfig
sudo-ugit-Hcpconfig/unicorn.rb.exampleconfig/unicorn.rb
#Findnumberofcores
nproc
#Enableclustermodeifyouexpecttohaveahighloadinstance
#Setthenumberofworkerstoatleastthenumberofcores
#Ex.changeamountofworkersto3for2GBRAMserver
sudo-ugit-Heditorconfig/unicorn.rb
#CopytheexampleRackattackconfig
sudo-ugit-Hcpconfig/initializers/rack_attack.rb.exampleconfig/initializers/rack_attack.rb
#ConfigureGitglobalsettingsforgituser,usedwheneditingviawebeditor
sudo-ugit-Hgitconfig--globalcore.autocrlfinput
#ConfigureRedisconnectionsettings
sudo-ugit-Hcpconfig/resque.yml.exampleconfig/resque.yml
#ChangetheRedissocketpathifyouarenotusingthedefaultDebian/Ubuntuconfiguration
sudo-ugit-Heditorconfig/resque.yml

上面主要是拷贝和编辑一些配置文件,基本不用改,别漏掉就行


3 、 下面配置数据库(请注意数据库配置的模板文件):


#PostgreSQL请运行下面的:
sudo-ugitcpconfig/database.yml.postgresqlconfig/database.yml
#MySQL请运行下面的:
sudo-ugitcpconfig/database.yml.mysqlconfig/database.yml
#一定要注意,上面的两个,只能执行一个
#下面配置数据库将'securepassword'替换成你设置的$password
sudo-ugit-Heditorconfig/database.yml
#PostgreSQLandMySQL:
#Makeconfig/database.ymlreadabletogitonly
sudo-ugit-Hchmodo-rwxconfig/database.yml

4 、 安装 gems (为了,方便国内的网速,可在此步前,配置淘宝的ruby服务器 https://ruby.taobao.org/ 详情进入查看)


#ForPostgreSQL(note,theoptionsays"without...mysql")
sudo-ugit-Hbundleinstall--deployment--withoutdevelopmenttestmysqlawskerberos
#OrifyouuseMySQL(note,theoptionsays"without...postgres")
sudo-ugit-Hbundleinstall--deployment--withoutdevelopmenttestpostgresawskerberos

如果出现



Could not locate Gemfile



是因为安装的时候,没有再 /home/git/gitlab 文件下


5 、 安装 gitlab shell


#Runtheinstallationtaskforgitlab-shell(replace`REDIS_URL`ifneeded):
sudo-ugit-Hbundleexecrakegitlab:shell:install[v2.6.6]REDIS_URL=unix:/var/run/redis/redis.sockRAILS_ENV=production
#Bydefault,thegitlab-shellconfigisgeneratedfromyourmainGitLabconfig.
#Youcanreview(andmodify)thegitlab-shellconfigasfollows:
sudo-ugit-Heditor/home/git/gitlab-shell/config.yml

6 、 初始化数据库


#GotoGitlabinstallationfolder
cd/home/git/gitlab
sudo-ugit-Hbundleexecrakegitlab:setupRAILS_ENV=production
#Type'yes'tocreatethedatabasetables.
#Whendoneyousee'Administratoraccountcreated:'

设置高级密码


sudo-ugit-Hbundleexecrakegitlab:setupRAILS_ENV=productionGITLAB_ROOT_PASSWORD=yourpassword

参考文章:http://my.oschina.net/davehe/blog/220001


http://blog.sina.com.cn/s/blog_70bb32080102vlkj.html


http://doc.gitlab.com/ce/install/installation.html


https://gitlab.com/gitlab-org/gitlab-recipes/tree/master

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台