转载地址:http://www.zhangluya.com/?p=193

Gitlab完整安装部署文档20160526

1:基础环境说明:

System: CentOS_6.7_64

Redis : 3.2

MySQL : 5.6

IP    : 10.10.0.25

参考地址:https://github.com/gitlabhq/gitlab-recipes/tree/master/install/centos

ubuntu 安装文档:http://docs.gitlab.com/ce/install/installation.html#using-https

http://hdu104.com/401

一:Add EPEL repository

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 -qa gpg*

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

二:Add PUIAS Computational repository

wget -O /etc/yum.repos.d/PUIAS_6_computational.repo https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/install/centos/PUIAS_6_computational.repo

wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-puias http://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias

rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY-puias

rpm -qa gpg*

yum repolist

yum-config-manager –enable epel –enable PUIAS_6_computational

三:install the required tools for GitLab

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 \

git cmake libcom_err-devel.i686 libcom_err-devel.x86_64 nodejs

yum-config-manager –enable rhel-6-server-optional-rpms

yum -y install vim-enhanced

update-alternatives –set editor /usr/bin/vim.basic

yum -y install python-docutils

四:安装git

yum -y install postfix

yum -y remove git

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

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

curl –progress https://www.kernel.org/pub/software/scm/git/git-2.8.2.tar.gz|tar xz

cd git-2.8.2/

./configure

make

make prefix=/usr/local install

cd ..

五:安装:Ruby

yum remove ruby

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

#wget https://pkgs.api.huahuacaocao.net/gitlab/ruby-2.2.3.tar.gz

wget http://10.10.0.4:81/gitlab/ruby-2.2.3.tar.gz

tar zvfx ruby-2.2.3.tar.gz

cd ruby-2.2.3

./configure –disable-install-rdoc

make

make prefix=/usr/local install

cd ..

修改本地源为taobao源:

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

gem install bundler –no-doc

ruby -v

六:添加用户

adduser –system –shell /bin/bash –comment ‘GitLab’ –create-home –home-dir /home/git/ git

vi /etc/sudoers +86

#———————————————————————-

#将如下:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

#修改为

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

#———————————————————————-

七:配置MySQL

安装略:IP地址 10.10.0.4

CREATE USER ‘git’@’10.10.%’ IDENTIFIED BY ‘xxxxxx’;

SET storage_engine=INNODB;

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

GRANT SELECT,LOCK TABLES,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,ALTER ON `gitlabhq_production`.* TO ‘git’@’10.10.%’;

八:配置Redis

略:

127.0.0.1:6379

九:下载gitlab-ce 最新代码

cd /home/git

sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git

mv gitlab-ce-master gitlab

配置gitlab

cd /home/git/gitlab

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

vim config/gitlab.yml

#======================================================================================

#修改462行 git bin_path 为:

bin_path: /usr/local/bin/git

#修改30-35行gitlab为https

 gitlab:

     host: gitlab.api.hhcc.net

     port: 443

     https: true

#修改70-72行邮箱信息

   email_from: admin@hhcc.net

   email_display_name: GitLab

   email_reply_to: admin@hhcc.net

#======================================================================================

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

chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites

chmod -R u+rwX tmp/pids/

chmod -R u+rwX tmp/sockets/

chmod -R u+rwX  public/uploads

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

#视情况修改worker_processes 数量

sudo -u git -H editor config/unicorn.rb

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

#Configure Git global settings for git user, useful when editing via web

#Edit user.email according to what is set in gitlab.yml

sudo -u git -H git config –global user.name “admin”

sudo -u git -H git config –global user.email “admin@hhcc.net”

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

#Configure Redis

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

vim config/resque.yml #以下方式任选其一

#———————————–

production: redis://127.0.0.1:6379

#production: unix:/dev/shm/redis.sock

#———————————–

#Configure MySQL

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

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

sudo -u git -H chmod o-rwx config/database.yml

#——————————————–

production:

  adapter: mysql2

  encoding: utf8

  collation: utf8_general_ci

  reconnect: false

  database: gitlabhq_production

  pool: 10

  username: git

  password: “xxxxxx”

  host: 10.10.0.4

#——————————————–

#Install Gems

cd /home/git/gitlab

#修改默认的源为taobao源

vim Gemfile

#————————————

#source “https://rubygems.org”

source “https://ruby.taobao.org”

#————————————

yum install -y mysql-devel

gem install mysql2 -v ‘0.3.20’

gem install rdoc-data; rdoc-data –install

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

#Install GitLab shell

#sudo -u git -H bundle exec rake gitlab:shell:install[v2.1.0] REDIS_URL=redis://127.0.0.1:6379 RAILS_ENV=production

sudo -u git -H bundle exec rake gitlab:shell:install REDIS_URL=redis://127.0.0.1:6379 RAILS_ENV=production

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

#—————————————————–

user: git

gitlab_url: https://gitlab.api.hhcc.net/

http_settings:

  #注意以下行 默认为false

  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

  host: 127.0.0.1

  port: 6379

log_level: INFO

audit_usernames: false

#—————————————————–

#Ensure the correct SELinux contexts are set

restorecon -Rv /home/git/.ssh

#Initialize Database and Activate Advanced Features

#设置密码(任选其一)

#第一次登陆设置

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

#默认设置

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

#成功会有如下提示:

#== Seed from /home/git/gitlab/db/fixtures/production/001_admin.rb

#Administrator account created:

#

#login:    root

#password: xxxxxx

#Install Init Script

#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

#echo “/etc/init.d/gitlab start” >> /etc/rc.local

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

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

#Set up logrotate

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

#Check Application Status

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

#Compile assets

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

Start your GitLab instance

#修改gitlab端口可远程访问

vim gitlab/config/unicorn.rb +42

#—————————-

listen “0.0.0.0:8081”, :tcp_nopush => true

#—————————-

安装workhorse:

curl -O --progress https://storage.googleapis.com/golang/go1.5.3.linux-amd64.tar.gz


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

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

rm -rf go1.5.3.linux-amd64.tar.gz

cd /home/git
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-workhorse.git


cd gitlab-workhorse

sudo -u git -H make

#start gitlab

/etc/init.d/gitlab start

#配置Nginx https支持:

参考文档:https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/install/installation.md#using-https

nginx 配置文件路径:

cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab

vim gitlab.api.hhcc.net.conf

#———————————————————————————

upstream gitlab {

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

}

upstream gitlab-workhorse {

    #server unix:/home/git/gitlab/gitlab-workhorse/socket;

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

}

server {

      listen 0.0.0.0:80;

      server_name gitlab.api.hhcc.net;

      server_tokens off;

      return 301 https://$http_host$request_uri;

      access_log  /data/logs/nginx/gitlab_access.log;

      error_log   /data/logs/nginx/gitlab_error.log;

}

server {

     listen 0.0.0.0:443 ssl;

     server_name gitlab.api.hhcc.net;

     server_tokens off;

     root /home/gitlab/public;

     client_max_body_size 20m;

     access_log /data/logs/nginx/gitlab_access.log;

     error_log /data/logs/nginx/gitlab_error.log;

         ssl on;

         ssl_certificate      /usr/local/nginx-1.8.1/conf/key/api.crt;

         ssl_certificate_key  /usr/local/nginx-1.8.1/conf/key/api.key;

         #GitLab needs backwards compatible ciphers to retain compatibility with Java IDEs

         ssl_ciphers “ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4”;

         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

         ssl_prefer_server_ciphers on;

         ssl_session_cache shared:SSL:10m;

         ssl_session_timeout 5m;

 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-Forwarded-Ssl     on;

         proxy_set_header    X-Forwarded-Proto   https;

     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-Forwarded-Ssl     on;

         proxy_set_header    X-Forwarded-Proto   https;

     proxy_set_header X-Frame-Options SAMEORIGIN;

     proxy_pass http://gitlab;

 }

 location ~ ^/[\w\.-]+/[\w\.-]+/gitlab-lfs/objects {

     client_max_body_size 0;

     error_page 418 = @gitlab-workhorse;

     return 418;

 }

 location ~ ^/[\w\.-]+/[\w\.-]+/(info/refs|git-upload-pack|git-receive-pack)$ {

     client_max_body_size 0;

     error_page 418 = @gitlab-workhorse;

     return 418;

 }

 location ~ ^/[\w\.-]+/[\w\.-]+/repository/archive {

     client_max_body_size 0;

     error_page 418 = @gitlab-workhorse;

     return 418;

 }

 location ~ ^/api/v3/projects/.*/repository/archive {

     client_max_body_size 0;

     error_page 418 = @gitlab-workhorse;

     return 418;

 }

 location ~ ^/[\w\.-]+/[\w\.-]+/builds/download {

     client_max_body_size 0;

     error_page 418 = @gitlab-workhorse;

     return 418;

 }

 location ~ /ci/api/v1/builds/[0-9]+/artifacts {

     client_max_body_size 0;

     error_page 418 = @gitlab-workhorse;

     return 418;

 }

 location @gitlab-workhorse {

     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_set_header    X-Forwarded-Ssl     on;

         proxy_set_header    X-Forwarded-Proto   https;

     proxy_pass http://gitlab-workhorse;

 }

 location ~ ^/(assets)/ {

     root /home/git/gitlab/public;

     gzip_static on;

     expires max;

     add_header Cache-Control public;

 }

 error_page 502 /502.html;

}

#———————————————————————————

转载地址:http://www.zhangluya.com/?p=193


配置邮件报警:

一:

vim /home/git/gitlab/config/initializers/smtp_settings.rb

#———————————————————————————

[root@bj-6-gitlab-01 gitlab]# cat config/initializers/smtp_settings.rb

# To enable smtp email delivery for your GitLab instance do the following:

# 1. Rename this file to smtp_settings.rb

# 2. Edit settings inside this file

# 3. Restart GitLab instance

#

# For full list of options and their values see http://api.rubyonrails.org/classes/ActionMailer/Base.html

#

# If you change this file in a Merge Request, please also create a Merge Request on https://gitlab.com/gitlab-org/omnibus-gitlab/merge_requests

if Rails.env.production?

  Rails.application.config.action_mailer.delivery_method = :smtp

  ActionMailer::Base.smtp_settings = {

    #address: “smtp.exmail.qq.com”,

    address: “pop.exmail.qq.com”,

    port: 25,

    user_name: “admin@hhcc.net”,

    password: “xxxxxx”,

    domain: “pop.exmail.qq.com”,

    authentication: :login,

    #enable_starttls_auto: true,

    enable_starttls_auto: false,

    openssl_verify_mode: ‘peer’ # See ActionMailer documentation for other possible options

  }

end

#———————————————————————————

2:

cd /home/git/gitlab

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

将默认邮箱修改为自己的邮箱

#关闭注册功能

gitlab关闭注册:去掉 Sign-up enabled 的对勾

Admin–>settings –> Sign-in Restrictions

Sign-upenbaled  关闭注册功能

Sign-inenbaled  关闭注册登录功能

问题1:error: RPC failed; result=22, HTTP code = 411

该问题是由于客户端设置的http_post_buffer大小不足导致的,解决方法如下:

git config –global https.postBuffer 524288000

git config –global http.postBuffer 524288000

问题二:在web端删除项目后重建 提示已存在

可能是由于缓存的原因 稍等2分钟再重建即可

问题三:不能上传大于10M的文件

需要后台修改

问题四:gitlab备份目录地址修改

转载地址:http://www.zhangluya.com/?p=193


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

#—————————————-

    backup:

    path: “tmp/backups”

#—————————————-

问题五:环境检查

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

问题六:清除缓存

sudo -u git -H bundle exec rake cache:clear RAILS_ENV=production

问题七:备份恢复

备份:

cd /home/git/gitlab

bundle exec rake gitlab:backup:create RAILS_ENV=production

恢复:

bundle exec rake gitlab:backup:restore RAILS_ENV=production BACKUP=111

#这里需填写想恢复文件时间戳

BACKUP=111

问题七:

zhangluyadeMacBook-Pro:~ zhangluya$ git clone git@gitlab.api.hhcc.net:php/mall.api.hhcc.net.git
Cloning into ‘mall.api.hhcc.net’…
GitLab: Failed to authorize your Git request: internal API unreachable
fatal: Could not read from remote repository.


Please make sure you have the correct access rights

and the repository exists

内部错误 设置下本地域名绑定即可:

[root@bj-6-gitlab-01 ~]# cat /etc/hosts

10.10.0.25 gitlab.api.hhcc.net

问题八:雷哥提交

解决办法:主要看以下三点

1:

vim config/unicorn.rb

#———————-

timeout 300 #默认为60 修改为300

#———————-

2:修改nginx  client_max_body_size 2000M;

问题集锦:

https://github.com/gitlabhq/gitlabhq/issues/4437