阿里雲部署gitlab填坑記

本文同步自個人博客
地址:http://www.reeoo.me/archives/gitlab.htmlhtml

個人博客是基於hexo生成的靜態博客,每次寫完文章,hexo g一下,而後把生成的文件用ftp上傳到server,雖然一切正常,可是感受這種方式很low,想嘗試一下自動部署,無奈在服務器上部署git服務器屢次,都沒能成功,經羣裏面的大神推薦,因而嘗試一把gitlabmysql

像往常同樣,不會搞,先在網上找一篇教程,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源切換

因爲天朝衆所周知的緣由,爲了提升軟件安裝速度,能夠將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版本
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/

安裝Ruby環境

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

安裝MySQL及初始化GitLab庫

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';

安裝Redis

yum -y install redis
/etc/init.d/redis start
chkconfig redis on

添加git賬號並容許sudo

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

測試是否能夠用git賬號登陸數據庫

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

安裝GitLab

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

安裝GitLab-Shell

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

安裝須要ruby的gems

在執行下面的命令以前先要把gem的默認源改成淘寶的,雖然前面改過了,但這裏仍是默認的沒改的,不知道怎麼回事,須要vim Gemfile,修改source "https://rubygems.org"https://ruby.taobao.org/,注意是https不是httpsql

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了。

初始化數據庫(建立GitLab相關表)

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

設置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 -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

拉取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? ... 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/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信息,
    參考Error in Gitlab: git configured for git user … no try fixing it

解決了

  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了,繼續折騰中。。。。

等把這個問題解決了,在折騰自動部署的功能。

最後但願遇到過上面第三個問題的網友,說說解決方法,或者探討一下,謝謝!

相關文章
相關標籤/搜索