本文同步自个人博客
地址:http://www.reeoo.me/archives/gitlab.htmlhtml
个人博客是基于hexo
生成的静态博客,每次写完文章,hexo g
一下,而后把生成的文件用ftp
上传到server
,虽然一切正常,可是感受这种方式很low
,想尝试一下自动部署,无奈在服务器上部署git
服务器屡次,都没能成功,经群里面的大神推荐,因而尝试一把gitlab
mysql
像往常同样,不会搞,先在网上找一篇教程,CentOS安装GitLab,按照这篇,搞了一边,各类坑,边填坑边记录吧。nginx
先来讲说个人软件环境c++
软件 | 版本 |
---|---|
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 |
大概如此。git
因为天朝众所周知的缘由,为了提升软件安装速度,能够将yum
源设置为阿里云开源镜像。github
cd /etc/yum.repos.d wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
可是某些包仍是安装的很慢。redis
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 --version // 若是小于1.7.10则先卸载 yum remove git // 下载最新的git并安装 wget -O git-src.zip https://github.com/git/git/archive/master.zip unzip git-src.zip cd git-src make prefix=/usr/local all make prefix=/usr/local install ln -fs /usr/local/bin/git* /usr/bin/
mkdir /tmp/ruby && cd /tmp/ruby curl --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-rdoc make && make install ln -s /usr/local/bin/bundle /usr/bin/bundle ln -s /usr/local/bin/ruby /usr/bin/ruby ln -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
yum install mysql mysql-devel mysql-server -y /etc/init.d/mysqld start chkconfig 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';
yum -y install redis /etc/init.d/redis start chkconfig redis on
useradd --comment 'gitlab' git echo "git ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
sudo -u git -H mysql -u gitlab -p -D gitlabhq_production
cd /home/git sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-8-stable gitlab cd /home/git/gitlab sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml //编辑git路径, gitlab的host:port vim 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-satellites sudo -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/uploads sudo chmod -R u+rwX public/uploads sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb // 可能某些文件夹已经存在了,直接跳过~~~ // 配置数据库链接信息 sudo -u git cp config/database.yml.mysql config/database.yml sudo -u git -H vim config/database.yml vim config/database.yml // production: // username: gitlab // password: "gitlab
cd /home/git sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-shell.git -b v2.6.0 cd 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-shell sudo -u git -H ./bin/install
在执行下面的命令以前先要把gem
的默认源改成淘宝的,虽然前面改过了,但这里仍是默认的没改的,不知道怎么回事,须要vim Gemfile
,修改source "https://rubygems.org"
为https://ruby.taobao.org/
,注意是https
不是http
sql
cd /home/git/gitlab sudo -u git -H bundle install --deployment --without development test postgres aw
这个过程可能会出现下面的错误:shell
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了。
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
这步完成会出现用户名和密码
Administrator account created: login.........root password......5iveL!fe
安装启动文件以及日志切割文件
cp lib/support/init.d/gitlab /etc/init.d/gitlab cp lib/support/init.d/gitlab.default.example /etc/default/gitlab cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
$ 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 -t chown -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=production System information System: CentOS 6.7 Current User: git Using RVM: no Ruby Version: 2.1.5p273 Gem Version: 2.2.2 Bundler Version:1.11.2 Rake Version: 10.3.2 Sidekiq Version:3.3.0 GitLab information Version: 7.8.4 Revision: 019ffd9 Directory: /home/git/gitlab DB Adapter: mysql2 URL: http://testxxx.reeoo.me HTTP Clone URL: http://testxxx.reeoo.me/some-project.git SSH Clone URL: git@testxxx.reeoo.me:some-project.git Using LDAP: no Using Omniauth: no GitLab Shell Version: 2.6.0 Repositories: /home/git/repositories/ Hooks: /home/git/gitlab-shell/hooks/ Git: /usr/local/bin/git
sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
/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? ... yes Checking Environment ... Finished Checking GitLab Shell ... GitLab Shell version >= 2.5.4 ? ... OK (2.6.0) Repo base directory exists? ... yes Repo base directory is a symlink? ... no Repo base owned by git:git? ... yes Repo base access is drwxrws---? ... yes Satellites access is drwxr-x---? ... yes hooks directories in repos are links: ... reeoo / mytest ... ok Running /home/git/gitlab-shell/bin/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: PONG gitlab-shell self-check successful Checking GitLab Shell ... Finished Checking Sidekiq ... Running? ... yes Number of Sidekiq processes ... 1 Checking Sidekiq ... Finished Checking LDAP ... LDAP is disabled in config/gitlab.yml Checking LDAP ... Finished Checking GitLab ... Database config exists? ... yes Database is SQLite ... no All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config outdated? ... no Log directory writable? ... yes Tmp directory writable? ... yes Init script exists? ... yes 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. projects have namespace: ... reeoo / mytest ... yes Projects have satellites? ... reeoo / mytest ... yes Redis version >= 2.0.0? ... yes Ruby 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/git
,testxxx.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
。
前面说到设置了git的信息,但执行检查的时候,仍是会说你没有设置git信息,
参考Error in Gitlab: git configured for git user … no try fixing it
解决了
关于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
期间还遇到一个问题,说可用内存不足的(个人阿里云服务器单核1G内存),网上查了一下,貌似须要作别的处理,挺麻烦,直接又花了400RMB把内存升级到了2G。
最后一个问题,也是发这篇文章的时候还没解决的:
把ssh key上传到gitlab以后,clone仓库,总是要求输入密码,可是密码怎么输都不对,不知道怎么回事,百度谷歌了N多资料,也没有解决,目前gitlab
算是部署了,可是不能clone
,更别提pull
,commit
,push
了,继续折腾中。。。。
等把这个问题解决了,在折腾自动部署的功能。
最后但愿遇到过上面第三个问题的网友,说说解决方法,或者探讨一下,谢谢!