设为首页 收藏本站
查看: 1649|回复: 0

[经验分享] Gitlab完整搭建手册+排错

[复制链接]

尚未签到

发表于 2018-9-19 11:12:06 | 显示全部楼层 |阅读模式
  GitLab,是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。
  它拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。
  开源项目地址:https://github.com/gitlabhq/gitlabhq
1  2
  3
  4
  5
  6
  7
  8
# Distribution      : CentOS 6.5 Minimal  # GitLab version    : 7.4.5
  # GitLab-shell      : 2.0.1
  # Ruby version      : ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
  # Gem version       : 2.2.2
  # Redis-server      : Redis server version 2.4.10 (00000000:0)
  # Web Server        : Nginx/1.0.15
  # Database          : MySQL/5.5.40
  一,安装源和依赖包
1  2
  3
  4
  5
  6
  7
  8
  9
cd /usr/local/src  #增epel源,如果你是i686系统,请把x86_64修改下。
yum install http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm#确认是否安装成功  rpm -qa gpg*
  gpg-pubkey-0608b895-4bd22942
  二,安装依赖包
1  2
  3
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
  安装邮件服务
  postfix或者sendmail,官网上安装是postfix,本人默认就装来sendmail,所以此步骤省略
  三,安装git
  默认centos的git版本是1.7.10,所以要先删除,然后再下载源码安装
1  2
  3
  4
  5
  6
  7
  8
  9
yum remove git -y  yum install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-devel openssl-devel
  mkdir /tmp/git && cd /tmp/git
  curl --progress https://www.kernel.org/pub/software/scm/git/git-2.1.3.tar.gz | tar xz
  cd  git-2.1.3/ && ./configure && make && make prefix=/usr/local install
  完成后验证
1  2
  3
  4
  5
which git  /usr/local/bin/git
  git --version
  git version 2.1.3
  四,安装ruby
  ruby版本需要2.0+,所以先卸载系统已存在的
1  2
  3
  4
  5
  6
  7
  8
  9
yum remove ruby  #如果是源码安装的
  cd (your-ruby-source-path) && make uninstall
  mkdir /tmp/ruby && cd /tmp/ruby
  curl --progress ang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz | tar xz
  cd ruby-2.1.2 && ./configure --disable-install-rdoc && make && make prefix=/usr/local install
  #引用淘宝ruby源
  gem sources --remove https://rubygems.org/
  gem sources -a https://ruby.taobao.org/           ##注意加https
  gem sources -l
  安装bundler
1gem install bundler --no-doc  完成后验证
1  2
  3
  4
  5
which ruby  /usr/local/bin/ruby
  ruby -v
  ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
  五,创建系统用户
1adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git  增加/usr/local/bin
1  2
  3
visudo  #修改以下内容
  Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
  六,安装mysql
  官网给出两个选择,mysql、postgreSQL,我使用的mysql
  centos默认会安装5.1版本的mysql,所以要源码安装,此步骤掠过。。。
1  2
  3
#mysql的版本至少5.5.14或更新  mysql --version
  mysql  Ver 14.14 Distrib 5.5.40, for Linux (x86_64) using readline 5.1
  创建数据库用户并授权
1  2
  3
  4
  5
  6
  7
  8
  9
  10
  11
  12
  13
  14
  15
mysql -u root -p  mysql> CREATE USER 'git'@'localhost'>  mysql> show variables like "%engine";
  +------------------------+--------+
  | Variable_name          | Value  |
  +------------------------+--------+
  | default_storage_engine | InnoDB |
  | storage_engine         | InnoDB |
  +------------------------+--------+
  2 rows in set (0.01 sec)
  #如果不是InnoDB引擎,需执行下面命令
  mysql> SET storage_engine=INNODB;
  创建数据库
1mysql> CREATE DATABASE IF NOT EXISTS gitlabhq_production DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;  给用户授权
1mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX,>
  测试是否能够成功登录
1  2
  3
  4
  5
  6
  7
  8
  9
  10
  11
  12
  13
  14
  15
  16
  17
mysql -ugit -pgitpwd -D gitlabhq_production  Reading table information for completion of table and column names
  You can turn off this feature to get a quicker startup with -A
  Welcome to the MySQL monitor.  Commands end with ; or \g.

  Your MySQL connection>  Server version: 5.5.40-log Source distribution
  Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
  Oracle is a registered trademark of Oracle Corporation and/or its
  affiliates. Other names may be trademarks of their respective
  owners.
  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  mysql> \q
  七,配置redis
1  2
  3
  4
  5
  6
  7
  8
  9
  10
  11
chkconfig redis on  cp /etc/redis.conf /etc/redis.conf.orig
  #修改监听端口
  sed 's/^port .*/port 0/' /etc/redis.conf.orig |tee /etc/redis.conf
  #增加内容
  echo 'unixsocket /var/run/redis/redis.sock' |tee -a /etc/redis.conf
  echo -e 'unixsocketperm 0770' |tee -a /etc/redis.conf
  创建目录改权限
1  2
  3
  4
  5
mkdir /var/run/redis  chown redis:redis /var/run/redis
  chmod 755 /var/run/redis
  启动服务
1service redis restart  附加git到redis组
1usermod -aG redis git  八,安装gitlab
1  2
  3
  4
cd /home/git  #下载源码
  sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-4-stable gitlab
  修改配置
1  2
  3
  4
  5
  6
  7
  8
  9
  10
cd gitLab/  sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
  sudo -u git -H vim config/gitlab.yml
  gitlab:
  ## Web server settings (note: host is the FQDN, do not include http://)
  host: www.gitlab.com
  port: 80
  https: false
  修改目录权限
1  2
  3
  4
  5
  6
  7
chown -R git log/  chown -R git tmp/
  chmod -R u+rwX log/
  chmod -R u+rwX tmp/
  chmod -R u+rwX tmp/pids/
  chmod -R u+rwX tmp/sockets/
  chmod -R u+rwX  public/uploads
  创建目录
1  2
sudo -u git -H mkdir /home/git/gitlab-satellites  chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites
  编辑配置文件unicorn.rb
1  2
  3
  4
  5
  6
  7
  8
  9
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb  #查看系统核心数
  nproc
  4
  #编辑配置
  sudo -u git -H vim config/unicorn.rb
  worker_processes 4
  拷贝配置文件rack_attack.rb
1sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb  定义全局的用户和邮箱
1  2
  3
sudo -u git -H git config --global user.name "GitLab"  sudo -u git -H git config --global user.email "example@example.com"
  sudo -u git -H git config --global core.autocrlf input
  编辑连接redis配置
1  2
  3
  4
  5
#拷贝配置  sudo -u git -H cp config/resque.yml.example config/resque.yml
  #连接redis配置,默认配置,未修改
  sudo -u git -H vim config/resque.yml
  九,配置gitlab数据库文件
1  2
  3
  4
  5
  6
  7
  8
  9
  10
  11
  12
  13
  14
  15
  16
  17
  18
sudo -u git cp config/database.yml.mysql config/database.yml  #编辑配置文件
  sudo -u git -H vim config/database.yml
  production:
  adapter: mysql2
  encoding: utf8
  collation: utf8_general_ci
  reconnect: false
  database: gitlabhq_production
  pool: 10
  username: git
  password: "gitpwd"
  host: localhost
  socket: /var/lib/mysql/mysql.sock
  #修改文件权限,只有git用户可读
  sudo -u git -H chmod o-rwx config/database.yml
  十,安装gem
1  2
  3
cd /home/git/gitLab  sudo -u git -H bundle install --deployment --without development test postgres aws
  #错误1:
  各种安装失败
  解决:
  修改Gemfile下的http://ruby.taobao.org/
  为:
  https://ruby.taobao.org/
#出现错误2:Could not find modernizr-2.6.2 in any of the sources  #解决办法:
  [git@Git gitlab]$ vi Gemfile
  第114行   gem "modernizr",        "2.6.2"
  更改改为:
  第114行   gem "modernizr-rails",  "2.7.1"
  [git@Git gitlab]$ vi Gemfile.lock
  第252行     modernizr (2.6.2)
  更改改为:
  第252行     modernizr-rails (2.7.1)
  第523行   modernizr (= 2.6.2)
  更改改为:
  第523行   modernizr-rails (= 2.7.1)
  重新执行
  su git -c "bundle install --deployment --without development test postgres"
  #出现错误3:
DSC0000.png 执行bundle install进行安装

  十一,安装gitlab-shell
  官网上给的gitlab-shell版本是2.1.0,后面会有问题(本地到远程不能连接),网上查找问题是版本问题,需要gitlab-shell的版本是2.0.1
1  2
  3
  4
  5
  6
  7
  8
  9
  10
  11
  12
  13
  14
  15
  16
  17
sudo -u git -H bundle exec rake gitlab:shell:install[v2.0.1] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production  #编辑配置
  sudo -u git -H vim /home/git/gitlab-shell/config.yml
  ---
  user: git
  gitlab_url: https://localhost/
  http_settings:
  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
  socket: "/var/run/redis/redis.sock"
  log_level: INFO
  audit_usernames: false
  十二,初始化数据库
1  2
  3
  4
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=newpassword
  十三,配置服务脚本
1  2
  3
  4
  5
  6
  7
  8
  9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  wget -O /etc/init.d/gitlab DSC0001.jpg https://raw.github.com/gitlabhq/gitlab-recipes/master/init/sysvinit/centos/gitlab-unicorn
  ## 或者复制本地的(本地的根网上下的脚本略有差异)cp /home/git/gitlab/lib/support/init.d/gitlab /etc/init.d/gitlab
  chmod +x /etc/init.d/gitlab
  chkconfig --add gitlab
  chkconfig gitlab on
  #设置logrotate
  cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
  #检测应用状态
  sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
  sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
  #启动服务
  service gitlab start
  ##如果出现报错:
  Starting unicorn: bin/web: line 21: bundle: command not found
  修改/etc/profile
  把bundle的路径加到环境变量里
  export PATH=/usr/local/mysql/bin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
  十四,配置web服务
1  2
  3
  4
  5
  6
#本人使用的nginx  yum -y install nginx
  chkconfig nginx on
  vim /etc/nginx/conf.d/gitlab.conf
  # GITLAB
  # Maintainer: @randx
  # App Version: 5.0
  upstream gitlab {
  server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
  }
  server {
  listen 192.168.0.210:80 default_server;         # e.g., listen 192.168.1.1:80;
  server_name www.gitlab.com;     # e.g., server_name source.example.com;
  root /home/git/gitlab/public;
  # individual nginx logs for this gitlab vhost
  access_log  /var/log/nginx/gitlab_access.log;
  error_log   /var/log/nginx/gitlab_error.log;
  location / {
  # serve static files from defined root folder;.
  # @gitlab is a named location for the upstream fallback, see below
  try_files $uri $uri/index.html $uri.html @gitlab;
  }
  # if a file, which is not found in the root folder is requested,
  # then the proxy pass the request to the upsteam (gitlab unicorn)
  location @gitlab {
  proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
  proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
  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_pass http://gitlab;
  }
  }
  添加nginx用户到git组
1  2
  3
usermod -a -G git nginx  chmod g+rx /home/git/
  #修改下server标签监听端口和域名
  vim /etc/nginx/conf.d/gitlab.conf
  server {
  listen x.x.x.x:80;
  server_name www.gitlab.com;
  #..略..
  }
  启动服务
1  2
  3
  4
  5
service nginx start  #访问登录
  #用户名:root
  #密码:5iveL!fe
DSC0002.png

  #问题一
  #================================
1  2
  3
  4
  5
  6
  7
  8
  9
  10
  11
#报错信息:  sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
  This will create the necessary database tables and seed the database.
  You will lose any previous data stored in the database.
  Do you want to continue (yes/no)? yes
  Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "collation"=>"utf8_general_ci", "reconnect"=>false, "database"=>"gitlabhq_production", "pool"=>10, "username"=>"git", "password"=>"gitpwd"}, {:charset=>"utf8", :collation=>"utf8_general_ci"}
  (If you set the charset manually, make sure you have a matching collation)
  -- enable_extension("plpgsql")
  rake aborted!
  Mysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
1  2
  3
  4
#解决办法:  vim config/database.yml
  #mysql.sock的位置指定,默认在/tmp目录下
  socket: /var/lib/mysql/mysql.sock
  #============================
  #问题二
  #============================
1  2
  3
  4
  5
  6
  7
  8
  9
#报错信息:  Running /home/git/gitlab-shell/bin/check
  Check GitLab API access: /home/git/gitlab-shell/lib/gitlab_net.rb:122:in `read': No such file or directory @ rb_sysopen - /home/git/gitlab-shell/.gitlab_shell_secret (Errno::ENOENT)
  from /home/git/gitlab-shell/lib/gitlab_net.rb:122:in `secret_token'
  from /home/git/gitlab-shell/lib/gitlab_net.rb:79:in `get'
  from /home/git/gitlab-shell/lib/gitlab_net.rb:39:in `check'
  from /home/git/gitlab-shell/bin/check:11:in `''
  #之前提到过的,由于gitlab-shell版本问题导致,按照我安装的版本应该没什么问题。
  #============================
  #问题三
  #============================

  遇到这类问题仔细检查几个文件
  /home/git/gitlab/config/unicorn.rb:配置ruby提供的服务端口,ip
  /home/git/gitlab/config/gitlab.yml:配置gitlab服务的端口,ip
  /home/git/gitlab-shell/config.yml:配置gitlab-shell要调用的API接口
  unicorn.rb:第40行改成
  listen ”192.168.0.210:8000″, :tcp_nopush => true
  gitlab.yml:第18行和第19行改成
  host: 192.168.0.210
  port: 8000
  config.yml:第5行改成
  gitlab_url: ”http://192.168.0.210:8000/
  切记这个端口不与nginx启动的端口冲突,完成后重启gitlab,登录www.gitlab.com进行登录
  #============================
  #问题四
  #============================
  编辑 gitlab.yml , 找到如下部分:
## Gravatargravatar:    enabled: true                 # Use user avatar image from Gravatar.com (default: true)  
    # gravatar urls: possible placeholders: %{hash} %{size} %{email}
  
    # plain_url: "http://..."     # default: http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon
  
    # ssl_url:   "https://..."    # default: https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon
  把 plain_url 的注释去掉,写成如下内容:
plain_url: "http://gravatar.duoshuo.com/avatar/%{hash}?s=%{size}&d=identicon"  重启服务
  如果gitlab不是新搭建的,依然会有一些头像地址会指向原先的地址,需要执行下面的命令修正缓存数据
rake cache:clear RAILS_ENV=production


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-594191-1-1.html 上篇帖子: gitlab haproxy ssl 配置 下篇帖子: 快速安装部署gitlab中文版
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表