CentOS 下gitlab-8.5安裝配置

CentOS 下gitlab安裝配置:

1.首先配置好epel yum源

可以用阿里雲鏡像源 參考  http://mirrors.aliyun.com/help/centos 設置

2.安裝Gitlab所需要的依賴包

#yum install readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel gcc-c++ libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui python-devel logwatch logrotate cmake perl-Time-HiRes redis sudo wget postfix nodejs

3.安裝升級git到2.7.3版本以上

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

#tar xvf git-2.7.3.tar.gz

#cd git-2.7.3

#./configure --prefix=/usr/local/

#make 

#make install

# git --version

git version 2.7.3

4.安裝Ruby2.1:(必須要用2.1版本,其它版本不支持)

#rpm -qa|grep -i ruby (先看系統有沒安裝ruby,如果版本不對需要先yum remove卸載之)

#wget ftp://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.0.tar.gz 

#tar xvf ruby-2.1.0.tar.gz

#cd ruby-2.1.0

#./configure --prefix=/usr/local/

#make && make install

#which ruby

/usr/local/bin/ruby

#ruby -v

ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]

換成淘寶gem鏡像源

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

安裝bundler命令:

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

5.安裝Go:(gitlab-workhorse需要用)

#wget https://storage.googleapis.com/golang/go1.5.3.linux-amd64.tar.gz

## sha1sum go1.5.3.linux-amd64.tar.gz 

c5377eca4837968d043b681f00a852a262f0f5f6  go1.5.3.linux-amd64.tar.gz

#tar -xvf go1.5.3.linux-amd64.tar.gz -C /usr/local 

#ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/

6.新建git賬戶

#useradd --comment 'GitLab' git

7.安裝配置mysql

安裝略

#mysql -h127.0.0.1 -u root -p

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

GRANT all privileges ON `gitlabhq_production`.* TO 'gitlab'@'localhost' IDENTIFIED BY 'gitlab_passwd';

測試登陸是否正常:

#mysql -h127.0.0.1 -u gitlab -p gitlabhq_production

8.安裝redis 2.8以上版本: ==

#wget http://download.redis.io/releases/redis-2.8.24.tar.gz

#tar xvf redis-2.8.24.tar.gz -C /usr/local/

#cd /usr/local/redis-2.8.24/

#make

#ln -s /usr/local/redis-2.8.24/  /usr/local/redis

#echo 'export PATH=/usr/local/redis/src/:$PATH' >>/etc/profile

然後退出重新登錄下使PATH變量生效

redis實例我們部署在git賬號下

#mkdir -p /data/git/redis/{bin,conf,data,log} /var/run/redis/

#cp /usr/local/redis/redis.conf /data/git/redis/conf

#vim /data/git/redis/conf/redis.conf 修改配置文件,需要啓用unixsocket

unixsocket /var/run/redis/redis.sock

daemonize yes 

pidfile /data/git/redis/log/redis.pid

port 6379 #可以不監聽端口,配置成port 0

timeout 0 

loglevel notice 

logfile /data/git/redis/log/redis.log 

dir /data/git/redis/data

dbfilename dump.rdb 

appendonly yes 

appendfilename redis.aof 

databases 16 

stop-writes-on-bgsave-error yes 

rdbcompression yes 

rdbchecksum yes 

slave-serve-stale-data yes 

slave-read-only yes 

slave-priority 100 

maxmemory 200m 

appendfsync everysec 

no-appendfsync-on-rewrite no 

auto-aof-rewrite-percentage 100 

auto-aof-rewrite-min-size 8mb 

lua-time-limit 5000 

slowlog-log-slower-than 10000 

slowlog-max-len 128 

hash-max-ziplist-entries 512 

hash-max-ziplist-value 64 

list-max-ziplist-entries 512 

list-max-ziplist-value 64 

set-max-intset-entries 512 

zset-max-ziplist-entries 128 

zset-max-ziplist-value 64 

activerehashing yes 

client-output-buffer-limit normal 0 0 0 

client-output-buffer-limit slave 32mb 8mb 60 

client-output-buffer-limit pubsub 32mb 8mb 60

rename-command FLUSHDB FLUSHDB_JBJHHZSTSL 

rename-command FLUSHALL FLUSHALL_SZPZCLLJXK

#chown -R git.git /data/git/redis/ /var/run/redis/

用git用戶啓動redis

$redis-server /data/git/redis/conf/redis.conf

$redis-cli -s /var/run/redis/redis.sock 看能否登錄

9.安裝gitlab-shell:(用來ssh訪問倉庫的管理軟件)

#su - git 

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

$cd gitlab-shell

查看版本:

$git tag

$git checkout v2.6.10

$cp config.yml.example config.yml

$vim config.yml

http://localhost:8080 換爲需要配置的域名,如http://git.aa.com

$./bin/install

10.安裝gitlab-workhorse

GitLab Workhorse是一個敏捷的反向代理。它會處理一些大的HTTP請求,比如文件上傳、文件下載、Git push/pull和Git包下載。其它請求會反向代理到GitLab Rails應用,即反向代理給後端的unicorn

$cd /home/git

$git clone https://gitlab.com/gitlab-org/gitlab-workhorse.git

$cd gitlab-workhorse

$git checkout 0.6.4

$make

11.安裝gitlab-8.5.0:

$cd /home/git

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

$cd /home/git/gitlab

查看版本:

$git tag

$git checkout v8.5.0

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

$sed -i 's/localhost/git.aa.com/g' config/gitlab.yml

修改Gitlab發件地址:

$sed -i 's/[email protected]/gitlab@git.aa.com/g' config/gitlab.yml

新建和配置相關目錄權限:

$chown -R git log/  tmp/

$chmod -R u+rwx  log/  tmp/

$mkdir /home/git/gitlab-satellites

$mkdir -p public/uploads  && chmod -R u+rwx  public/uploads

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

配置Gitlab Email相關信息:

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

$git config --global user.email "gitlab@git.aa.com"

$git config --global core.autocrlf input

配置Gitlab 數據庫: 

$cp config/database.yml{.mysql,}

$vim config/database.yml

production:

  adapter: mysql2

  encoding: utf8

  database: gitlabhq_production

  pool: 5

  username: gitlab

  password: supersecret

  host: 127.0.0.1

  port: 3306

  # socket: /tmp/postgresql.sock 

$chmod o-rwx config/database.yml

安裝Gems:

$cd /home/git/gitlab/

先更改成淘寶Gem源:

$sed -i 's|https://rubygems.org|https://ruby.taobao.org|g' Gemfile

$sed -i 's|https://rubygems.org|https://ruby.taobao.org|g' Gemfile.lock

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

Fetching gem metadata from https://ruby.taobao.org/........

Fetching version metadata from https://ruby.taobao.org/..

Installing rake 10.5.0

Installing CFPropertyList 2.3.2

Installing RedCloth 4.2.9 with native extensions

Installing ace-rails-ap 2.0.1

Installing i18n 0.7.0

Installing json 1.8.3 with native extensions

....

Bundle complete! 168 Gemfile dependencies, 263 gems now installed.

Gems in the groups development, test, postgres, puma and aws were not installed.

Bundled gems are installed into ./vendor/bundle.

....

初始化數據庫和激活高級功能,等待完成後會顯示Gitlab管理員用戶名密碼:

$bundle exec rake gitlab:setup RAILS_ENV=production

Administrator account created:

login.........root

password......5iveL!fe       (記住此密碼)

安裝Gitlab啓動腳本: 

$su - root

#cd /home/git/gitlab

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

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

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

#chkconfig --add gitlab

#chkconfig gitlab on

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

檢測Gitlab環境配置:

$cd /home/git/gitlab/

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

System information

System:         CentOS 6.5

Current User:   git

Using RVM:      no

Ruby Version:   2.1.0p0

Gem Version:    2.2.0

Bundler Version:1.11.2

Rake Version:   10.5.0

Sidekiq Version:4.0.1

GitLab information

Version:        8.5.7

Revision:       fatal: Not a git repository (or any of the parent directories): .git

Directory:      /home/git/gitlab

DB Adapter:     mysql2

URL:            http://git.aa.com

HTTP Clone URL: http://git.aa.com/some-group/some-project.git

SSH Clone URL:  git@git.aa.com:some-group/some-project.git

Using LDAP:     no

Using Omniauth: no

GitLab Shell

Version:        2.6.10

Repositories:   /home/git/repositories/

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

Git:            /usr/bin/git

拉取Gitlab靜態資源文件:

$bundle exec rake assets:precompile RAILS_ENV=production

啓動Gitlab:

#service gitlab start

啓動後再次全面檢測:

$cd /home/git/gitlab/

$bundle exec rake gitlab:check RAILS_ENV=production

根據提示fix一些問題(doc/install/installation.md 裏有詳細安裝設置)

#chmod -R ug+rwX,ug-s,o-rwx /home/git/repositories/

#find /home/git/repositories/ -type d -print0 |xargs -0 chmod g+s

12.安裝配置nginx(版本需大於1.6,否則安裝完畢客戶端git clone或git push會報錯):

cd /usr/local/src

安裝pcre

#wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz

#tar xvf pcre-8.38.tar.gz 

#cd pcre-8.38

#./configure 

#make && make install

安裝zlib

#wget http://zlib.net/zlib-1.2.8.tar.gz

#tar xvf zlib-1.2.8.tar.gz 

#cd zlib-1.2.8

#./configure 

#make && make install

安裝openssl

#wget http://www.openssl.org/source/openssl-1.0.1s.tar.gz

#tar xvf openssl-1.0.1s.tar.gz 

#cd openssl-1.0.1s

# ./config

#make 

#make install

#wget http://nginx.org/download/nginx-1.6.3.tar.gz

#tar xvf nginx-1.6.3.tar.gz

#cd nginx-1.6.3

#./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.38  --with-zlib=/usr/local/zlib-1.2.8 --with-openssl=/usr/local/openssl-1.0.1s

#make 

#make install

#cd /usr/local/nginx/conf

#mkdir sites-available

#cp /home/git/gitlab/lib/support/nginx/gitlab sites-available/gitlab.conf

#vim sites-available/gitlab.conf

server_name 換爲git.aa.com

#grep -v "^#" sites-available/gitlab.conf| grep -v "^$"

upstream gitlab-workhorse {

  server unix:/home/git/gitlab/tmp/sockets/gitlab-workhorse.socket fail_timeout=0;

}

server {

  listen 0.0.0.0:80 default_server;

  server_name git.aa.com; 

  server_tokens off;

  root /home/git/gitlab/public;

  access_log  /usr/local/nginx/logs/gitlab_access.log;

  error_log   /usr/local/nginx/logs/gitlab_error.log;

  location / {

    client_max_body_size 0;

    gzip off;

    proxy_read_timeout      300;

    proxy_connect_timeout   300;

    proxy_redirect          off;

    proxy_http_version 1.1;

    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_set_header    X-Forwarded-Proto   $scheme;

    proxy_pass http://gitlab-workhorse;

  }

}

修改nginx主配置文件

#grep -v "^#" nginx.conf | grep -v "^$"

user  root git;

worker_processes  2;

error_log  logs/error.log  notice;

pid        logs/nginx.pid;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {

        listen       80;

        server_name  localhost;

        location / {

            root   html;

            index  index.html index.htm;

        }

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

    }

    include /usr/local/nginx/conf/sites-available/gitlab.conf;    

}

啓動nginx:

/usr/local/nginx/sbin/nginx

== 更換git域名: ==

修改以下三個配置文件的舊域名

/home/git/.gitconfig

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

/home/git/gitlab/config/gitlab.yml

重啓gitlab服務:

/etc/init.d/gitlab restart

== GitLab錯誤相關:== 

= git clone報錯: =

error: The requested URL returned error: 401 Unauthorized while accessing http://git.aa.com/test/atlantis.git/info/refs

fatal: HTTP request failed

解決:

方法一:客戶端升級git 到2.7.3或以上版本

方法二:url中加上用戶名

git clone http://[email protected]/project


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章