CentOS源碼安裝GitLab漢化版

示例環境:

軟件版本
CentOS6.5 x86_64
Git2.6.2
Ruby2.2.3
Node.js4.2.1
Redis3.0.5
MariaDB
10.0.21
GitLab8.0.5漢化版
GitLab Shell2.6.6
Nginx1.8.0
Go1.5.1
Gitlab-git-http-server0.2.14

一、修改Yum源爲阿里雲提高下載速度

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo


二、安裝依賴軟件包

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 cmake pcre-devel


三、安裝Git

  • 查看當前git版本

git --version

  • 如果git版本小於1.7.10則先卸載

rpm -e --nodeps git

  • 下載最新git源碼包並編譯安裝

cd /jinglian

wget https://www.kernel.org/pub/software/scm/git/git-2.6.2.tar.xz 

tar Jxf git-2.6.2.tar.xz

cd git-2.6.2

./configure --prefix=/jinglian/git

make && make install

 

echo 'export PATH=/jinglian/git/bin:$PATH' >> /etc/profile


四、安裝Ruby

cd /jinglian

wget https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.3.tar.gz --no-check-certificate

tar zxf ruby-2.2.3.tar.gz

cd ruby-2.2.3

./configure --prefix=/App/ruby --disable-install-rdoc

make && make install

 

echo 'export PATH=/jinglian/ruby/bin:$PATH' >> /etc/profile

  • 退出shell重新登錄後修改RubyGems 鏡像爲淘寶提高下載速度

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

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


五、安裝Node.js

cd /jinglian

wget https://nodejs.org/dist/v4.2.1/node-v4.2.1-linux-x64.tar.gz --no-check-certificate

tar zxf node-v4.2.1-linux-x64.tar.gz

mv node-v4.2.1-linux-x64 /jinglian/nodejs

 

echo 'export PATH=/jinglian/nodejs/bin:$PATH' >> /etc/profile

六、安裝Go

cd /jinglian/src/

wget https://storage.googleapis.com/golang/go1.5.1.linux-amd64.tar.gz --no-check-certificate

tar zxf go1.5.1.linux-amd64.tar.gz

mv go /jinglian/

 

cat >> /etc/profile << EOF

export GOROOT=/jinglian/go

export GOARCH=amd64

export GOOS=linux

export GOBIN=\$GOROOT/bin

export GOPATH=/root/code/go

export PATH=\$GOBIN:\$PATH

EOF

七、安裝Redis

cd /jinglian/src/

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

tar zxf redis-3.0.5.tar.gz

cd redis-3.0.5

make PREFIX=/jinglian/redis install

 

echo 'export PATH=/jinglian/redis/bin:$PATH' >> /etc/profile


  • 添加Redis配置 /jinglian/redis/redis.conf

daemonize yes

pidfile /jinglian/redis/redis.pid

port 6379

tcp-backlog 60000

timeout 0

tcp-keepalive 60

loglevel warning

logfile "/jinglian/redis/redis.log"

syslog-enabled no

databases 16

save 900 1

save 300 10

save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename dump.rdb

dir /jinglian/redis

slave-serve-stale-data yes

repl-diskless-sync yes

repl-diskless-sync-delay 5

repl-ping-slave-period 10

repl-timeout 60

repl-disable-tcp-nodelay no

slave-priority 100

maxclients 60000

maxmemory-policy noeviction

appendonly no

appendfilename "appendonly.aof"

appendfsync everysec

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100

auto-aof-rewrite-min-size 64mb

aof-load-truncated yes

lua-time-limit 5000

slowlog-log-slower-than 10000

slowlog-max-len 128

latency-monitor-threshold 0

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

hll-sparse-max-bytes 3000

activerehashing yes

client-output-buffer-limit normal 0 0 0

client-output-buffer-limit slave 256mb 64mb 60

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

hz 10

aof-rewrite-incremental-fsync yes


  • 啓動Redis

/jinglian/redis/bin/redis-server /jinglian/redis/redis.conf

redis啓動腳本:

#!/bin/bash

#

# redis - this script starts and stops the redis-server daemon

#

# chkconfig:  - 80 12

# description: Redis is a persistent key-value database

# processname: redis-server

# config:   /usr/local/redis/etc/redis.conf

# pidfile:   /usr/local/redis/var/redis.pid


source /etc/init.d/functions


BIN="/jinglian/redis/bin"

CONFIG="/jinglian/redis/redis.conf"

PIDFILE="/jinglian/redis/redis.pid"



### Read configuration

[ -r "$SYSCONFIG" ] && source"$SYSCONFIG"


RETVAL=0

prog="redis-server"

desc="Redis Server"


start() {


    if [ -e $PIDFILE ]

    then

       echo "$desc already running...."

       exit 1

    fi


    echo -n $"Starting $desc: "

    daemon $BIN/$prog $CONFIG


    RETVAL=$?

    echo

    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog

    return $RETVAL

}


stop() {

    echo -n $"Stop $desc: "

    killproc $prog

    RETVAL=$?

    echo

    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE

    return $RETVAL

}


restart() {

  stop

  start

}


case "$1" in

 start )

    start

    ;;

 stop )

    stop

    ;;

 restart )

    restart

    ;;

 condrestart)

    [ -e /var/lock/subsys/$prog ] && restart

    RETVAL=$?

    ;;

 status)

    status $prog

    RETVAL=$?

    ;;

  *)

    echo$"Usage: $0 {start|stop|restart|condrestart|status}"

    RETVAL=1

esac


exit $RETVAL





八、安裝配置mysql

安裝步驟不在複述。

登陸mysql,創建數據庫並授權;

mysql -uroot -p

CREATE DATABASE `gitlabhq_production`;

GRANT SELECTINSERTUPDATEDELETECREATECREATE TEMPORARY TABLES, DROPINDEXALTER, LOCK TABLES ON `gitlabhq_production`.* TO 'git'@'127.0.0.1' IDENTIFIED BY 'PASSWORD';

GRANT SELECTINSERTUPDATEDELETECREATECREATE TEMPORARY TABLES, DROPINDEXALTER, LOCK TABLES ON `gitlabhq_production`.* TO 'git'@'localhost' IDENTIFIED BY 'PASSWORD';

FLUSH PRIVILEGES;

QUIT;


九、安裝配置GitLab

useradd --system -s /bin/bash --comment 'GitLab' -m -d /home/git git

  • 修改git家目錄權限,否則訪問 gitlab.socket 報權限錯誤

chmod 755 /home/git

  • 切換至git用戶

su - git

git clone https://gitlab.com/larryli/gitlab.git -b 8-0-zh gitlab

  • 配置GitLab

cd gitlab/

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

  • 修改 gitlab.yml 配置,將行host: localhost 修改爲本機IP地址或者域名,如爲域名,確保域名映射本機地址,此時需修改 /etc/hosts 文件

  • 修改 gitlab.yml ,配置git路徑行 bin_path: /usr/bin/git 爲 bin_path: /App/git/bin/git

  • 新建衛星目錄,拷貝示例文件,修改權限

mkdir -p /home/git/gitlab-satellites

cp config/secrets.yml.example config/secrets.yml

chmod 0600 config/secrets.yml

chmod -R u+rwX,go-w log/

chmod -R u+rwX tmp/

chmod -R u+rwX tmp/pids/

chmod -R u+rwX tmp/sockets/

chmod -R u+rwX public/uploads/

chmod 0750 public/uploads/

mkdir -p /home/git/repositories

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

chmod -R ug-s /home/git/repositories/

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

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

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

git config --global core.autocrlf input

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

  • 修改Redis相關配置 config/resque.yml 文件 production: unix:/var/run/redis/redis.sock爲 production: redis://127.0.0.1:6379

  • 數據庫配置

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

  • 修改 config/database.yml 前段 PRODUCTION 部分內容, password: "secure password" 修改爲password: "PASSWORD"

chmod o-rwx config/database.yml


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


十、安裝GitLab Shell

bundle exec rake gitlab:shell:install[v2.6.6] REDIS_URL=redis://127.0.0.1:6379 RAILS_ENV=production


十一、安裝gitlab-git-http-server

cd /home/git

git clone https://gitlab.com/gitlab-org/gitlab-git-http-server.git -b 0.2.14 

cd gitlab-git-http-server

make

  • 注意:GitLab 8.0對應0.2.14版,安裝最新版可能有未知問題。本人首次安裝最新版0.3.0時,clone代碼報錯如下圖:


十二、初始化數據庫並激活高級功能

1

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

  • GITLAB_ROOT_PASSWORD 值爲管理員 root 登錄密碼本例設爲 newpassword


十三、切換爲root用戶後拷貝服務腳本

exit

cp /home/git/gitlab/lib/support/init.d/gitlab /etc/init.d/


十四、root權限配置Logrotate

cp /home/git/gitlab/lib/support/logrotate/gitlab /etc/logrotate.d/


十五、檢查應用狀態

su - git

cd gitlab/

bundle exec rake gitlab:env:info RAILS_ENV=production


十六、編譯靜態文件

bundle exec rake assets:precompile RAILS_ENV=production


十七、切換至root用戶安裝Nginx

exit

cd /App/src/

wget http://nginx.org/download/nginx-1.8.0.tar.gz 

tar zxf nginx-1.8.0.tar.gz

cd nginx-1.8.0

./configure \

--prefix=/App/nginx \

--with-http_stub_status_module \

--with-http_gzip_static_module \

--without-http_auth_basic_module \

--without-http_autoindex_module \

--without-http_browser_module \

--without-http_empty_gif_module \

--without-http_geo_module \

--without-http_limit_conn_module \

--without-http_limit_req_module \

--without-http_map_module \

--without-http_memcached_module \

--without-http_referer_module \

--without-http_split_clients_module \

--without-http_ssi_module \

--without-http_userid_module \

--without-mail_imap_module \

--without-mail_pop3_module \

--without-mail_smtp_module \

--without-poll_module \

--without-select_module

 

make && make install

useradd -s /bin/false nginx

  • 修改Nginx配置 /App/nginx/conf/nginx.conf

user  nginx nginx;

worker_processes  auto;

 

error_log  logs/error.log error;

 

pid        logs/nginx.pid;

worker_rlimit_nofile    65536;

 

events

{

    use epoll;

    accept_mutex off;

    worker_connections  65536;

}

 

http

{

    include       mime.types;

    default_type  text/html;

 

    charset UTF-8;

    server_names_hash_bucket_size   128;

    client_header_buffer_size       4k;

    large_client_header_buffers  4 32k;

    client_max_body_size            20m;

 

    open_file_cache max=65536  inactive=60s;

    open_file_cache_valid      80s;

    open_file_cache_min_uses   1;

 

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

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';

 

    access_log  logs/access.log  main;

 

    sendfile    on;

    server_tokens off;

 

    keepalive_timeout  60;

 

    gzip  on;

    gzip_min_length 1k;

    gzip_buffers  4   64k;

    gzip_http_version   1.1;

    gzip_comp_level 2;

    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

 

    upstream gitlab 

    {

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

    }

 

    upstream gitlab-git-http-server 

    {

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

    }

 

    server {

        listen      80;

        server_name _;

        root        /home/git/gitlab/public;

 

        location /

        {

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

        }

 

        location /uploads/

        {

            proxy_read_timeout      300;

            proxy_connect_timeout   300;

            proxy_redirect          off;

            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_set_header    X-Frame-Options     SAMEORIGIN;

            proxy_pass http://gitlab;

        }

 

        location @gitlab

        {

            proxy_read_timeout      300;

            proxy_connect_timeout   300;

            proxy_redirect          off;

            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_set_header    X-Frame-Options     SAMEORIGIN;

            proxy_pass http://gitlab;

        }

 

        location ~ [-\/\w\.]+\.git\/

        {

            proxy_read_timeout      300;

            proxy_connect_timeout   300;

            proxy_redirect          off;

            proxy_buffering off;

            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-git-http-server;

        }

 

        location ~ ^/(assets)/

        {

            root /home/git/gitlab/public;

            gzip_static on;

            expires max;

            add_header Cache-Control public;

        }

 

        error_page 502 /502.html;

    }

}


十八、SMTP相關配置

  • 複製smtp示例配置

cp /home/git/gitlab/config/initializers/smtp_settings.rb.sample /home/git/gitlab/config/initializers/smtp_settings.rb

  • 修改 smtp_settings.rb 將 enable_starttls_auto: true 修改爲 enable_starttls_auto: falseopenssl_verify_mode: 'peer' 刪除或添加 # 註釋其餘按照自己的郵箱正常配置即可

    spacer.gif

    修改/config/environments/production.rb 配置爲用smtp發送郵件

    spacer.gif

    修改vim /home/git/gitlab/config/gitlab.yml

    spacer.gif


十九、啓動GitLab實例

/etc/init.d/gitlab start

二十、瀏覽器打開登錄頁面


二十一、輸入賬號 root密碼爲初始化數據庫時自定義變量 GITLAB_ROOT_PASSWORD 值


需要合作交流的可以加QQ羣:163935235

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