云中漫步 发表于 2018-9-19 10:14:05

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)
  换成淘宝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
  c5377eca4837968d043b681f00a852a262f0f5f6go1.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/example@example.com/gitlab@git.aa.com/g' config/gitlab.yml
  新建和配置相关目录权限:
  $chown -R git log/tmp/
  $chmod -R u+rwxlog/tmp/
  $mkdir /home/git/gitlab-satellites
  $mkdir -p public/uploads&& chmod -R u+rwxpublic/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 "^$"
  userroot git;
  worker_processes2;
  error_loglogs/error.lognotice;
  pid      logs/nginx.pid;
  events {
  worker_connections1024;
  }
  http {
  include       mime.types;
  default_typeapplication/octet-stream;
  sendfile      on;
  keepalive_timeout65;
  server {
  listen       80;
  server_namelocalhost;
  location / {
  root   html;
  indexindex.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://user@git.aa.com/project

页: [1]
查看完整版本: CentOS 下gitlab-8.5安装配置