Centos 6.5上構建Git Lab服務及問題總結


前言:

    官方上面說並不推薦在CentOS上面安裝GitLab,無奈公司的服務器都是CentOS的系統.....

不過,好在經歷了三天才算把GitLab搭建起來,查了N多參考教程,發現一個問題,並不是每個教程都是通用的、總會遇到某些未知的錯誤是其他作者沒有碰到的,畢竟每台服務器的環境是不一樣的,問題百出,很是讓人很是頭痛。

   下面總結了自己在CentOS搭建GitLab的教程以及某些錯誤的解決辦法,算是對自己的總結吧!或許那天就用到了......

-----------------------------------------------------------------------------------------

――安裝前准備工作

1)添加epel源

[root@Git ~]# mkdir /tmp/soft/[root@Git ~]# cd /tmp/soft/
[root@Git soft]# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@Git soft]# rpm -ivh epel-release-6-8.noarch.rpm
warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing... ########################################### [100%]
1:epel-release ########################################### [100%]

2)配置epel源

[epel]name=Extra Packages for Enterprise Linux 6 - $basearch#download.fedoraproject.org域名已經失效#去掉#號將download.fedoraproject.org變更為dl.fedoraproject.orgbaseurl=http://dl.fedoraproject.org/pub/epel/6/$basearch#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearchfailovermethod=priorityenabled=1gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

3)執行yum makecache 更新

[root@Git soft]# yum makecacheLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfile * base: centos.ustc.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.aliyun.combase                                                                                                                         | 3.7 kB     00:00base/group_gz                                                                                                                | 220 kB     00:00base/filelists_db                                                                                                            | 5.9 MB     00:03base/other_db                                                                                                                | 2.8 MB     00:01epel                                                                                                                         | 4.4 kB     00:00epel/group_gz                                                                                                                | 237 kB     00:05epel/filelists_db                                                                                                            | 8.4 MB     05:56epel/primary_db                                                                                                              | 6.1 MB     03:36epel/other_db                                                                                                                | 3.6 MB     01:22epel/updateinfo                                                                                                              | 780 kB     00:11extras                                                                                                                       | 3.4 kB     00:00extras/filelists_db                                                                                                          |  11 kB     00:00extras/prestodelta                                                                                                           |  907 B     00:00extras/other_db                                                                                                              | 5.8 kB     00:00mariadb                                                                                                                      | 1.9 kB     00:00mariadb/filelists_db                                                                                                         |  47 kB     00:01mariadb/primary_db                                                                                                           |  15 kB     00:00mariadb/other_db                                                                                                             | 1.2 kB     00:00updates                                                                                                                      | 3.4 kB     00:00updates/filelists_db                                                                                                         | 1.7 MB     00:01updates/prestodelta                                                                                                          | 249 kB     00:00updates/primary_db                                                                                                           | 2.6 MB     00:02updates/other_db                                                                                                             |  21 MB     00:15epel/pkgtags                                                                                                                 | 1.0 MB     00:36Metadata Cache Created

4)安裝軟件所需依賴包

[root@Git soft]# yum -y install readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-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 python-devel redis wget crontabs logwatch logrotate perl-Time-HiRes git gettext-devel libel openssl-devel zlib-devel gcc gcc-c++ make autoconf readline-devel expat-devel gettext-devel tk-devel  libxml2-devel libffi-devel libxslt-devel libicu-devel python-pip sqlite-devel  patch libyaml* pcre-devel

――安裝Git Server

[root@Git soft]# yum -y install git perl-ExtUtils-MakeMaker[root@Git soft]# git clone git://github.com/git/gitInitialized empty Git repository in /tmp/soft/git/.git/remote: Counting objects: 171891, done.remote: Compressing objects: 100% (46560/46560), done.remote: Total 171891 (delta 123695), reused 171404 (delta 123322)Receiving objects: 100% (171891/171891), 60.16 MiB | 571 KiB/s, done.Resolving deltas: 100% (123695/123695), done.[root@Git soft]# cd git/[root@Git git]# git checkout v1.9.2[root@Git git]# autoconf[root@Git git]# make prefix=/usr/local/git all[root@Git git]# make prefix=/usr/local/git install[root@Git git]# yum erase git[root@Git git]# ln -s /usr/local/git/bin/* /usr/bin/[root@Git git]# git --versiongit version 1.9.2            #表示安裝成功#刪除git安裝包[root@Git git]# cd ..[root@Git soft]# rm -rf git/

――安裝配置ruby

1)下載ruby

[root@Git soft]# wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.1.tar.gz

2)編譯安裝ruby

[root@Git soft]# tar zfvx ruby-2.1.1.tar.gz[root@Git soft]# cd ruby-2.1.1[root@Git ruby-2.1.1]# ./configure[root@Git ruby-2.1.1]# make && make install#安裝bundler需要添加rubygems的國內鏡像[root@Git ruby-2.1.1]# gem sources --remove https://rubygems.org/[root@Git ruby-2.1.1]# gem source -a http://ruby.taobao.org/[root@Git ruby-2.1.1]# gem sources -l*** CURRENT SOURCES ***http://ruby.taobao.org/[root@Git ruby-2.1.1]# gem install bundlerFetching: bundler-1.6.2.gem (100%)Successfully installed bundler-1.6.2Parsing documentation for bundler-1.6.2Installing ri documentation for bundler-1.6.2Done installing documentation for bundler after 2 seconds1 gem installed[root@Git ruby-2.1.1]# ln -s /usr/local/bin/ruby /usr/bin/ruby[root@Git ruby-2.1.1]# ln -s /usr/local/bin/gem /usr/bin/gem[root@Git ruby-2.1.1]# ln -s /usr/local/bin/bundle /usr/bin/bundle

3)創建一個Git用戶供GitLab使用

#之前已經搭建過Git Server不需要再次創建Git用戶[root@Git ruby-2.1.1]# adduser --comment 'GitLab' git[root@Git ruby-2.1.1]# passwd git#為了方便添加git用戶擁有root權限 [sudoers文件默認沒有寫權限需要強制保存:wq!][root@Git ruby-2.1.1]# vi /etc/sudoersgit     ALL=(ALL)       ALL[root@Git ruby-2.1.1]# chmod -R 755 /home/git[root@Git ruby-2.1.1]# vi /home/git/.bash_profileexport GIT_SSL_NO_VERIFY=1[root@Git ruby-2.1.1]# source /home/git/.bash_profile#不添加變量的話使用https鏈接會報如下錯誤fatal: unable to access 'https://github.com/gitlabhq/grit.git/': Peer certificate cannot be authenticated with known CA certificates

4)安裝GitLab的Shell

[root@Git git]# su - git#克隆gitlab的shell[git@Git ~]$ git clone https://gitlab.com/gitlab-org/gitlab-shell.git -b v1.8.0正克隆到 'gitlab-shell'...remote: Reusing existing pack: 1222, done.remote: Total 1222 (delta 0), reused 0 (delta 0)接收對象中: 100% (1222/1222), 218.70 KiB | 16.00 KiB/s, done.處理 delta 中: 100% (620/620), done.檢查連接... 完成。[git@Git ~]$ cd gitlab-shell/[git@Git gitlab-shell]$ cp config.yml.example config.yml[git@Git gitlab-shell]$ vi config.yml#自己的gitlab域名gitlab_url: "http://git.test.com/"#完成配置[git@Git gitlab-shell]$ ./bin/installmkdir -p /home/git/repositories: truemkdir -p /home/git/.ssh: truechmod 700 /home/git/.ssh: truetouch /home/git/.ssh/authorized_keys: truechmod 600 /home/git/.ssh/authorized_keys: truechmod -R ug+rwX,o-rwx /home/git/repositories: truefind /home/git/repositories -type d -print0 | xargs -0 chmod g+s: true

5)建立gitlab數據庫並授權

[git@Git gitlab-shell]$ mysql -u rootWelcome to the MariaDB monitor.  Commands end with ; or \g.Your MariaDB connection id is 3Server version: 5.5.36-MariaDB-wsrep MariaDB Server, wsrep_25.9.r3961Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab';Query OK, 0 rows affected (0.20 sec)MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;Query OK, 1 row affected (0.11 sec)MariaDB [(none)]> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';Query OK, 0 rows affected (0.06 sec)MariaDB [(none)]> quitBye

6)克隆GitLab源

[git@Git gitlab-shell]$ cd ..[git@Git ~]$ git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-4-stable gitlab正克隆到 'gitlab'...remote: Reusing existing pack: 77202, done.remote: Counting objects: 67, done.remote: Compressing objects: 100% (65/65), done.remote: Total 77269 (delta 25), reused 1 (delta 0)接收對象中: 100% (77269/77269), 75.26 MiB | 241.00 KiB/s, done.處理 delta 中: 100% (53687/53687), done.[git@Git ~]$ cd gitlab[git@Git gitlab]$ cp config/gitlab.yml.example config/gitlab.yml[git@Git gitlab]$ vi config/gitlab.yml## GitLab settingsgitlab:## Web server settings  host: git.test.com  port: 80  https: false[git@Git gitlab]$ chown -R git log/[git@Git gitlab]$ chown -R git tmp/[git@Git gitlab]$ chmod -R u+rwX  log/[git@Git gitlab]$ chmod -R u+rwX  tmp/[git@Git gitlab]$ mkdir tmp/pids/[git@Git gitlab]$ mkdir tmp/sockets/[git@Git gitlab]$ chmod -R u+rwX  tmp/pids/[git@Git gitlab]$ chmod -R u+rwX  tmp/sockets/[git@Git gitlab]$ mkdir public/uploads[git@Git gitlab]$ chmod -R u+rwX  public/uploads[git@Git gitlab]$ cp config/unicorn.rb.example config/unicorn.rb[git@Git gitlab]$ cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb[git@Git gitlab]$ git config --global user.name "GitLab"[git@Git gitlab]$ git config --global user.email "gitlab@localhost"[git@Git gitlab]$ git config --global core.autocrlf input

7)配置gitlab數據庫

[git@Git gitlab]$ cp config/database.yml.mysql config/database.yml[git@Git gitlab]$ vi config/database.ymlproduction:  adapter: mysql2  encoding: utf8  reconnect: false  database: gitlabhq_production  pool: 5  username: gitlab  password: "gitlab"  # host: localhost  # socket: /tmp/mysql.sock

8)安裝gems

[git@Git gitlab]$sudo gem install charlock_holmes --version '0.6.9.4'Fetching: charlock_holmes-0.6.9.4.gem (100%)Building native extensions.  This could take a while...Successfully installed charlock_holmes-0.6.9.4Parsing documentation for charlock_holmes-0.6.9.4Installing ri documentation for charlock_holmes-0.6.9.4Done installing documentation for charlock_holmes after 0 seconds1 gem installed[git@Git gitlab]$ vi Gemfilesource "https://rubygems.org"改為source "http://rubygems.org"[git@Git gitlab]$ bundle install --deployment --without development test postgresFetching source index from http://rubygems.org/Fetching https://github.com/gitlabhq/grit.gitCould not find modernizr-2.6.2 in any of the sources#出現錯誤: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)#重新執行:[git@Git gitlab]$ bundle install --deployment --without development test postgres puma aws

9)啟動redis

[git@Git gitlab]$ sudo /etc/init.d/redis start啟動 :[確定][git@Git gitlab]$ sudo chkconfig redis on

10)對數據庫進行初始化

[git@Git gitlab]$ bundle exec rake gitlab:setup RAILS_ENV=production --verboseThis 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#最后初始化成功后會獲得賬號和密碼Administrator account created:login.........admin@local.hostpassword......5iveL!fe

11)檢查GitLab及其環境的配置是否正確

[[git@Git gitlab]$ bundle exec rake gitlab:env:info RAILS_ENV=productionSystem informationSystem:         CentOS release 6.5 (Final)Current User:   gitUsing RVM:      noRuby Version:   2.1.1p76Gem Version:    2.2.2Bundler Version:1.6.2Rake Version:   10.1.0GitLab informationVersion:        6.4.3Revision:       3173626Directory:      /home/git/gitlabDB Adapter:     mysql2URL:            http://git.yingtao.comHTTP Clone URL: http://git.yingtao.com/some-project.gitSSH Clone URL:  git@git.yingtao.com:some-project.gitUsing LDAP:     noUsing Omniauth: noGitLab ShellVersion:        1.9.3Repositories:   /home/git/repositories/Hooks:          /home/git/gitlab-shell/hooks/Git:            /usr/bin/git[git@Git gitlab]$ bundle exec rake sidekiq:start RAILS_ENV=productionrake aborted!SIGTERM/home/git/gitlab/lib/tasks/sidekiq.rake:9:in `system'/home/git/gitlab/lib/tasks/sidekiq.rake:9:in `block (2 levels) in <top (required)>'Tasks: TOP => sidekiq:start(See full trace by running task with --trace)[git@Git gitlab]$ bundle exec rake gitlab:check RAILS_ENV=productionChecking Environment ...Git configured for git user? ... yesHas python2? ... yespython2 is supported version? ... yesChecking Environment ... FinishedChecking GitLab Shell ...GitLab Shell version >= 1.7.9 ? ... OK (1.9.3)Repo base directory exists? ... yesRepo base directory is a symlink? ... noRepo base owned by git:git? ... yesRepo base access is drwxrws---? ... yesupdate hook up-to-date? ... yesupdate hooks in repos are links: ... can't check, you have no projectsRunning /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? ... yesGitLab 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: ... can't check, you have no projectsProjects have satellites? ... can't check, you have no projectsRedis version >= 2.0.0? ... yesYour git bin path is "/usr/bin/git"Git version >= 1.7.10 ? ... yes (1.9.2)Checking GitLab ... Finished

11)下載啟動腳本

[git@Git gitlab]$ sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/init/sysvinit/centos/gitlab-unicorn -P /etc/init.d/[git@Git gitlab]$ sudo mv /etc/init.d/gitlab-unicorn /etc/init.d/gitlab[git@Git gitlab]$ sudo chmod +x /etc/init.d/gitlab[git@Git gitlab]$ sudo chkconfig --add gitlab[git@Git gitlab]$ sudo chkconfig gitlab on[git@Git gitlab]$ sudo /etc/init.d/gitlab start

12)復制配置文件[這里使用nginx做為WEB服務]

[git@Git gitlab]$ cp lib/support/nginx/gitlab /usr/local/nginx/conf/conf.d/[git@Git gitlab]$ cd /usr/local/nginx/conf/conf.d/[git@Git gitlab]$ sudo chown -R git:git .[git@Git conf.d]$ cp gitlab gitlab.conf[git@Git conf.d]$ vi gitlab.confupstream gitlab {  server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;}server {  listen *:80 default_server;         # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea  server_name git.test.com;     # e.g., server_name source.example.com;  server_tokens off;     # don't show the version number, a security best practice  root /home/git/gitlab/public;  client_max_body_size 5m;  access_log  logs/gitlab_access.log;  error_log   logs/gitlab_error.log;  location / {    try_files $uri $uri/index.html $uri.html @gitlab;  }  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_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;    proxy_pass http://gitlab;  }}[git@Git conf.d]$ sudo service nginx restart

13)拉取GitLab靜態文件

[git@Git conf.d]$ cd /home/git/gitlab[git@Git gitlab]$ bundle exec rake assets:precompile RAILS_ENV=production[git@Git gitlab]$ sudo service gitlab restart

14)訪問測試

初始管理員帳號和密碼為:admin@local.host5iveL!fe

1)訪問http://IP 如果配置正常會顯示如下頁面:

wKioL1NlpD-RxE99AAGzgjcxyRs692.jpg

2)輸入默認的登陸賬號和密碼,會提示你修改默認密碼:

wKiom1NlpGrijKTjAAHpoYOtcBw019.jpg

3)密碼修改后,會重新跳回到登陸界面:

wKioL1NlpEDANBcoAAHQSsyt0TQ563.jpg

4)重新輸入登陸賬號和新密碼,登陸成功后顯示如下:

wKiom1NlpGugWObbAAJsMUFWs4w443.jpg



本文出自 “命運.” 博客,請務必保留此出處http://hypocritical.blog.51cto.com/3388028/1405574


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2021 ITdaan.com