博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
阿里云部署gitlab填坑记
阅读量:6849 次
发布时间:2019-06-26

本文共 9318 字,大约阅读时间需要 31 分钟。

本文同步自

地址:

我的博客是基于hexo生成的静态博客,每次写完文章,hexo g一下,然后把生成的文件用ftp上传到server,虽然一切正常,但是感觉这种方式很low,想尝试一下自动部署,无奈在服务器上部署git服务器多次,都没能成功,经群里面的大神推荐,于是尝试一把gitlab

像往常一样,不会搞,先在网上找一篇教程,,按照这篇,搞了一边,各种坑,边填坑边记录吧。

软件环境

先来说说我的软件环境

软件 版本
System centos6.7
Python 2.6
Ruby 2.1.5
Git 2.7.0
Redis 2.0
GitLab 7.8.4
GitLab Shell 2.6.0

大概如此。

yum源切换

由于天朝众所周知的原因,为了提高软件安装速度,可以将yum源设置为阿里云开源镜像。

cd /etc/yum.repos.dwget -O 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

安装Git

//查看当前git版本git --version// 如果小于1.7.10则先卸载yum remove git// 下载最新的git并安装wget -O git-src.zip https://github.com/git/git/archive/master.zipunzip git-src.zipcd git-srcmake prefix=/usr/local allmake prefix=/usr/local installln -fs /usr/local/bin/git* /usr/bin/

安装Ruby环境

mkdir /tmp/ruby && cd /tmp/rubycurl --progress ftp://ftp.ruby-lang.org/pub/ruby/ruby-2.1.5.tar.gz | tar xz// 这步有点慢,等的我差点睡着了,基本上一秒钟0.1%    cd ruby-2.1.5./configure --disable-install-rdocmake && make installln -s /usr/local/bin/bundle /usr/bin/bundleln -s /usr/local/bin/ruby /usr/bin/rubyln -s /usr/local/bin/gem /usr/bin/gem// 设置ruby gem源为淘宝源gem source -r https://rubygems.org/gem source -a https://ruby.taobao.org/  //这里应该是https,原文是`http`,也是个坑gem install bundler --no-ri --no-rdoc

安装MySQL及初始化GitLab库

yum install mysql mysql-devel mysql-server -y/etc/init.d/mysqld startchkconfig mysqld on// 登录mysql创建gitab的帐号和数据库mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab';mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';

安装Redis

yum -y install redis/etc/init.d/redis startchkconfig redis on

添加git帐号并允许sudo

useradd --comment 'gitlab' gitecho "git ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers

测试是否可以用git帐号登录数据库

sudo -u git -H mysql -u gitlab -p -D gitlabhq_production

安装GitLab

cd /home/gitsudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-8-stable gitlabcd /home/git/gitlabsudo -u git -H cp config/gitlab.yml.example config/gitlab.yml   //编辑git路径, gitlab的host:portvim config/gitlab.yml// bin_path: /usr/local/bin/git// host: localhost// port: 80    // 给文件夹添加相应的权限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-satellitessudo -u git -H mkdir tmp/pids/sudo -u git -H mkdir tmp/sockets/sudo chmod -R u+rwX  tmp/pids/sudo chmod -R u+rwX  tmp/sockets/sudo -u git -H mkdir public/uploadssudo chmod -R u+rwX  public/uploadssudo -u git -H cp config/unicorn.rb.example config/unicorn.rbsudo -u git -H cp config/initializers/rack_attack.rb.exampleconfig/initializers/rack_attack.rb// 可能某些文件夹已经存在了,直接跳过~~~// 配置数据库连接信息sudo -u git cp config/database.yml.mysql config/database.ymlsudo -u git -H vim  config/database.ymlvim config/database.yml// production:// username: gitlab// password: "gitlab

安装GitLab-Shell

cd /home/gitsudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-shell.git -b v2.6.0cd gitlab-shell/sudo -u git -H cp config.yml.example config.yml// 编辑配置文件, 设置gitlab_url, redis-cli, log-level...vim config.yml// gitlab_url: "http://localhost/"// /usr/bin/redis-cli// 安装git-shellsudo -u git -H ./bin/install

安装需要ruby的gems

在执行下面的命令之前先要把gem的默认源改为淘宝的,虽然前面改过了,但这里还是默认的没改的,不知道怎么回事,需要vim Gemfile,修改source "https://rubygems.org"https://ruby.taobao.org/,注意是https不是http

cd /home/git/gitlabsudo -u git -H bundle install --deployment --without development test postgres aw

这个过程可能会出现下面的错误:

An error occurred while installing rugged (0.21.2), and Bundler cannot continue.Make sure that `gem install rugged -v '0.21.2'` succeeds before bundling.

需要安装:

sudo yum -y install cmake

然后重新执行就OK了。

初始化数据库(创建GitLab相关表)

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

这步完成会出现用户名和密码

Administrator account created:login.........rootpassword......5iveL!fe

安装启动文件以及日志切割文件

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

设置git帐号信息

$ sudo -u git -H git config --global user.name "Reeoo Shen"$ sudo -u git -H git config --global user.email "ireeoo@163.com"$ sudo -u git -H git config --global core.autocrlf input

这一步虽然设置了这些信息,但是到后面执行检查的时候,还是会说你没有设置。。。

安装nginx

我的服务器本来就装的nginx,这一步我就不写了

更改权限,启动nginx

nginx -tchown -R git:git /var/lib/nginx//etc/init.d/nginx start

检测当前环境

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

输出:

[root@iZ234fbksx3Z gitlab]# sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=productionSystem informationSystem:        CentOS 6.7Current User:    gitUsing RVM:    noRuby Version:    2.1.5p273Gem Version:    2.2.2Bundler Version:1.11.2Rake Version:    10.3.2Sidekiq Version:3.3.0GitLab informationVersion:    7.8.4Revision:    019ffd9Directory:    /home/git/gitlabDB Adapter:    mysql2URL:        http://testxxx.reeoo.meHTTP Clone URL:    http://testxxx.reeoo.me/some-project.gitSSH Clone URL:    git@testxxx.reeoo.me:some-project.gitUsing LDAP:    noUsing Omniauth:    noGitLab ShellVersion:    2.6.0Repositories:    /home/git/repositories/Hooks:        /home/git/gitlab-shell/hooks/Git:        /usr/local/bin/git

拉取gitlab静态资源文件

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

启动gitlab

/etc/init.d/gitlab start

检测各个组件是否正常工作

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

这里就是坑了,各种no。。。。

是不是我看错教程了,我怀疑这个教程本来就是跑不通的,尼玛。。。
经过将近一天的折腾,终于把问题降到了就剩下一个了:

Checking Environment ...Git configured for git user? ... yesChecking Environment ... FinishedChecking GitLab Shell ...GitLab Shell version >= 2.5.4 ? ... OK (2.6.0)Repo base directory exists? ... yesRepo base directory is a symlink? ... noRepo base owned by git:git? ... yesRepo base access is drwxrws---? ... yesSatellites access is drwxr-x---? ... yeshooks directories in repos are links: ... reeoo / mytest ... okRunning /home/git/gitlab-shell/bin/checkCheck GitLab API access: OKCheck directories and files:     /home/git/repositories: OK    /home/git/.ssh/authorized_keys: OKTest redis-cli executable: redis-cli 2.4.10Send ping to redis server: PONGgitlab-shell self-check successfulChecking GitLab Shell ... FinishedChecking Sidekiq ...Running? ... yesNumber of Sidekiq processes ... 1Checking Sidekiq ... FinishedChecking LDAP ...LDAP is disabled in config/gitlab.ymlChecking LDAP ... FinishedChecking GitLab ...Database config exists? ... yesDatabase is SQLite ... noAll migrations up? ... yesDatabase contains orphaned GroupMembers? ... noGitLab config exists? ... yesGitLab config outdated? ... noLog directory writable? ... yesTmp directory writable? ... yesInit script exists? ... yesInit script up-to-date? ... no  Try fixing it:  Redownload the init script  For more information see:  doc/install/installation.md in section "Install Init Script"  Please fix the error above and rerun the checks.projects have namespace: ... reeoo / mytest ... yesProjects have satellites? ... reeoo / mytest ... yesRedis version >= 2.0.0? ... yesRuby version >= 2.0.0 ? ... yes (2.1.5)Your git bin path is "/usr/local/bin/git"Git version >= 1.7.10 ? ... yes (2.7.0)Checking GitLab ... Finished

就是这个

Init script up-to-date? ... no  Try fixing it:  Redownload the init script  For more information see:  doc/install/installation.md in section "Install Init Script"  Please fix the error above and rerun the checks.

有人说可以忽略这个,我也没找到解决方案,只能暂时忽略了,不知道后面的本地clone仓库里面的代码老是要求输入密码,是不是跟这个也有关系。

最后访问testxxx.reeoo.me出现502 Bad GateWay

查询nginx日志,
tail /var/log/nginx/gitlab_error.log
发现是"/home/git/gitlab/public/favicon.ico.html" failed (13: Permission denied)

加上权限,chmod 775 /home/gittestxxx.reeoo.me可以访问了(之前的那个检查里面有好多有问题的时候,貌似testxxx.reeoo.me也是可以正常访问的),新建个项目,发现不能commit

Your changes could not be committed, because the file has been changed(在gitlab服务器上commit
commit就报这个错。。。
发现gitlab-shell/config.yml里面的gitlab_url: "testxxx.reeoo.me:80"是这样的,
改成gitlab_url: "http://testxxx.reeoo.me"重启再试,我靠,好了,Your changes have been successfully committed

问题

  1. 前面说到设置了git的信息,但执行检查的时候,还是会说你没有设置git信息,

    参考

解决了

  1. 关于redis配置的错误:

    sudo -u git ./check    Check GitLab API access: OK    Check directories and files:            /home/git/repositories: OK            /home/git/.ssh/authorized_keys: OK    Test redis-cli executable: redis-cli 2.4.10    Send ping to redis server: Could not connect to Redis at /var/run/redis/redis.sock: No such file or directory

    到/home/git/gitlab-shell/config.yml里面把socket注掉,重新运行检查就好了:

    redis:      bin: /usr/bin/redis-cli      # host: 127.0.0.1      # port: 6379      # pass: redispass # Allows you to specify the password for Redis      database: 0      #socket: /var/run/redis/redis.sock # Comment out this line if you want to use TCP //把这行注掉      namespace: resque:gitlab
  2. 期间还遇到一个问题,说可用内存不足的(我的阿里云服务器单核1G内存),网上查了一下,貌似需要做别的处理,挺麻烦,直接又花了400RMB把内存升级到了2G。

  3. 最后一个问题,也是发这篇文章的时候还没解决的:

    把ssh key上传到gitlab之后,clone仓库,老是要求输入密码,但是密码怎么输都不对,不知道怎么回事,百度谷歌了N多资料,也没有解决,目前gitlab算是部署了,但是不能clone,更别提pull,commit,push了,继续折腾中。。。。

等把这个问题解决了,在折腾自动部署的功能。

最后希望遇到过上面第三个问题的网友,说说解决方法,或者探讨一下,谢谢!

转载地址:http://hdgul.baihongyu.com/

你可能感兴趣的文章
观察者模式
查看>>
Android WebView缓存机制详解
查看>>
Linux iptables命令高级网络
查看>>
STL中mem_fun和mem_fun_ref的用法
查看>>
Mysql管理总结
查看>>
Exchange2007的规划和安装
查看>>
同步时间
查看>>
去除TFS版本控制信息
查看>>
南海区妇幼保健院HIS数据容灾备份系统项目
查看>>
思科3560交换机端口限速
查看>>
linux网络设备无法启动问题处理
查看>>
生活大爆炸系列之磨望远镜
查看>>
文档:Windows Server 2012 配置Hyper-V复制
查看>>
正则表达式
查看>>
Angular企业级开发(1)-AngularJS简介
查看>>
如何查看自己电脑系统的安装日期-Window上
查看>>
tomcat 连接数设置(转)
查看>>
Windows压缩包安装MySQL
查看>>
13040:All in All
查看>>
动态规划
查看>>