CentOS 7.0 源码安装 Gitlab

前言:源码安装Gitlab其实并不推荐,既麻烦还容易出现问题,不是很推荐新手。推荐大家使用 docker 或者官方的一键包去安装。这里只是记录自己搭建的过程,亲测好用。


一、yum 安装依赖

CentOS 7 默认自带了 EPEL 源,如果没有的话请自行添加。

# run as root !!!
yum  update
yum install gcc ruby-devel libxml2 libxml2-devel libxslt libxslt-devel

二、安装 Ruby

先卸载自带的ruby

yum remove ruby

源码安装Ruby2.3.1版本

url --remote-name --progress https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz
tar xvzf ruby-2.3.1.tar.gz
cd ruby-2.3.1
./configure --disable-install-rdoc
make
make install

安装Bundler Gem (它是帮助管理ruby下的所有依赖的包,相当于yum的功能)

gem install bundler --no-ri --no-rdoc

更换ruby源,自带的源下载软件包太慢。更换为淘宝的。

gem sources --remove https://rubygems.org/
gem sources -a https://ruby.taobao.org/

三、安装GO(gitlab-workhorse需要用)

新版本的 gitlab 使用 HTTPS 方式去 clone 或者 push 代码的时候,需要用到 workhorse

curl --remote-name --progress https://storage.googleapis.com/golang/go1.5.3.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.5.3.linux-amd64.tar.gz
ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/

四、安装数据库

MySQL 已经不再包含在 CentOS 7 的源中,而改用了 MariaDB,先搜索 MariaDB 现有的包:

rpm -qa | grep mariadb

卸载

rpm -e --nodeps mariadb-*

安装MySQL

wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server
yum install mysql-community-devel

更改配置文件

vim /etc/my.cnf
[mysqld]
datadir=/data/mysql    //这个目录是单独创建的,请注意

初始化

mysql_install_db --user=mysql --datadir=/data/mysql/

设置root的密码和相关登录信息

# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y                  [设置root用户密码]
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y                 [删除匿名用户]
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y       [禁止root远程登录]
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y          [删除test数据库]
 - Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
 ... Failed!  Not critical, keep moving...
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y            [刷新权限]
 ... Success!




All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


Cleaning up...

创建一个gitlab用户,以及库,用来存储数据

mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab'; 
Query OK, 0 rows affected (0.00 sec) 
mysql> CREATE DATABASE IF NOT EXISTS `gitlab` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; 
Query OK, 1 row affected (0.01 sec) 
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlab`.* TO 'gitlab'@'localhost'; 
Query OK, 0 rows affected (0.00 sec) 
mysql> FLUSH PRIVILEGES; 
Query OK, 0 rows affected (0.00 sec)

启动mysql

service mysqld start

四、安装redis

先卸载自带的redis

yum remove redis

源码安装,安装包网上自行下载

tar zxvf redis-3.0.3.tar.gz
cd redis-3.0.3
make
make install

执行redis的安装脚本(不要一路回车,看清楚)

[root@gitlab redis-3.0.3]# ./utils/install_server.sh  Welcome to the redis service installer This script will help you easily set up a running redis server Please select the redis port for this instance: [6379]     
Selecting default: 6379 
Please select the redis config file name [/etc/redis/6379.conf] /etc/redis.conf Please select the redis log file name [/var/log/redis_6379.log] /var/log/redis.log Please select the data directory for this instance [/var/lib/redis/6379] /var/lib/redis.pid    
Please select the redis executable path [/usr/local/bin/redis-server]            Selected config: Port           : 6379 
Config file    : /etc/redis.conf 
Log file       : /var/log/redis.log 
Data dir       : /var/lib/redis.pid 
Executable     : /usr/local/bin/redis-server 
Cli Executable : /usr/local/bin/redis-cli 
Is this ok? Then press ENTER to go on or Ctrl-C to abort. 
Copied /tmp/6379.conf => /etc/init.d/redis_6379 
Installing service... 
Successfully added to chkconfig! 
Successfully added to runlevels 345! 
Starting Redis server... 
Installation successful!

更改redis的启动脚本,并启动服务

mv /etc/init.d/redis_6379 /etc/init.d/redis
service redis start

创建git用户

useradd --comment 'GitLab' git
echo "git ALL=(ALL)       NOPASSWD: ALL" >>/etc/sudoers

安装gitlab-shell

切换到git用户,clone新版gitlab-shell到git家目录中

su - git
git clone https://github.com/gitlabhq/gitlab-shell.git -b v3.6.1 gitlab-shell

将分支切换为v3.6.1

cd gitlab-shell
git checkout -b v3.6.1

提供配置文件,修改gitlab的URL地址

cp config.yml.example config.yml
vim config.yml
gitlab_url: "http://192.168.100.100/"
或者 gitlab_url: "http://git.test.com/"

进行安装操作

[git@gitlab~ gitlab-shell]$ ./bin/install  
mkdir -p /home/git/repositories: true
mkdir -p /home/git/.ssh: true chmod 700 /home/git/.ssh: true 
touch /home/git/.ssh/authorized_keys: true 
chmod 600 /home/git/.ssh/authorized_keys: true 
chmod -R ug+rwX,o-rwx /home/git/repositories: true 
find /home/git/repositories -type d -print0 | xargs -0 chmod g+s: true

安装gitlab

克隆gitlab的代码到git家目录

su - git 
cd
git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 8-10-stable gitlab

配置项目,提供配置文件

cd gitlab
cp config/gitlab.yml.example config/gitlab.yml

将localhost改为本机ip或者是域名

[git@gitlab ~]$ sed -i 's/localhost/192.168.100.100/g' config/gitlab.yml
或者
[git@gitlab ~]$ sed -i 's/localhost/git.test.com/g' config/gitlab.yml

修改目录的相关权限

[git@gitlab ~]$ chown -R git log/
[git@gitlab ~]$ chown -R git tmp/
[git@gitlab ~]$ chmod -R u+rwx log/
[git@gitlab ~]$ chmod -R u+rwx tmp/

[git@gitlab ~]$ mkdir /home/git/gitlab-satellites

#可以视为临时目录,通过web ui的提交请求文件以及检出版本库都会存放在这个位置

提供unicorn的配置

[git@gitlab ~]$ cp config/unicorn.rb.example config/unicorn.rb

修改unicorn的配置,指明监听的端口和超时时间

[git@gitlab ~]$ vim config/unicorn.rb
listen "192.168.100.100:2486", :tcp_nopush => true
timeout 300

配置git的用户和邮件

[git@gitlab ~]$ git config --global user.name "GitLab"
[git@gitlab ~]$ git config --global user.email "gitlab@test.com"
[git@gitlab ~]$ git config --global core.autocrlf input

配置数据库,使gitlab将数据存入到MySQL数据库中

[git@gitlab ~]$ cp config/database.yml.mysql config/database.yml
[git@gitlab ~]$ vim config/database.yml
production:
  adapter: mysql2
  encoding: utf8
  collation: utf8_general_ci
  reconnect: false
  database: gitlab
  pool: 10
  username: gitlab
  password: "gitlab"

这里注意一下,我的配置如下,如果host和socket的注释不打开,后面gem操作将会报错,会提示无法连接数据库。

image.png

修改目录权限,保证其他用户不能访问

[git@gitlab ~]$ chmod o-rwx config/database.yml

切回git用户

[root@gitlab ~]# su - git
[git@gitlab ~]$ cd gitlab

修改Gemfile文件,将gem源改成淘宝的源

[git@gitlab ~]$ vim Gemfile
source "https://ruby.taobao.org"

安装一些依赖包

[git@gitlab ~]$ bundle install --deployment --without development test postgres puma aws
...
Remember to run generator to generate sample file and include mousetrap-rails with Rails Asset Pipeline

    $ rails generate mousetrap:install

Post-install message from rdoc:
Depending on your version of ruby, you may need to install ruby rdoc/ri data:

<= 1.8.6 : unsupported
= 1.8.7 : gem install rdoc-data; rdoc-data --install
= 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!    #显示这个就代表安装基本成功了。

初始化gitlab

[git@gitlab ~]$ bundle exec rake gitlab:setup RAILS_ENV=production 
... 
This will create the necessary database tables and seed the database. 
You will lose any previous data stored in the database. Do you want to continue (yes/no)? yes 

Administrator account created: 

login.........root 
password......5iveL!fe      #默认的管理员密码

为gitlab提供启动脚本

# run as root  !!!
[root@gitlab ~]# wget -O /etc/init.d/gitlab https://raw.githubusercontent.com/gitlabhq/gitlab-recipes/master/init/sysvinit/centos/gitlab-unicorn --no-check-certificate
[root@gitlab ~]# chmod +x /etc/init.d/gitlab 
[root@gitlab ~]# chkconfig --add gitlab

启动gitlab服务

[root@gitlab ~]# service gitlab start

这就可以使用了,nginx配置一下 proxy_pass 反向代理,即可访问。


错误解决

1. nginx报错

2016/07/19 09:26:11 [crit] 3881#0: *10 connect() to unix:/home/git/gitlab/tmp/sockets/gitlab-workhorse.socket failed (13: Permission denied) while connecting to upstream, client: 192.168.1.180, server: www.gitlab810.com, request: "GET / HTTP/1.1", upstream: "http://unix:/home/git/gitlab/tmp/sockets/gitlab-workhorse.socket:/", host: "www.gitlab810.com"
2016/07/19 09:26:11 [error] 3881#0: *10 open() "/home/git/gitlab/public/502.html" failed (13: Permission denied), client: 192.168.1.180, server: www.gitlab810.com, request: "GET / HTTP/1.1", upstream: "http://unix:/home/git/gitlab/tmp/sockets/gitlab-workhorse.socket/", host: "www.gitlab810.com"

这是因为我的nginx使用的是www用户运行,而/home/git/gitlab/tmp/sockets/gitlab-workhorse.socket/用户组是git,

解决方案:把git加入www用户组,并赋予实行权限

usermod -a -G git www
chmod g+rx /home/git/

2. 在进行到Install Gems时出错:Make sure that gem install RedCloth -v '4.2.9' succeeds before bundling

gem install RedCloth -v '4.2.9'

又出现新问题:can’t find header files for ruby at /usr/lib/ruby/include/ruby.h

apt-get install ruby-dev

3. Make sure that gem install charlock_holmes -v '0.7.3' succeeds before

gem install charlock_holmes -v '0.7.3'

ERROR: Error installing charlock_holmes: ERROR: Failed to build gem native extension.

apt-get install libicu-dev

4. Make sure that gem install mysql2 -v '0.3.20' succeeds before bundling

gem install mysql2 -v '0.3.20'

libmysqlclient is missing. You may need to ‘apt-get install libmysqlclient-dev’

aptitude install libmysqlclient-dev

参考文档

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,670评论 5 460
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,928评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,926评论 0 320
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,238评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,112评论 4 356
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,138评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,545评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,232评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,496评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,596评论 2 310
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,369评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,226评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,600评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,906评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,185评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,516评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,721评论 2 335

推荐阅读更多精彩内容