Centos6.5_x64-GitLab搭建私有GitHub

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

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


1、安装源和依赖包mysql

$ cd /usr/local/srclinux

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

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

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

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


2、确认是否安装成功redis

$ rpm -qa gpg*sql

gpg-pubkey-0608b895-4bd22942


3、安装依赖包

$ 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


4、编译安装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


5、安装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


6、完成后验证ruby

$which ruby

/usr/local/bin/ruby


$ruby -v

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


7、安装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


8、建立git须要的系统用户

useradd git


9、安装mysql

$ yum install -y mysql-server mysql-devel

$ chkconfig mysqld on

$ service mysqld start


10、建立git数据库用户

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


11、建立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;


12、配置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


十3、安装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


十4、安装gem

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

cd /home/git/gitlab

$ vi Gemfile

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


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

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


十5、安装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


十6、初始化数据库

$ cd /home/git/gitlib

bundle exec rake gitlab:setup RAILS_ENV=production


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

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


十7、下载服务脚本,退出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 p_w_uploads

  ## 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


十9、访问gitlab,系统默认admin可是我用默认密码我登陆不了,这里我本身注册了用户名,注册完密码是经过邮件发送的。

#用户名:xx

#密码:xx


二10、至此gitlab安装完成,登陆到gitlab上面能够进行项目的建立、用户的添加、删除、权限分配。



问题总结

一、服务端新建好用户后没法经过ssh方式访问git服务器

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

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


检查git服务端上面有没有这个文件,而后检查用户的公钥有没有自动写入到这个文件里面,若是没有ssh目录和authorized_keys文件须要手动建立,目录权限为600


参考连接:

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

相关文章
相关标签/搜索