GitLab,是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。

它拥有与GitHub类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。

一、安装源和依赖包

$ cd /usr/local/src

#增epel源,如果你是i686系统,请把x86_64修改下。

$ wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6  https://www.fedoraproject.org/static/0608B895.txt

$ rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

$ rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

二、确认是否安装成功

$ rpm -qa gpg*

gpg-pubkey-0608b895-4bd22942

三、安装依赖包

$ yum -y update

$ yum -y groupinstall 'Development Tools'

$ yum -y install readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-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 redis sudo wget crontabs logwatch logrotate perl-Time-HiRes  cmake libcom_err-devel.i686 libcom_err-devel.x86_64

四、编译安装git

$ cd /usr/local/src

$ wget https://www.kernel.org/pub/software/scm/git/git-2.4.5.tar.gz

$ yum install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-devel openssl-devel

$ yum remove git -y

$ tar xf git-2.4.5.tar.gz

$ cd git-2.4.5

$ ./configure --prefix=/usr/local/git

$ make;make install

五、安装ruby,ruby版本需要2.0+,所以先卸载系统已存在的

$ yum remove ruby

$ cd /usr/local/src

$ wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.6.tar.gz

$ tar xf ruby-2.1.6.tar.gz

$ cd ruby-2.1.6 && ./configure --prefix=/usr/local/ --disable-install-rdoc && make && make  install

六、完成后验证ruby

$which ruby

/usr/local/bin/ruby

$ruby -v

ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]

七、安装bundler

Gem是一个管理Ruby库和程序的标准包,它通过Ruby Gem(如 http://rubygems.org/ )源来查找、安装、升级和卸载软件包,非常的便捷

由于国内网络原因(你懂的),导致 rubygems.org 存放在 Amazon S3 上面的资源文件间歇性连接失败。所以你会与遇到 gem install rack 或 bundle install 的时候半天没有响应,具体可以用 gem install rails -V 来查看执行过程

将ruby默认的gem源替换成淘宝的既可以正常安装软件

$ gem sources --remove https://rubygems.org/

$ gem sources -a https://ruby.taobao.org/

$ gem sources -l

$ gem install bundler --no-doc

八、创建git需要的系统用户

useradd git

九、安装mysql

$ yum install -y mysql-server mysql-devel

$ chkconfig mysqld on

$ service mysqld start

十、创建git数据库用户

mysql> CREATE USER 'git'@'localhost' IDENTIFIED BY 'gitpwd';

十一、创建git需要的数据库、并授权一个连接git数据库的用户

mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;

mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq`.* TO 'git'@'localhost';

mysql> flush privileges;

十二、配置redis,

前面安装依赖包的时候已经使用yum把redis安装好了。

$ chkconfig redis on

$ cp /etc/redis.conf /etc/redis.conf.orig

修改redis监听端口

sed 's/^port .*/port 0/' /etc/redis.conf.orig |tee /etc/redis.conf

配置redis,增加redis配置内容

$ echo 'unixsocket /var/run/redis/redis.sock' |tee -a /etc/redis.conf

$ echo -e 'unixsocketperm 0770' |tee -a /etc/redis.conf

修改redis目录权限

$ chown redis:redis /var/run/redis

$ chmod 755 /var/run/redis

启动redis服务

$service redis restart

附加git到redis组

usermod -aG redis git

十三、安装gitlab配置

$ cd /home/git

#添加下面内容,不验证SSL,否则 git clone 时会出现错误 Peer certificate cannot be authenticated with known CA certificates

$ vi /home/git/.bash_profile

export GIT_SSL_NO_VERIFY=1

#下载源码,安装Gitlab

$ su - git

$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab

#修改配置,并修改gitlab配置文件

$ cd gitlab/

$ cp config/gitlab.yml.example config/gitlab.yml

$ vim  config/gitlab.yml

gitlab:

## Web server settings (note: host is the FQDN, do not include http://)

host: 121.413.102.123          //这里的ip是你利用http或者ssh访问git的时候地址

port: 80                    //http方式访问git的端口

https: false

time_zone: 'Beijing'        //将时区改为北京

git:

#bin_path: /usr/bin/git

bin_path: /usr/local/git/bin/git

#创建目录,配置unicorn

$ mkdir /home/git/gitlab-satellites

$ chmod 750 /home/git/gitlab-satellites

$ cp config/unicorn.rb.example config/unicorn.rb

#修改unicorn配置文件,特别注意:比较差配置的机器,注意将unicorn.rb中的timeout设置大一点,因为第一次启动的时候Gitlab需要初始化,如果timeout太小,由于需要执行较长时间,导致无法正常启动,出现502错误

$ vim config/unicorn.rb

worker_processes 4

#拷贝配置文件rack_attack.rb

$ cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

#定义全局的用户和邮箱,会将配置写入到gitlab.yml配置文件

$ git config --global user.name "GitLab"

$ git config --global user.email "example@example.com"

$ git config --global core.autocrlf input

#编辑连接redis配置,拷贝配置

$ cp config/resque.yml.example config/resque.yml

#配置gitlab数据库文件

$ cp config/database.yml.mysql config/database.yml

#编辑git连接数据库配置文件

$ vim config/database.yml

production:

adapter: mysql2

encoding: utf8

collation: utf8_general_ci

reconnect: false

database: gitlabhq

pool: 10

username: git

password: "gitpwd"

host: localhost

socket: /var/lib/mysql/mysql.sock

#修改文件权限,只有git用户可读

chmod 660 config/database.yml

十四、安装gem

#修改gemfile配置,改为淘宝的ruby源,修改为

cd /home/git/gitlab

$ vi Gemfile

source 'https://ruby.taobao.org/'

#执行命令,这一步的时间会等很久

$ bundle install --deployment --without development test postgres aws

十五、安装gitlab-shell

$ yum install nodejs

$ su  -  git

$ cd  /home/git/

$ git clone https://github.com/gitlabhq/gitlab-shell.git

$ cd gitlab-shell

$ mkdir /home/git/repositories

$ cp config.yml.example config.yml

#修改gitlab-shell配置文件

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

user: git

gitlab_url: "http://121.413.102.123 "

http_settings:

self_signed_cert: true

repos_path: "/home/git/repositories/"

auth_file: "/home/git/.ssh/authorized_keys"

redis:

bin: "/usr/bin/redis-cli"

namespace: resque:gitlab

socket: "/var/run/redis/redis.sock"

log_level: INFO

audit_usernames: false

十六、初始化数据库

$ cd /home/git/gitlib

bundle exec rake gitlab:setup RAILS_ENV=production

#可以设置管理员密码(此步骤可省略。。。)

$ bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=newpassword

十七、下载服务脚本,退出git用户使用root用户执行下面的命令

$ exit

$ wget -O /etc/init.d/gitlab  https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/init/sysvinit/centos/gitlab-unicorn

$ chmod +x /etc/init.d/gitlab

$ chkconfig --add gitlab

$ chkconfig gitlab on

#设置logrotate

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

#检测应用状态

$ bundle exec rake gitlab:env:info RAILS_ENV=production

System information

System:          CentOS 6.6

Current User:     root

Using RVM:     no

Ruby Version:     2.1.6p336

Gem Version:     2.2.3

Bundler Version:1.10.5

Rake Version:     10.4.2

Sidekiq Version:3.3.0

GitLab information

Version:     7.13.0.pre

Revision:     32330e8

Directory:     /home/git/gitlab

DB Adapter:     mysql2

URL:          http://121.43.102.23:8080

HTTP Clone URL:     http://121.413.102.123:8080/some-project.git

SSH Clone URL:     git@121.413.102.123 :some-project.git

Using LDAP:     no

Using Omniauth:     no

GitLab Shell

Version:     2.6.3

Repositories:     /home/git/repositories/

Hooks:          /home/git/gitlab-shell/hooks/

Git:          /usr/bin/git

#执行命令

$ bundle exec rake assets:precompile RAILS_ENV=production

#启动gitlab服务

$ service gitlab start

十八,配置gitlab 的web服务

$ yum -y install nginx

$ chkconfig nginx on

#下载gitlab配置文件,不使用SSL

$ wget -O /etc/nginx/conf.d/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab --no-check-certificate

#编辑gitlab配置文件

$ vi /etc/nginx/conf.d/gitlab.conf

  listen 0.0.0.0:80 default_server;     //设置登陆gitlab 的登陆端口。

#listen [::]:80 default_server;

#server_name YOUR_SERVER_FQDN; ## Replace this with something like gitlab.example.com

  server_name 121.413.102.123 ; #修改为本机ip

  server_tokens off; ## Don't show the nginx version number, a security best practice

  root /home/git/gitlab/public;

## Increase this if you want to upload large attachments

## Or if you want to accept large git objects over http

#client_max_body_size 20m;

  client_max_body_size 256m;     //修改为256

#添加nginx用户到git组

$ usermod -a -G git nginx

$ chmod g+rx /home/git/

#启动nginx服务

service nginx start

#修改gitlab_url为nginx中配置的相应端口

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

gitlab_url: "http://121.413.102.123"

#新建软连接。否则客户端在clone的时候报错

$ ln -s /usr/local/git/bin/git-receive-pack /usr/bin/

$ ln -s /usr/local/git/bin/git-upload-pack  /usr/bin/

#gitlab邮件服务设置文件。

$cd /home/git/gitlab/config/initializers/

$cp smtp_settings.rb.sample smtp_settings.rb

十九、访问gitlab,系统默认admin但是我用默认密码我登录不了,这里我自己注册了用户名,注册完密码是通过邮件发送的。

#用户名:xx

#密码:xx

二十、至此gitlab安装完成,登录到gitlab上面可以进行项目的创建、用户的添加、删除、权限分配。

问题总结

1、服务端新建好用户后无法通过ssh方式访问git服务器

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

auth_file: "/home/git/.ssh/authorized_keys"

检查git服务端上面有没有这个文件,然后检查用户的公钥有没有自动写入到这个文件里面,如果没有ssh目录和authorized_keys文件需要手动创建,目录权限为600

参考链接:

http://fighter.blog.51cto.com/1318618/1678308

http://www.centoscn.com/CentosServer/test/2015/0211/4692.html

http://www.restran.net/2015/04/09/gilab-centos-installation-note/

http://dl528888.blog.51cto.com/2382721/1213286

Centos6.5_x64-GitLab搭建私有GitHub的更多相关文章

  1. GitLab → 搭建私有的版本控制的托管服务平台

    开心一刻 睡着正香,媳妇用力把我晃醒说:“快起来,我爸来了.” 我一下醒了,手脚熟练的把衣服一抱,滚到床底,顺便把鞋也收了进去 媳妇蹲下无奈的说:“快出来!咱俩都结婚半年了.” 我:“对哦,搞习惯了” ...

  2. Ubuntu18.04安装GitLab搭建私有仓库服务器过程笔记

      百度了很多资料结果折腾很久还没安装成功,索性就直接上官网找文档参考顺利搭建完成 因为有2台服务器做练习,总结了2种安装方式提供参考:第一种官网安装方式,第二种国内镜像安装方式(建议采用第二种) 第 ...

  3. 【centos6.6环境搭建】Github unable to access SSL connect error出错处理

    问题 克隆github项目出现SSL connect error git clone https://github.com/creationix/nvm Cloning into 'nvm'... f ...

  4. composer使用gitlab搭建私有库

    { "repositories": [ { "type": "vcs", // 使用gitlab固定 "url": &q ...

  5. 用GitLab搭建自己的私有GitHub

    相信很多技术人员都知道有个github造福开发人员的git(分布式版本管理工具)代码管理社区,可以说现在git是开发人员的必备技能之一 本周有个朋友公司需要一个类似github的代码仓库管理系统,本人 ...

  6. GitLab → 搭建中常遇的问题与日常维护

    开心一刻 隔壁有一个80多岁的老大爷,昨天在小区的一棵树下发现一条黑色的蛇,冻僵了,大爷善心大发,就把蛇揣在了怀里,想给它一点温暖. 今天一大早看到大爷在树上挂了一个牌子,写到:不准随地大小便! 搭建 ...

  7. Jenkins+Gitlab搭建持续集成(CI)环境

    利用Jenkins+Gitlab搭建持续集成(CI)环境 Permalink: 2013-09-08 22:04:00 by hyhx2008in intern tags: jenkins gitla ...

  8. gitlab搭建与基本使用【转】

    一.git.github.gitlab的区别Git是版本控制系统,Github是在线的基于Git的代码托管服务.GitHub是2008年由Ruby on Rails编写而成.GitHub同时提供付费账 ...

  9. 在阿里云上搭建私有GIT仓库

    在阿里云上搭建私有GIT仓库 年轻人就得好好学习,不能这么颓废 最近做项目练练手,用到了github, 但是github访问速度是真的慢啊,下载项目,下载一天了.所以呢,我是个成熟的人了,只好自己搭建 ...

随机推荐

  1. openjudge dp水题记录

    当发现自己竟然不会打dp的时候内心是崩溃的,然后按照一年前的刷题记录刷openjudge,然后发现自己准确率比一年前(刚学信竞两个月时)的准确率低得多,已经没救. 列一下最近打的几道sb题 2985: ...

  2. 【JZOJ4889】【NOIP2016提高A组集训第14场11.12】最长公共回文子序列

    题目描述 YJC最近在学习字符串的有关知识.今天,他遇到了这么一个概念:最长公共回文子序列.一个序列S,如果S是回文的且分别是两个或多个已知序列的子序列,且是所有符合此条件序列中最长的,则 S 称为已 ...

  3. 在Swift中检查API的可用性

    http://www.cocoachina.com/swift/20150901/13283.html 本文由CocoaChina译者ALEX吴浩文翻译自Use Your Loaf博客 原文:Chec ...

  4. phpcms分类信息地区识别跳转

    <script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js"></scri ...

  5. python 不定长参数**kwargs

  6. BZOJ1878 洛谷1972 HH的项链题解

    洛谷链接 BZOJ链接 看到这样不用修改的题目,应该佷容易就联想到了离线来处理. 我们发现若将询问按照r来排序,排完后每次对答案有贡献的仅是每个颜色最后出现的位置 我们用next[i]表示i处颜色之前 ...

  7. 微服务开源生态报告 No.2

    通常,我们都会通过在 GitHub 上订阅邮件列表,来了解社区动态.这一次,我们联合以上各开源项目的负责人,发布「微服务开源生态报告」,汇集各个开源项目近期的社区动态,帮助开发者们更高效的了解到各开源 ...

  8. 直击 KubeCon 现场 | 阿里云 Hands-on Workshop 亮点回顾

    相关文章链接[合集]规模化落地云原生,阿里云亮相 KubeCon China沉淀九年,一文看清阿里云原生大事件 2019 年 6 月 24 日至 26 日,KubeCon + CloudNativeC ...

  9. SecureCRT 7.1.1和SecureFx key 亲测可用

    CRT:Name: ygeRCompany: TEAM ZWTSerialNumber: 03-77-119256License Key: ABH2MJ 9YVAC5 Z17QF7 4ZAS7Z AB ...

  10. oracle函数 NEW_TIME(dt1,c1,c2)

    [功能]:给出时间dt1在c1时区对应c2时区的日期和时间 [参数]:dt1,d2 日期型 [返回]:日期时间 [参数]:c1,c2对应的 时区及其简写 大西洋标准时间:AST或ADT 阿拉斯加_夏威 ...