Centos 6.5上构建Git Lab服务及问题总结

前言:

官方上面说并不推荐在CentOS上面安装GitLab,无奈公司的服务器都是CentOS的系统.....

不过,好在经历了三天才算把GitLab搭建起来,查了N多参考教程,发现一个问题,并不是每个教程都是通用的、总会遇到某些未知的错误是其他作者没有碰到的,毕竟每台服务器的环境是不一样的,问题百出,很是让人很是头痛。

下面总结了自己在CentOS搭建GitLab的教程以及某些错误的解决办法,算是对自己的总结吧!或许那天就用到了......

-----------------------------------------------------------------------------------------

——安装前准备工作

1)添加epel源

[[email protected] ~]# mkdir /tmp/soft/
[[email protected] ~]# cd /tmp/soft/
[[email protected] soft]# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[[email protected] soft]# rpm -ivh epel-release-6-8.noarch.rpm
warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing...                ########################################### [100%]
   1:epel-release           ########################################### [100%]

2)配置epel源

[epel]
name=Extra Packages for Enterprise Linux 6 - $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)执行yum makecache 更新

[[email protected] soft]# yum makecache
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                         | 3.7 kB     00:00
base/group_gz                                                                                                                | 220 kB     00:00
base/filelists_db                                                                                                            | 5.9 MB     00:03
base/other_db                                                                                                                | 2.8 MB     00:01
epel                                                                                                                         | 4.4 kB     00:00
epel/group_gz                                                                                                                | 237 kB     00:05
epel/filelists_db                                                                                                            | 8.4 MB     05:56
epel/primary_db                                                                                                              | 6.1 MB     03:36
epel/other_db                                                                                                                | 3.6 MB     01:22
epel/updateinfo                                                                                                              | 780 kB     00:11
extras                                                                                                                       | 3.4 kB     00:00
extras/filelists_db                                                                                                          |  11 kB     00:00
extras/prestodelta                                                                                                           |  907 B     00:00
extras/other_db                                                                                                              | 5.8 kB     00:00
mariadb                                                                                                                      | 1.9 kB     00:00
mariadb/filelists_db                                                                                                         |  47 kB     00:01
mariadb/primary_db                                                                                                           |  15 kB     00:00
mariadb/other_db                                                                                                             | 1.2 kB     00:00
updates                                                                                                                      | 3.4 kB     00:00
updates/filelists_db                                                                                                         | 1.7 MB     00:01
updates/prestodelta                                                                                                          | 249 kB     00:00
updates/primary_db                                                                                                           | 2.6 MB     00:02
updates/other_db                                                                                                             |  21 MB     00:15
epel/pkgtags                                                                                                                 | 1.0 MB     00:36
Metadata Cache Created

4)安装软件所需依赖包

[[email protected] soft]# yum -y install yum -y install readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel expat-devel db4-devel byacc sqlite-devel libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui python-devel redis wget crontabs logwatch logrotate perl-Time-HiRes git gettext-devel libel openssl-devel zlib-devel gcc gcc-c++ make autoconf readline-devel expat-devel gettext-devel tk-devel  libxml2-devel libffi-devel libxslt-devel libicu-devel python-pip sqlite-devel  patch libyaml* pcre-devel

——安装Git Server

[[email protected] soft]# yum -y install git perl-ExtUtils-MakeMaker
[[email protected] soft]# git clone git://github.com/git/git
Initialized empty Git repository in /tmp/soft/git/.git/
remote: Counting objects: 171891, done.
remote: Compressing objects: 100% (46560/46560), done.
remote: Total 171891 (delta 123695), reused 171404 (delta 123322)
Receiving objects: 100% (171891/171891), 60.16 MiB | 571 KiB/s, done.
Resolving deltas: 100% (123695/123695), done.
[[email protected] soft]# cd git/
[[email protected] git]# git checkout v1.9.2
[[email protected] git]# autoconf
[[email protected] git]# make prefix=/usr/local/git all
[[email protected] git]# make prefix=/usr/local/git install
[[email protected] git]# yum erase git
[[email protected] git]# ln -s /usr/local/git/bin/* /usr/bin/
[[email protected] git]# git --version
git version 1.9.2            #表示安装成功
#删除git安装包
[[email protected] git]# cd ..
[[email protected] soft]# rm -rf git/

——安装配置ruby

1)下载ruby

[[email protected] soft]# wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.1.tar.gz

2)编译安装ruby

[[email protected] soft]# tar zfvx ruby-2.1.1.tar.gz
[[email protected] soft]# cd ruby-2.1.1
[[email protected] ruby-2.1.1]# ./configure
[[email protected] ruby-2.1.1]# make && make install
#安装bundler需要添加rubygems的国内镜像
[[email protected] ruby-2.1.1]# gem sources --remove https://rubygems.org/
[[email protected] ruby-2.1.1]# gem source -a http://ruby.taobao.org/
[[email protected] ruby-2.1.1]# gem sources -l
*** CURRENT SOURCES ***
http://ruby.taobao.org/
[[email protected] ruby-2.1.1]# gem install bundler
Fetching: bundler-1.6.2.gem (100%)
Successfully installed bundler-1.6.2
Parsing documentation for bundler-1.6.2
Installing ri documentation for bundler-1.6.2
Done installing documentation for bundler after 2 seconds
1 gem installed
[[email protected] ruby-2.1.1]# ln -s /usr/local/bin/ruby /usr/bin/ruby
[[email protected] ruby-2.1.1]# ln -s /usr/local/bin/gem /usr/bin/gem
[[email protected] ruby-2.1.1]# ln -s /usr/local/bin/bundle /usr/bin/bundle

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

#之前已经搭建过Git Server不需要再次创建Git用户
[[email protected] ruby-2.1.1]# adduser --comment ‘GitLab‘ git
[[email protected] ruby-2.1.1]# passwd git
#为了方便添加git用户拥有root权限 [sudoers文件默认没有写权限需要强制保存:wq!]
[[email protected] ruby-2.1.1]# vi /etc/sudoers
git     ALL=(ALL)       ALL
[[email protected] ruby-2.1.1]# chmod -R 755 /home/git
[[email protected] ruby-2.1.1]# vi /home/git/.bash_profile
export GIT_SSL_NO_VERIFY=1
[[email protected] ruby-2.1.1]# source /home/git/.bash_profile
#不添加变量的话使用https链接会报如下错误
fatal: unable to access ‘https://github.com/gitlabhq/grit.git/‘: Peer certificate cannot be authenticated with known CA certificates

4)安装GitLab的Shell

[[email protected] git]# su - git
#克隆gitlab的shell
[[email protected] ~]$ git clone https://gitlab.com/gitlab-org/gitlab-shell.git -b v1.8.0
正克隆到 ‘gitlab-shell‘...
remote: Reusing existing pack: 1222, done.
remote: Total 1222 (delta 0), reused 0 (delta 0)
接收对象中: 100% (1222/1222), 218.70 KiB | 16.00 KiB/s, done.
处理 delta 中: 100% (620/620), done.
检查连接... 完成。
[[email protected] ~]$ cd gitlab-shell/
[[email protected] gitlab-shell]$ cp config.yml.example config.yml
[[email protected] gitlab-shell]$ vi config.yml
#自己的gitlab域名
gitlab_url: "http://git.test.com/"
#完成配置
[[email protected] 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

5)建立gitlab数据库并授权

[[email protected] gitlab-shell]$ mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.36-MariaDB-wsrep MariaDB Server, wsrep_25.9.r3961
Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MariaDB [(none)]> CREATE USER ‘gitlab‘@‘localhost‘ IDENTIFIED BY ‘gitlab‘;
Query OK, 0 rows affected (0.20 sec)
MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
Query OK, 1 row affected (0.11 sec)
MariaDB [(none)]> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO ‘gitlab‘@‘localhost‘;
Query OK, 0 rows affected (0.06 sec)
MariaDB [(none)]> quit
Bye

6)克隆GitLab源

[[email protected] gitlab-shell]$ cd ..
[[email protected] ~]$ git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-4-stable gitlab
正克隆到 ‘gitlab‘...
remote: Reusing existing pack: 77202, done.
remote: Counting objects: 67, done.
remote: Compressing objects: 100% (65/65), done.
remote: Total 77269 (delta 25), reused 1 (delta 0)
接收对象中: 100% (77269/77269), 75.26 MiB | 241.00 KiB/s, done.
处理 delta 中: 100% (53687/53687), done.
[[email protected] ~]$ cd gitlab
[[email protected] gitlab]$ cp config/gitlab.yml.example config/gitlab.yml
[[email protected] gitlab]$ vi config/gitlab.yml
## GitLab settings
gitlab:
## Web server settings
  host: git.test.com
  port: 80
  https: false
[[email protected] gitlab]$ chown -R git log/
[[email protected] gitlab]$ chown -R git tmp/
[[email protected] gitlab]$ chmod -R u+rwX  log/
[[email protected] gitlab]$ chmod -R u+rwX  tmp/
[[email protected] gitlab]$ mkdir tmp/pids/
[[email protected] gitlab]$ mkdir tmp/sockets/
[[email protected] gitlab]$ chmod -R u+rwX  tmp/pids/
[[email protected] gitlab]$ chmod -R u+rwX  tmp/sockets/
[[email protected] gitlab]$ mkdir public/uploads
[[email protected] gitlab]$ chmod -R u+rwX  public/uploads
[[email protected] gitlab]$ cp config/unicorn.rb.example config/unicorn.rb
[[email protected] gitlab]$ cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
[[email protected] gitlab]$ git config --global user.name "GitLab"
[[email protected] gitlab]$ git config --global user.email "[email protected]"
[[email protected] gitlab]$ git config --global core.autocrlf inpu

7)配置gitlab数据库

[[email protected] gitlab]$ cp config/database.yml.mysql config/database.yml
[[email protected] gitlab]$ vi config/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

[[email protected] gitlab]$sudo gem install charlock_holmes --version ‘0.6.9‘
Fetching: charlock_holmes-0.6.9.gem (100%)
Building native extensions.  This could take a while...
Successfully installed charlock_holmes-0.6.9
Parsing documentation for charlock_holmes-0.6.9
Installing ri documentation for charlock_holmes-0.6.9
Done installing documentation for charlock_holmes after 0 seconds
1 gem installed
[[email protected] gitlab]$ vi Gemfile
source "https://rubygems.org"改为source "http://rubygems.org"
[[email protected] gitlab]$ bundle install --deployment --without development test postgres
Fetching source index from http://rubygems.org/
Fetching https://github.com/gitlabhq/grit.git
Could not find modernizr-2.6.2 in any of the sources
#出现错误:Could not find modernizr-2.6.2 in any of the sources
#解决办法:
[[email protected] gitlab]$ vi Gemfile
第114行   gem "modernizr",        "2.6.2"
更改改为:
第114行   gem "modernizr-rails",  "2.7.1"
[[email protected] gitlab]$ vi Gemfile.lock
第252行     modernizr (2.6.2)
更改改为:
第252行     modernizr-rails (2.7.1)
第523行   modernizr (= 2.6.2)
更改改为:
第523行   modernizr-rails (= 2.7.1)
#重新执行:
[[email protected] gitlab]$ bundle install --deployment --without development test postgres puma aws

9)启动redis

[[email protected] gitlab]$ sudo /etc/init.d/redis start
启动 :[确定]
[[email protected] gitlab]$ sudo chkconfig redis on

10)对数据库进行初始化

[[email protected] gitlab]$ bundle exec rake gitlab:setup RAILS_ENV=production --verbose
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:
[email protected]
password......5iveL!fe

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

[[email protected] gitlab]$ bundle exec rake gitlab:env:info RAILS_ENV=production
System information
System:         CentOS release 6.5 (Final)
Current User:   git
Using RVM:      no
Ruby Version:   2.1.1p76
Gem Version:    2.2.2
Bundler Version:1.6.2
Rake Version:   10.0.4
GitLab information
Version:        5.1.0
Revision:       be39106
Directory:      /home/git/gitlab
DB Adapter:     mysql2
URL:            http://localhost
HTTP Clone URL: http://localhost/some-project.git
SSH Clone URL:  [email protected]:some-project.git
Using LDAP:     no
Using Omniauth: no
GitLab Shell
Version:        1.3.0
Repositories:   /home/git/repositories/
Hooks:          /home/git/gitlab-shell/hooks/
Git:            /usr/bin/git
[[email protected] gitlab]$ bundle exec rake sidekiq:start RAILS_ENV=production
rake aborted!
SIGTERM
/home/git/gitlab/lib/tasks/sidekiq.rake:9:in `system‘
/home/git/gitlab/lib/tasks/sidekiq.rake:9:in `block (2 levels) in <top (required)>‘
Tasks: TOP => sidekiq:start
(See full trace by running task with --trace)
[[email protected] gitlab]$ bundle exec rake gitlab:check RAILS_ENV=production

Checking Environment ...
Git configured for git user? ... yes
Has python2? ... yes
python2 is supported version? ... yes
Checking Environment ... Finished
Checking Gitlab Shell ...
GitLab Shell version? ... OK (1.3.0)
Repo base directory exists? ... yes
Repo base directory is a symlink? ... no
Repo base owned by git:git? ... yes
Repo base access is drwxrws---? ... yes
post-receive hook up-to-date? ... yes
post-receive hooks in repos are links: ... can‘t check, you have no projects
Checking Gitlab Shell ... Finished
Checking Sidekiq ...
Running? ... yes
Checking Sidekiq ... Finished
Checking GitLab ...
Database config exists? ... yes
Database is SQLite ... no
All migrations up? ... yes
GitLab config exists? ... yes
GitLab config outdated? ... no
Log directory writable? ... yes
Tmp directory writable? ... yes
Init script exists? ... no
  Try fixing it:
  Install the init script
  #原文说明不用介意这个问题
  For more information see:
  doc/install/installation.md in section "Install Init Script"
  Please fix the error above and rerun the checks.
Init script up-to-date? ... can‘t check because of previous errors
Projects have satellites? ... can‘t check, you have no projects
Redis version >= 2.0.0? ... yes
Checking GitLab ... Finished

11)下载启动脚本

[[email protected] gitlab]$ sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/init/sysvinit/centos/gitlab-unicorn -P /etc/init.d/
[[email protected] gitlab]$ sudo mv /etc/init.d/gitlab-unicorn /etc/init.d/gitlab
[[email protected] gitlab]$ sudo chmod +x /etc/init.d/gitlab
[[email protected] gitlab]$ sudo chkconfig --add gitlab
[[email protected] gitlab]$ sudo chkconfig gitlab on
[[email protected] gitlab]$ sudo /etc/init.d/gitlab start

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

[[email protected] gitlab]$ cp lib/support/nginx/gitlab /usr/local/nginx/conf/conf.d/
[[email protected] gitlab]$ cd /usr/local/nginx/conf/conf.d/
[[email protected] gitlab]$ sudo chown -R git:git .
[[email protected] conf.d]$ cp gitlab gitlab.conf
[[email protected] conf.d]$ vi gitlab.conf
upstream gitlab {
  server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
}
server {
  listen *:80 default_server;         # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea
  server_name git.test.com;     # e.g., server_name source.example.com;
  server_tokens off;     # don‘t show the version number, a security best practice
  root /home/git/gitlab/public;
  client_max_body_size 5m;
  access_log  logs/gitlab_access.log;
  error_log   logs/gitlab_error.log;
  location / {
    try_files $uri $uri/index.html $uri.html @gitlab;
  }
  location @gitlab {
    proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_redirect     off;
    proxy_set_header   X-Forwarded-Proto $scheme;
    proxy_set_header   Host              $http_host;
    proxy_set_header   X-Real-IP         $remote_addr;
    proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
    proxy_pass http://gitlab;
  }
}
[[email protected] conf.d]$ sudo service nginx restart

13)拉取GitLab静态文件

[[email protected] conf.d]$ cd /home/git/gitlab
[[email protected] gitlab]$ bundle exec rake assets:precompile RAILS_ENV=production
[[email protected] gitlab]$ sudo service gitlab restart

14)访问测试

初始管理员帐号和密码为:
[email protected]
5iveL!fe

登陆成功后如下:

Centos 6.5上构建Git Lab服务及问题总结

时间: 2024-12-25 16:07:27

Centos 6.5上构建Git Lab服务及问题总结的相关文章

在CentOS 5.8上搭建PPTP VPN服务

在天朝上网,vpn已经是必备之物了,我也记录一下搭建vpn服务的方法. 1. 确认内核是否支持MPPE模块MPPE用来支持Microsoft Point to Point Encryption, 包括微软和Linux桌面都支持MPPE modprobe ppp-compress-18 && echo ok 2. 安装ppp软件包pptp是使用ppp协议对数据进行封装的,然后将ppp数据帧封装在ip数据报文中. yum install ppp 3. 安装pptp软件包下载32位rpm包: w

centos上搭建git服务--3

前言:当我们想要实现几个小伙伴合作开发同一个项目,或者建立一个资源分享平台的时候,GIT就是一个很好的选择.当然,既然是一个共有平台,那么把这个平台放到个人计算机上明显是不合适的,因此就要在服务器上搭建GIT了.另一个需求是,我们在本地开发,然后推送到服务器上,并且自动同步到web站点目录,这样就可以直接看到网页效果了,这就要实现自动同步.下面我带领大家实现这么一个功能. 如果条件允许的话,大家可以跟着做的(注:我的服务器是centos 7,lamp环境). 一.在服务器上安装git: //yu

Centos上搭建git服务

1.安装Git $ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel $ yum install git 接下来我们 创建一个git用户组和用户,用来运行git服务: $ groupadd git $ adduser git -g git 2.创建证书登录 收集所有需要登录的用户的公钥,公钥位于id_rsa.pub文件中,把我们的公钥导入到/home/git/.ssh/auth

CentOS 7.2安装Jenkins自动构建Git项目

1.环境 本文使用VMWare虚拟机进行实验. 最终实现目标,在Jenkins服务器上新建构建任务,从Git服务器上拉取master HEAD(不编译,仅演示),部署到"目标服务器",再执行一个脚本. Jenkins服务器 2核CPU,4GB内存,20GB硬盘,IP:192.168.118.145(要求能上网,装插件) CentOS 7.2最小安装(CentOS-7-x86_64-Minimal-1511.iso) Git远程库服务器 IP: 192.168.118.148 已经存在一

在CentOS 7上构建RAID5、LVM和SAMBA服务器(5)——架设SAMBA服务器

在CentOS 7上构建RAID5.LVM和SAMBA服务器(5)--架设SAMBA服务器 6. 架设SAMBA服务器 6.1. 预备 本节的任务是配置SAMBA服务,共享/home/shared目录,使指定的Windows用户可以远程访问该共享. 首先要在CentOS上运行yum命令安装SAMBA服务: yum install samba 安装之后,执行systemctl命令来启动smb和nmb两个samba的守护进程. 图37 启动SAMBA 6.2. 修改smb.conf文件 修改/etc

centos上安装git

按照这篇文章 安装依赖: yum install curl yum install curl-devel yum install zlib-devel yum install openssl-devel yum install perl yum install cpio yum install expat-devel yum install gettext-devel 下载git源码包: https://github.com/git/git/releases 安装: cd /git源码包解压路径

在CentOS 7系统上架设DNS服务

文档说明: 本文档以一个案例来介绍如何在CentOS 7系统上部署DNS服务.该案例仅是我对如何部署DNS服务的知识总结,并非是生产环境中存在的案例.并且,该案例中用到的CentOS系统均是安装在VMware虚拟机内的,虽然一般情况下这不会有什么不妥,但还是特别说明一下. 案例说明: 本案例使用了两台VMware虚拟机.两台虚拟机上均安装CentOS 7(详细版本号为7.0.1406,核心版本号为3.10.0-123.el7.x86_64),其中一台虚拟机用于模拟Master DNS服务器(假设

CentOS服务器上的 git 包版本控制

本文衔接上文"记录一次无聊的(经历了Nodejs -> Shell -> C)的探索问题过程",服务器上git版本是1.8.3.1,使用的pm2来管理nodejs进程,并且配置了一键deploy项目.在deploy执行过程中,新版本的pm2 => pm2-deploy的shell中没对git老版本做兼容,上文提到解决方案: 1. pm2-deploy做兼容,相关shell例子也已给出 2. 升级服务器git版本 本文围绕一次 git 升级操作展开,并且分享此次过程的操

在 CentOS 6.x 上安装最新版本的 git

在 CentOS 的默认仓库中有git,所以最简单的方法是: $ sudo yum install git 这种方法虽然简单,但是一般仓库里的版本更新不及时,比如 CentOS 仓库中的 git 最新版是1.7.1(今天是2014-10-28),但是 git 官方已经到2.x 的版本了. 这时,就不得不动用最终的大杀器了,通过自己编译源码安装. 步骤如下: 1. 需要给 CentOS 下载安装编译工具. $ sudo yum groupinstall “Development Tools” 2.