安装yum源

yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

vim /etc/yum.repos.d/epel.repo

baseurl去掉注释

注释mirrorlist

 

安装git环境所需的包

yum -y install libicu-devel patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make autoconf automake libtool bison libxml2-devel libxslt-devel libyaml-devel zlib-devel openssl-devel cpio expat-devel gettext-devel curl-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker

 

移除机器上现有的git ruby

yum -y remove git ruby

 

安装git

mkdir /tmp/git && cd /tmp/git

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

tar -zxvf git-1.8.4.1.tar.gz

cd git-1.8.4.1/

make prefix=/usr/local all

make prefix=/usr/local install

ln -fs /usr/local/bin/git* /usr/bin/

 

安装ruby

mkdir /tmp/ruby && cd /tmp/ruby

curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz | tar xz

cd ruby-2.0.0-p353/

./configure --disable-install-rdoc

make && make install

gem source -r https://rubygems.org/

gem source -a http://ruby.taobao.org/

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

ln -s /usr/local/bin/ruby /usr/bin/ruby

ln -s /usr/local/bin/gem /usr/bin/gem

ln -s /usr/local/bin/bundle /usr/bin/bundle

 

新建git账号并允许sudo

useradd --comment 'GitLab' git

echo "git ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

 

安装git-shell

su - git

sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-shell.git -b v1.8.0

cd gitlab-shell/

sudo -u git -H cp config.yml.example config.yml

vim config.yml

修改gitlab域名

gitlab_url: "http://localhost/"

如:

gitlab_url: "http://gitlab.example.com/“

:wq!

sudo -u git -H ./bin/install

 

使用mysql并建立gitlab数据库,本机如果没有mysql直接yum安装即可

sudo yum -y install mysql mysql-devel mysql-server

sudo /etc/init.d/mysqld start

mysql -uroot -p

CREATE USER 'gituser'@'localhost' IDENTIFIED BY 'gitpasswd';

CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.*TO 'gituser'@'localhost';

\q

 

测试gituser登陆数据库是否正常

sudo -u git -H mysql -u gituser -p -D gitlabhq_production

 

安装redis

sudo yum -y install redis

sudo /etc/init.d/redis start

sudo chkconfig redis on

 

安装gitlab

cd /home/git

sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-4-stable gitlab

cd /home/git/gitlab

sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

vim config/gitlab.yml

修改git域名,上面git-shell配置文件里面定义的

gitlab:

  ## Web server settings

  host: gitlab.example.com

  port: 80

  https: false

修改git path

git:

  bin_path: /usr/local/bin/git

:wq!

 

添加相应文件的权限、新建必要的文件及复制配置文件

chown -R git log/

chown -R git tmp/

chmod -R u+rwX  log/

chmod -R u+rwX  tmp/

sudo -u git -H mkdir /home/git/gitlab-satellites

sudo -u git -H mkdir tmp/pids/

sudo -u git -H mkdir tmp/sockets/

sudo chmod -R u+rwX tmp/pids/

sudo chmod -R u+rwX tmp/sockets/

sudo -u git -H mkdir public/uploads

sudo chmod -R u+rwX public/uploads/

sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb

sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

 

设置gitlab全局账号

sudo -u git -H git config --global user.name "GitLab"

sudo -u git -H git config --global user.email "gitlab@localhost"

sudo -u git -H git config --global core.autocrlf input

 

设置数据库连接文件信息,如下是我数据库信息配置:

sudo -u git cp config/database.yml.mysql config/database.yml

sudo -u git -H vim config/database.yml

#

# PRODUCTION

#

production:

  adapter: mysql2

  encoding: utf8

  reconnect: false

  database: gitlabhq_production

  pool: 10

  username: gituser

  password: "gitpasswd”

  # host: localhost

  # socket: /tmp/mysql.sock

 

#

# Development specific

#

development:

  adapter: mysql2

  encoding: utf8

  reconnect: false

  database: gitlabhq_development

  pool: 5

  username: gituser

  password: "gitpasswd”

  # socket: /tmp/mysql.sock

 

# Warning: The database defined as "test" will be erased and

# re-generated from your development database when you run "rake".

# Do not set this db to the same as development or production.

test: &test

  adapter: mysql2

  encoding: utf8

  reconnect: false

  database: gitlabhq_test

  pool: 5

  username: gituser

  password: "gitpasswd”

  # socket: /tmp/mysql.sock

 

安装gems

cd /home/git/gitlab

vim Gemfile

修改source "https://rubygems.org/"

为source "https://ruby.taobao.org/"

vim Gemfile.lock

修改remote: https://rubygems.org/

为remote: https://ruby.taobao.org/

:wq

sudo -u git -H bundle install --deployment --without development test postgres aws

如出现此类错误Could not find modernizr-2.6.2 in any of the sources,则修改:

vim Gemfile

修改:gem "modernizr",        "2.6.2"

为gem "modernizr-rails",  "2.7.1"

:wq

vim Gemfile.lock

修改:modernizr (2.6.2)

为:modernizr-rails (2.7.1)

修改:modernizr (= 2.6.2)

为:modernizr-rails (= 2.7.1)

:wq

再次运行:sudo -u git -H bundle install --deployment --without development test postgres aws

 

初始化数据库

sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

Do you want to continue (yes/no)? yes

初始化完成后最后两行就是你gitlab默认的用户名密码

 

配置启动及日志切割文件

sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab

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

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

 

测试环境信息

sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

 

安装nginx

sudo yum -y install nginx

以下是我nginx主配置文件内容

cat /etc/nginx/nginx.conf | grep -v "^#" | grep -v "^$"

user              root git;

worker_processes  2;

pid        /var/run/nginx.pid;

events {

    worker_connections  1024;

}

http {

    include       /etc/nginx/mime.types;

    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';

upstream gitlab {

    server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;

}

server {

    listen *:80 default_server;

    server_name gitlab.example.com;

    server_tokens off;

    root /home/git/gitlab/public;

    client_max_body_size 5m;

    access_log  /var/log/nginx/gitlab_access.log;

    error_log   /var/log/nginx/gitlab_error.log;

    location / {

        try_files $uri $uri/index.html $uri.html @gitlab;

    }

    location @gitlab {

        proxy_read_timeout 300;

        proxy_connect_timeout 300;

        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;

    }

}

    #tcp_nopush     on;

    #keepalive_timeout  0;

    #gzip  on;

    

    # Load config files from the /etc/nginx/conf.d directory

    # The default server is in conf.d/default.conf

}

更改权限及启动nginx

sudo nginx -t

sudo chown -R git.git /var/lib/nginx/

sudo /etc/init.d/nginx start

 

拉取gitlab静态资源文件

sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production

 

启动gitlab

sudo /etc/init.d/gitlab start

 

检查各个组件是否正常工作

sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

 

一切正常的话 使用你的浏览器访问gitlab吧(域名访问,修改hosts文件先)

http://gitlab.example.com

账号密码为上面初始化数据后显示的账号密码

admin@local.host/5iveL!fe

 

到此,gitlab安装完成