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

[经验分享] centos6安装gitlab

[复制链接]

尚未签到

发表于 2018-9-19 11:42:26 | 显示全部楼层 |阅读模式
  #刚玩博客还不会排版,其实这是我写的一键脚本,不小心给自己点个赞(汗!)
  #谷歌你最好的老师没有之二
  #gitlab基于ruby开发模仿Github的版本控制软件,因为是开源的,,但是我们确实有这样的需求,相比Gtihub来说可以减少很多成本.
  #从安装ruby、git、数据库、web、和gitlab到访问,一定要有耐心.
  #安装环境:
  ##[root@localhost config]# uname -r
  ##2.6.32-279.el6.x86_64
  ##[root@localhost config]# cat /etc/redhat-release

  ##CentOS>  一.安装依赖
  ## 安装epel-release
  yum -y install http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
  #安装ruby依赖包
  ## packages (from rvm install message):
  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 mysql-devel
  #安装或者更新git
  yum -y remove git
  yum -y install zlib-devel openssl-devel cpio expat-devel gettext-devel curl-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
  wget http://git-core.googlecode.com/files/git-1.8.3.4.tar.gz
  tar -zxf git-1.8.3.4.tar.gz
  cd git-1.8.3.4
  make prefix=/usr all
  make prefix=/usr install
  cd ..
  #安装前版本
  [root@gitlab ~]# git --version
  git version 1.7.1
  #安装后版本
  [root@gitlab ~]# git --version
  git version 1.8.3.4
  二.安装RVM
  #RVM工具
  curl -L get.rvm.io | bash -s stable
  #出现以下信息为安装成功
  # Administrator,
  #
  #   Thank you for using RVM!
  #   We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
  #
  # ~Wayne, Michal & team.
  #加载RVM,改名(使用淘宝源)
  source /etc/profile.d/rvm.sh
  cp /usr/local/rvm/config/db  /usr/local/rvm/config/db.bk
  sed -i 's#ftp.ruby-lang.org/pub/ruby#ruby.taobao.org/mirrors/ruby#' /usr/local/rvm/config/db
  sed -i 's#cache.ruby-lang.org/pub/ruby#ruby.taobao.org/mirrors/ruby#' /usr/local/rvm/config/db
  #安装libyaml(防止后期报错,可不装)
  rvm pkg install libyaml
  三.安装ruby
  #安装ruby
  #rvm install 2.0.0-p247 --with-libyaml-dir=/usr/local/rvm/usr
  #rvm --default use 2.0.0-p247
  rvm install 2.0.0-p353 --with-libyaml-dir=/usr/local/rvm/usr
  rvm --default use 2.0.0-p353
  #引用淘宝ruby源
  gem sources --remove https://rubygems.org/
  gem sources -a http://ruby.taobao.org/
  gem sources -l
  #安装bundler
  gem install bundler --no-ri --no-rdoc
  四.安装gitlab-shell
  #创建用户git
  adduser --system --create-home --comment 'GitLab' git
  #复制gitlab-shell到本地
  su - git -c "git clone https://github.com/gitlabhq/gitlab-shell.git"
  su - git -c "cd gitlab-shell;git checkout v1.7.0"
  ##修改配置文件
  su - git -c "cp gitlab-shell/config.yml.example gitlab-shell/config.yml"
  ##安装
  su - git -c "gitlab-shell/bin/install"
  五.安装Redis和mysql
  #安装Redis,据说高级特性需要
  yum -y install redis ;service redis start ; chkconfig redis on
  #安装mysql
  #安装Mysql数据库.略过,以及数据库操作
  ##yum install -y mysql-server mysql-devel ; chkconfig mysqld on ; service mysqld start
  #编译安装宣告下变量
  ##export PATH="/opt/mysql/bin:$PATH"
  ##echo "export PATH="/opt/mysql/bin:$PATH"">>/etc/profile
  ##修改root密码
  #echo "UPDATE mysql.user SET Password=PASSWORD('$MYSQL_ROOT_PW') WHERE User='root'; FLUSH PRIVILEGES;" | mysql -u root
  ##创建gitlab数据库
  #echo "CREATE DATABASE IF NOT EXISTS gitlabhq_production DEFAULT CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';" | mysql -u root
  CREATE DATABASE IF NOT EXISTS gitlabhq_production DEFAULT CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
  ##创建连接数据库用户

  grant  all on  gitlabhq_production.* to gitlab@localhost>  六.安装gitlab
  #复制GitLab到本地
  su - git -c "git clone https://github.com/gitlabhq/gitlabhq.git gitlab"
  ## 检查
  su - git -c "cd gitlab;git checkout 5-4-stable"
  #以下操作在/home/git/gitlab
  cd /home/git/gitlab
  ### 复制配置文件
  su git -c "cp config/gitlab.yml.example config/gitlab.yml"
  ### 修改配置文件主机名(可以不做)
  sed -i "s/  host: localhost/  host: gitlab.test/g" config/gitlab.yml
  ### 修改邮件地址
  sed -i "s/from: gitlab@localhost/from: gitlab@gitlab.test/g" config/gitlab.yml
  #修改puma.rb文件
  su git -c "cp config/puma.rb.example config/puma.rb"
  sed -i "s/0.0.0.0:9292/127.0.0.1:3000/g" /home/git/gitlab/config/puma.rb
  sed -i "s/# bind/bind/g" /home/git/gitlab/config/puma.rb
  #为git用户授权
  su git -c "chown -R git /home/git/gitlab/log/;chmod -R u+rwx /home/git/gitlab/log/;chown -R git /home/git/gitlab/tmp/;chmod -R u+rwx /home/git/gitlab/tmp/;mkdir /home/git/gitlab-satellites;mkdir /home/git/gitlab/tmp/pids/;chmod -R u+rwx /home/git/gitlab/tmp/pids/;mkdir /home/git/gitlab/tmp/sockets/;chmod -R u+rwx /home/git/gitlab/tmp/sockets/;mkdir /home/git/gitlab/public/uploads;chmod -R u+rwX /home/git/gitlab/public/uploads"
  ### 复制数据配置文件
  su git -c "cp config/database.yml.mysql config/database.yml"
  ### 设置mysql用户和密码
  sed -i "s/root/gitlab/g" config/database.yml
  sed -i "s/secure password/123456/g" config/database.yml
  ### 配置git用户
  su git -c 'git config --global user.name  "GitLab"'
  su git -c 'git config --global user.email "gitlab@$GL_HOSTNAME"'
  七.安装 Gems
  ## 安装
  gem install charlock_holmes --version '0.6.9'
  #bundle使用淘宝源,并且安装(时间长.)
  sed -i '1s/https/http/g' /home/git/gitlab/Gemfile
  sed -i '1s/rubygems/ruby.taobao/g' /home/git/gitlab/Gemfile
  #安装bundle
  su git -c "bundle install --deployment --without development test postgres"
  八.初始化数据库
  #初始化数据库
  export force=yes
  su git -c "bundle exec rake gitlab:start RAILS_ENV=production"
  su git -c "bundle exec rake gitlab:setup RAILS_ENV=production"
  #初始化在数据库里添加数据,最后后会出现:
  #用户名:admin@local.host
  #密  码:5iveL!fe
  #su git -c "bundle exec rake gitlab:env:info RAILS_ENV=production"
  九.启动脚本
  #curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab-centos
  #chmod +x /etc/init.d/gitlab
  curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/5-1-stable/init.d/gitlab
  chmod +x /etc/init.d/gitlab
  #在17行后添加2行内容
  sed -i "17 a source /etc/profile.d/rvm.sh\nrvm use 1.9.3-p448" /etc/init.d/gitlab
  #或者复制
  ##cp /home/git/gitlab/lib/support/init.d/gitlab   /etc/init.d/
  #添加到开机启动项
  chkconfig gitlab on
  #启动
  /etc/init.d/gitlab start
  十.配置web站点
  #配置nginx
  #安装nginx,(编译安装和rpm都能实现)
  # yum -y install nginx
  #下载nginx下的gitlab.conf文件
  curl --output /etc/nginx/conf.d/gitlab.conf https://raw.github.com/gitlabhq/gitlab-recipes/5-1-stable/nginx/gitlab
  #修改下server标签监听端口和域名
  vim /etc/nginx/conf.d/gitlab.conf
  server {
  listen 80;
  server_name gitlab.wine.cn;
  #..略..
  }
  更改安装目录权限
  # chown -R git:git /etc/nginx
  #更改nginx所属用户
  #注意:
  #需要nginx用户改为git,否则会出现502访问错误.
  vim /etc/nginx/nginx.conf
  #user              nginx;
  user              git;
  /etc/init.d/gitlab start
  /etc/init.d/nginx start
  #然后访问
  gitlab.wine.cn
  #####以下是报错环节,没怎么整理很乱###################
  [root@gitlab init.d]# sh gitlab start
  Could not find mysql2-0.3.11 in any of the sources
  Run `bundle install` to install missing gems.
  #解决
  yum install mysql-devel
  gem install mysql2 -v '0.3.11'
  -------------------------------------
  #检查
  [root@gitlab gitlab]# /home/git/gitlab-shell/bin/check
  Check GitLab API access: FAILED. code: 502
  Check directories and files:
  /home/git/repositories: OK
  /home/git/.ssh/authorized_keys: OK
  #解决:nginx与gitlab之间权限问题
  ------------------------
  --------------------------------------------
  #su git -c "bundle install --deployment --without development test postgres"

  /usr/bin/ld: /usr/local/lib/libz.a(crc32.o):>  /usr/local/lib/libz.a: could not read symbols: Bad value
  collect2: ld 返回 1
  make: *** [nokogiri.so] 错误 1
  make failed, exit code 2
  Gem files will remain installed in /home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/nokogiri-1.5.9 for inspection.
  Results logged to /home/git/gitlab/vendor/bundle/ruby/2.0.0/extensions/x86_64-linux/2.0.0/nokogiri-1.5.9/gem_make.out
  An error occurred while installing nokogiri (1.5.9), and Bundler cannot continue.
  Make sure that `gem install nokogiri -v '1.5.9'` succeeds before bundling.
  #安装gem install nokogiri -v '1.5.9'
  linking shared-object nokogiri/nokogiri.so

  /usr/bin/ld: /usr/local/lib/libz.a(crc32.o):>  /usr/local/lib/libz.a: could not read symbols: Bad value
  collect2: ld returned 1 exit status
  make: *** [nokogiri.so] Error 1
  make failed, exit code 2
  Gem files will remain installed in /usr/local/rvm/gems/ruby-2.0.0-p247/gems/nokogiri-1.5.9 for inspection.
  Results logged to /usr/local/rvm/gems/ruby-2.0.0-p247/extensions/x86_64-linux/2.0.0/nokogiri-1.5.9/gem_make.out
  #yum后还报错
  [root@gitlab gitlab]# gem install nokogiri -v '1.5.9'
  ERROR:  While executing gem ... (Zlib::DataError)
  invalid stored block lengths
  #解决
  安装zlib
  cd zlib
  CFLAGS="-O3 -fPIC" ./configure
  make&&make install
  #然后在安装
  gem install nokogiri -v '1.5.9'
  ----------------------------
  ----------------------------
  ###
  [root@gitlab init.d]# bundle exec rake gitlab:env:info RAILS_ENV=production
  (in /home/git/gitlab)
  rake aborted!
  Cant connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
  /home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `connect`
  /home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in initialize
  #使用下面,然后就不报了
  #ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
  -------------------------------------------
  相关资料网站:
  https://gitlab.com/gitlab-org/gitlab-recipes/tree/master/install/centos
  https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md
  http://linuxblind.blog.51cto.com/7616603/1277018
  http://www.chenshake.com/centos-6-4-installing-and-using-gitlab/#Gitlab
  https://github.com/shake/gitlab-installer
  http://tz100.me/494.html


运维网声明 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-594221-1-1.html 上篇帖子: 配置gitlab环境实现代码管理及Web Hook测试和ldap认证 下篇帖子: gitlab 安装报错:Could not find modernizr-2.6.2 in any of the sources-David
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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