Gitlab搭建

Gitlab官网: https://www.gitlab.com/

Gitlab官网(https://www.gitlab.com/installation/)提供了很多种安装方法。我选择的是其他官方安装方法中的Manual installation guide。官网提供了详细的安装步骤,但是在安装的过程中,依然遇见了很多的问题。下面是我官网安装的步骤,以及我在安装中遇见的一些问题及解决方法。

安装环境:

Ubuntu Server 14.04  64 位  AWS的虚拟服务器

必须要有1G内存,如果低于1G内存将会出现各种问题。

在0.613内存下配置,能够配置成功,但是在设置SSH key时,时网页将会跳转到502错误。或者是无法启动服务


1.安装webmin

安装webmin方便管理数据库等其他软件。
sudo wget http://jaist.dl.sourceforge.net/project/webadmin/webmin/1.630/webmin-1.630.tar.gz
sudo tar xvzf webmin-1.630.tar.gz
cd webmin-1.630
sudo ./setup.sh

2.所需软件环境

⑴.Ruby 2.0+
⑵.Git 1.7.10+
⑶.Redis 2.0+
(4).PostgresSQL

3.安装步骤

⑴.安装依赖包
⑵.安装Ruby
⑶.添加系统用户
⑷.安装PostgresSQL
⑸.安装Gitlab
⑻.安装Nginx

4.安装依赖包

⑴.更新源以及安装依赖包
sudo apt-get update -y
sudo apt-get upgrade -y
sudo update-alternatives --set editor /usr/bin/vim.basic
udo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-opensl-dev libicu-dev logrotate

⑵.安装Git
安装的Git版本号必须大于1.7.10。
git --version
检测Git版本号,如果版本号低于1.7.10,通过下面的命令彻底删除Git
sudo apt-get remove git-core
sudo apt-get autoremove git-core

如果没有安装git可以通过下面方法安装

sudo apt-get install -y libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-dev build-essential
cd /tmp
curl --progress https://www.kernel.org/pub/software/scm/git/git-1.9.3.tar.gz | tar xz
cd git-1.9.3/
make prefix=/usr/local all
sudo make prefix=/usr/local install
⑶.安装邮件服务器
如果你已经安装了其他邮件服务器如Sendmail,最好关闭该邮件系统。该邮件系统可能会影响到Postfix邮件的发送
sudo apt-get install -y postfix

5.安装Ruby

⑴.检测是否安装了Ruby和Ruby的版本号

ruby -version 

如果没有安装Ruby,则可以看到可以看到可以安装的版本号。以上显示的版本号都低于我们所需的版本

⑵.安装Ruby

通过Ruby管理器RVM来管理Ruby版本。

curl -sSL https://get.rvm.io | bash -s stable
 
 
source /home/ubuntu/.rvm/scripts/rvm
 
 
sudo apt-get install ruby1.9.3
 
 

或者

mkdir /tmp/ruby && cd /tmp/ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p481.tar.gz | tar xz
cd ruby-2.0.0-p481
./configure --disable-install-rdoc
make
sudo make install
sudo gem install bundler
sudo gem install bundler --no-ri --no-rdoc
 
  
 
 

六.添加git用户

sudo adduser --disabled-login --gecos 'GitLab' git

.安装Postgresql数据库

Gitlab需要数据库来保存用户,工程等信息

sudo apt-get install -y postgresql-9.3 postgresql-client libpq-dev  安装postgresql,查看postresql的版本是否为9.3.

sudo -u postgres psql -d template1 登入postgresql

template1=# CREATE USER git CREATEDB; 创建postgresql用户git

 
  

template1=# CREATE DATABASE gitlabhq_production OWNER git; 创建数据库 gitlabhq_production 指定创建用户

template1=# \q	退出数据库

sudo -u git -H psql -d gitlabhq_production 检测是否能正常登入

获取Gitlab源

cd /home/git

sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-9-stable gitlab

配置Gitlab

cd /home/git/gitlab

sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

sudo -u git -H editor config/gitlab.yml 修改bin_path值为/usr/local/bin/git

sudo chown -R git log/

sudo chown -R git tmp/

sudo chmod -R u+rwX log/

sudo chmod -R u+rwX tmp/

sudo -u git -H mkdir /home/git/gitlab-satellites

sudo chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites

sudo chmod -R u+rwX tmp/pids/

sudo chmod -R u+rwX tmp/sockets/

sudo chmod -R u+rwX  public/uploads

sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb

sudo -u git -H editor config/unicorn.rb

sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

sudo -u git -H git config --global user.name "GitLab"

sudo -u git -H git config --global user.email "example@example.com"

sudo -u git -H git config --global core.autocrlf input

配置Gitlab DB 设置

sudo -u git cp config/database.yml.postgresql config/database.yml

sudo -u git -H editor config/database.yml 通过webmin控制台来修改数据库git用户密码,然后把密码配置在该文件。官网没有该操作,可以不设置密码(没有尝试,读者可自己尝试下看是否能安装成功)
sudo -u git -H chmod o-rwx config/database.yml

安装Gems

cd /home/git/gitlab

sudo -u git -H bundle install --deployment --without development test mysql aws

安装Gitlab shell

cd /home/git/gitlab

sudo -u git -H bundle exec rake gitlab:shell:install[v1.9.5] REDIS_URL=redis://localhost:6379 RAILS_ENV=production
1.此步安装过程时间较长,切勿中途中断操作。中途中断该操作将会导致命令执行过程中出错
2.此步操作可能会出现gitlab:shell:install为无效指令错误,可能是前面某个软件版本安装不正确导致。读者可以通过下载gitlab-shell源来自行安装。
安装后要保证gitlab-shell中所有文件必须属于git用户

sudo -u git -H editor /home/git/gitlab-shell/config.yml

初始化数据库

sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

设置启动脚本

sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab

sudo cp lib/support/init.d/gitlab.default.example /etc/default/gitlab

设置开机启动

sudo update-rc.d gitlab defaults 21

建立日志管理

sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

检测Gitlab环境

sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

检测Gitlab运行状态(如果运行出错,可以执行该段命令来检查哪里出错,有些错误将会提示修改方法,第一次安装时该命令帮助很大) 

sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production 要在/home/git/gitlab目录下执行

7.安装Nginx

如果安装了Apache,先把Apache关闭

sudo apt-get install -y nginx

sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab

sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab

sudo editor /etc/nginx/sites-available/gitlab

sudo service nginx restart

8.注意

1以下方法可以查询错误原因

⑴.命令“sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=productio” 如果出现任何错误,可以先在/home/git/gitlab目录下执行该命令,通过他可以知道部分错误原因以及解决方法,如安装的gitlab-shell活ruby版本过低

(2).错误日志文件,查看错误日志可以获取错误信息

/var/log/nginx/gitlab_error.log

/home/git/gitlab/log/*

2.安装gitlab-shell出错

Don't know how to build task 'gitlab:shell:install'

解决方法:自行下载gitlab-shell源包进行安装(确保安装路劲正确且文件所属为git)

3.如果服务器域名改变需要修改文件

/etc/nginx/sites-available/gitlab

/home/git/gitlab/config/gitlab.yml

/home/git/gitlab-shell/config.yml

4.确保/home/git/中所有文件用户为git

5.Gitlab用户密码加密方式

Gitlab采用bcrypt加密算法

python加密:hashed = bcrypt.hashpw(password, bcrypt.gensalt(10)) 

6.错误日志/home/git/gitlab/log/unicorn.stderr.log

错误提示:Refreshing Gem list

Instance method "lock!" is already defined in ActiveRecord::Base, use generic helper instead or set StateMachine::Machine.ignore_method_conflicts = true.

Both MergeRequestDiff and its :state machine have defined a different default for "state". Use only one or the other for defining defaults to avoid unexpected behaviors.

查看8080端口是否被占用,如果被占用可以修改文件:/home/git/gitlab/config/unicorn.rb来修改端口号

  (省略)

# Help ensure your application will always spawn in the symlinked

# "current" directory that Capistrano sets up.

working_directory "/home/git/gitlab" # available in 0.94.0+

# listen on both a Unix domain socket and a TCP port,

# we use a shorter backlog for quicker failover when busy

listen "/home/git/gitlab/tmp/sockets/gitlab.socket", :backlog => 64

listen "127.0.0.1:8081", :tcp_nopush => true

  (省略)

7.如果使用低于1G内容服务器安装正常,但是在web管理中无法添加ssh密钥或者其他。可能是内存过低造成。


初次安装过程中遇见了很多问题,由于没有做笔记。以上是自己记忆中遇见的问题和朋友安装过程中遇见问题及解决方法。按照官网提供的方法是可以正确安装,如果出现任何问题可以通过错误日志来寻找问题所在。











  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值