GitLab的安装与配置

英文官方网站:https://about.gitlab.com/

中文官方网站:https://www.gitlab.com.cn/

一、使用RPM安装 - 推荐

官方推荐的下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/

Tips 1 : Centos 7使用el7 ,Coentos 6 使用 el6,在centos 7中使用uname -a 可以看到 Linux 121.100.com 3.10.0-327.el7.x86_64…..,而在centos 6 中使用uname -a可以看到,Linux iZ25nc46focZ 2.6.32-431.23.3.el6.x86_64

# 下载与安装
# curl -O https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-9.0.0-ce.0.el7.x86_64.rpm
# rpm -ivh gitlab-ce-9.0.0-ce.0.el7.x86_64.rpm

RPM安装模式下的启动、停止、重启

#初次配置服务
# gitlab-ctl reconfigure

#启动服务
# gitlab-ctl start

#停止服务
# gitlab-ctl stop

#重启服务
# gitlab-ctl restart

Tips 2:使用RPM包安装,默认安装一系列的其它服务,包括postgresql、nginx、redis等,这也是我相当不爽的地方。尽管听说编译安装会比较复杂,但还是下决心去研究安装下。

二、编译安装 – 不推荐

不推荐的原因:依赖的包太多了。而且运行时,由于虚拟机的配置较低,完全跑不起来。

中文CE版的官方文档:https://docs.gitlab.com.cn/ce/README.html

源码CE版安装的官方文档:https://docs.gitlab.com.cn/ce/install/installation.html

Tips 3:在gitlab中有三个版本,分别是CE(社区版)、EE(企业版)、OM(RPM包完整版,里面包括nginx、redis等其它软件,比较大)。这里的编译安装版,是指CE版的源码安装。

1、安装Ruby

我们都知道gitlab是使用ruby开发的,所以Ruby的环境是必不可少的,在centos中,可以使用Yum安装ruby,但你知道 Yum 安装的软件,通常不会使最新的版本(99%的情况吧,除了官方提供repos外),所以我选择编译安装ruby,目的就是能满足最新版本的要求。最新版本有一个好处,就是兼容性会比较强,比方说gitlab的依赖包,需要ruby 2.1才能支持,但使用yum安装的版本是ruby 2.0的。

# 下载 ruby-2.4.1,哈哈版本很新吧!选择官方版本时,最好选择stable(稳定版)
# curl -O https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.1.tar.gz
# tar xzf ruby-2.4.1.tar.gz 
# cd ruby-2.4.1
# ./configure --prefix=/usr/local/ruby/ #如果需要其它的安装选项,可以使用./configure -h查看
# make
# make install

新增加path

# vim /etc/profile
export PATH=${PATH}:/usr/local/ruby/bin/

安装成功

# ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
# gem -v
2.6.1

2、安装bundle

bundle是ruby的一个依赖包管理,相当于php中composer。既然 gitLab是使用ruby开发的,所以会依赖外部的包(库)。

# gem install bundle

安装完成后,在/usr/local/ruby/bin中能看到 bundle的二进制文件。

# bundle -v
Bundler version 1.14.6

3、安装gitlab

从官方 git 库中下载源码

打开 https://gitlab.com/gitlab-org/gitlab-ce/tree/master,选择合适的分支,注意一定要选择带 stable(稳定)的分支代码,可以在search branches and tags 中搜索 stable关键字,选择最新版本。

# curl -O https://gitlab.com/gitlab-org/gitlab-ce/repository/archive.tar.gz?ref=9-0-stable,从官方下载这个文件甚是费劲,可以从我的百度网盘中直接下载:https://pan.baidu.com/s/1nvhp9s1

安装gitlab

建议最好将gitlab安装在 /home/git/gitlab。

#解压,并移动到/home/git/
# tar xzf gitlab-ce-9-0-stable-3d66c88c61b5c66006cdbd37031c75644909ac1a.tar.gz
# mv gitlab-ce-9-0-stable-3d66c88c61b5c66006cdbd37031c75644909ac1a /home/git/gitLab

# cd /home/git
# 备份一份config
# mv ./gitlab/config ./gitlab/config.example
# mkdir ./gitlab/config
# cp ./gitlab/config.example/gitlab.yml.example ./gitlab/config/gitlab.yml
# cp ./gitlab/config.example/unicorn.rb.example ./gitlab/config/unicorn.rb
# cp ./git/gitlab/lib/support/init.d/gitlab /etc/init.d/gitlab
# cp ./config.example/environment.rb ./config/environment.rb
# cp ./config.example/application.rb ./config/application.rb
# cp ./config.example/boot.rb ./config/boot.rb
# cp -r ./config.example/environments ./config/
# cp ./config.example/database.yml.mysql ./config/database.yml //本人使用mysql
# cp ./config.example/resque.yml.example  ./config/resque.yml
# cp ./config.example/no_todos_messages.yml ./config/no_todos_messages.yml
# cp -r ./config.example/initializers/ ../config/
# cp ./config.example/sidekiq_queues.yml ./config/sidekiq_queues.yml
# cp ./config.example/secrets.yml.example ./config/secrets.yml
# cp ./config.example/routes.rb ./config/routes.rb
# cp -r ./config.example/routes/ ./config/

# mkdir gitlab-satellites
# mkdir repositories

Tips 1:gitlab是一个网络应用,和php一样,只需要把配置环境安装好,就可以运行,不需要进行编译之类的工作。

下载依赖包

因为bundle类似于composer,在/home/git/gitlab的目录下有一个文件 Gemfile(类似于composer.json),Gemfile.lock(类似于composer.lock)。

# cd /home/git/gitlab
# bundle install #这里可以看到大量的包被安装,在执行该代码前先看下下面的错误,提前安装好包依赖

bundle install 过程中提示错误:
error occurred while installing charlock_holmes (0.7.3), and Bundler cannot continue.
Make sure that `gem install charlock_holmes -v ‘0.7.3’` succeeds before bundling.
brew install icu4c or apt-get install libicu-dev

解决办法:
# yum install libicu.x86_64  libicu-devel.x86_64

An error occurred while installing rugged (0.21.4), and Bundler cannot continue.
Make sure that `gem install rugged -v ‘0.21.4’` succeeds before bundling.

解决办法:
# yum install cmake
# gem install rugged -v '0.24.0'

An error occurred while installing mysql2 (0.3.20), and Bundler cannot continue.
Make sure that `gem install mysql2 -v ‘0.3.20’` succeeds before bundling.

#解决办法
# yum install mysql-community-devel.x86_64
# gem install mysql2 -v '0.3.20

An error occurred while installing pg (0.18.4), and Bundler cannot continue.
Make sure that `gem install pg -v ‘0.18.4’` succeeds before bundling.

#解决办法
# gem install pg -v '0.18.4'
# yum install postgresql-devel.x86_64

An error occurred while installing sqlite3 (1.3.13), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v ‘1.3.13’` succeeds before bundling.

# 解决办法
# yum install sqlite-devel.x86_64
# gem install sqlite3 -v '1.3.13'

Bundler::GemRequireError: There was an error while trying to load the gem ‘coffee-rails’.
Gem Load Error is: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes.

#解决办法:因为execjs需要javascript的支持
#参考这里:NodeJs的安装

初始化数据表

bundle exec rake db:setup RAILS_ENV=production

 制作启动文件

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

 三、配置

详细的配置参考官方文档:https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

中文官方文档:https://docs.gitlab.com.cn/omnibus/

gitLab的默认配置文件地址:/etc/gitlab/gitlab.rb,这是我目前见过最长的配置文件,哈哈!很完整。配置项的说明参考文章:gitlab中的配置参数

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>