在centos6.5中安装 GitLab 全过程和问题记录
?在centos6.5中安裝 GitLab 全過程和問題記錄
如果你想省事,使用最新版本的gitlab,請下載一鍵安裝包,一鍵安裝
腳本:https://bitnami.com/stack/gitlab/installer
? ?
下載后安裝時候請查看README
readme:https://bitnami.com/stack/gitlab/README.txt
以下是編譯安裝,真TM麻煩
先秀下安裝完成后的成果。
?
centos安裝gitlab成果
開始之前
在開始之前請先查看官方的剛需文檔: https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/requirements.md ,該文檔說明了系統,軟件和硬件等各方面的需求。詳細的了解這些,可以避免碰到很多怪異的問題。
安裝步驟總覽
-
基礎操作系統(CentOS 6.4 Minimal,升級后為6.5)
-
Ruby (版本: 2.0.0p353)
-
創建項目運行用戶(創建git賬號,方便權限管理)
-
GitLab Shell(版本:1.8.0)
-
數據庫(可以支持mysql和PostgreSQL,這里使用mysql,版本:5.1.17)
-
GitLab(版本:6.3.1)
-
Web服務器(可支持nginx和apache,這里使用tengine-1.5.2)
-
防火墻(iptables)
1、安裝操作系統
這個比較簡單,安裝完成之后記的配置下網絡,使其可以在啟動時自動連接。而后需要升級系統和安裝一些相應的軟件和依賴包,以下逐一說明。
Tips:如果不能連接國外的網絡,經常出現網絡錯誤或者couldn’t not resolve host這樣的錯誤,建議修改dns服務器為8.8.8.8和8.8.4.4。
a、升級操作系統和安裝wget
$?sudo?yum?-y?update $?sudo?yum?-y?install?wget升級完成后,系統版本是6.5。
筆者注:和英文文檔不同,筆者這里是先升級系統和安裝wget,不然后面的操作會提示wget命令找到。
b、增加EPEL安裝源
EPEL,即Extra Packages for Enterprise Linux,這個軟件倉庫里有很多非常常用的軟件,而且是專門針對RHEL設計的,對RHEL標準yum源是一個很好的補充,完全免費使用,由Fedora項目維護,所以如果你使用的是RHEL,或者CentOS,Scientific等RHEL系的linux,可以非常放心的使用EPEL的yum源。
下載并安裝GPG key
$?sudo?wget?-O?/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6?https://www.fedoraproject.org/static/0608B895.txt $?sudo?rpm?--import?/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6檢驗下是否安裝成功
$?sudo?rpm?-qa?gpg*安裝epel-release-6-8.noarch包
$?sudo?rpm?-Uvh?http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm提示:不要在意x86_64,在i686的機器上一樣能使用。
c、增加PUIAS安裝源
PUIAS Linux是面向桌面和服務器的完整的操作系統,它靠編譯Red Hat Enterprise Linux的源代碼包來創建。除了這些上游的軟件包外,該項目還提供一些其他的軟件倉庫:“Addons”包含了通常的Red Hat發行中未收入的額外軟件包,“Computational”提供專門針對科學計算的軟件,“Unsupported”則收入各種各樣的測試性軟件 包。該發行由美國普林斯頓 大學的高等研究所維護。
創建/etc/yum.repos.d/PUIAS_6_computational.repo,并添加如下內容:
[PUIAS_6_computational] name=PUIAS?computational?Base$releasever?-$basearchmirrorlist=$releasever/$basearch/mirrorlist#baseurl=$basearchgpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puias下載并安裝GPG key
$?sudo?wget?-O?/etc/pki/rpm-gpg/RPM-GPG-KEY-puias?http://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias $?sudo?rpm?--import?/etc/pki/rpm-gpg/RPM-GPG-KEY-puias檢驗下是否安裝成功
$?sudo?rpm?-qa?gpg*Tips:安裝完EPEL和PUIAS兩個源后,可以檢測下:
$?sudo?yum?repolistd、安裝GitLab的所需依賴包和工具
$?su?-$?yum?-y?groupinstall?'Development?Tools' $?yum?-y?install?vim-enhanced?readline?readline-devel?ncurses-devel?gdbm-devel?glibc-devel?tcl-devel?openssl-devel?curl-devel?expat-devel?db4-devel?byacc?sqlite-devel?gcc-c++?libyaml?libyaml-devel?libffi?libffi-devel?libxml2?libxml2-devel?libxslt?libxslt-devel?libicu?libicu-devel?system-config-firewall-tui?python-devel??redi??sudo?wget?crontabs?logwatch?logrotate?perl-Time-HiRes?git RHEL提示?
如果部分包不能安裝,例如: eg. gdbm-devel, libffi-devel and libicu-devel,那么增加rhel6的安裝源。
e、配置redis
配置redis使其在開機時啟動:
$此處redis是yum安裝,為了省事、 $?sudo?chkconfig?redis?on $?sudo?service?redis?startf、配置郵件服務器
筆者注:這個過程筆者沒有配置,請參考英文文檔。
2、安裝Ruby
下載并編譯:
$?su?- $?mkdir?/tmp/ruby?&&?cd?/tmp/ruby $?curl?--progress?ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz?|?tar?xz $?cd?ruby-2.0.0-p353$?./configure?--prefix=/usr/local/ $?make?&&?make?install安裝完成后,重新登錄終端確保$PATH生效,檢測ruby的安裝成功與否:
$?which?ruby /usr/local/bin/ruby$?ruby?-v ruby?2.0.0p353?(2013-11-22?revision?43784)?[x86_64-linux]安裝bundle:
$?sudo?gem?install?bundler?--no-ri?--no-rdoc如果提示sudo: gem: command not found,使用root賬號登錄執行該命令即可。
3、系統用戶
創建用戶git
$?su?- $?adduser?--system?--shell?/bin/bash?--comment?'GitLab'?--create-home?--home-dir?/home/git/?git因為git用戶不需要登錄,所以這里不需要設置git的密碼。
轉發所有郵件
筆者注:因為上面沒有配置發送郵件,這里也省略。
4、配置GitLab shell
GitLab shell是專門為GitLab開發的提供ssh訪問和版本管理的軟件。
先使用root登錄,而后切換成git
$?su?- $?su?-?git克隆gitlab shell
$??git?clone?https://github.com/gitlabhq/gitlab-shell.git??$?cd?gitlab-shell切換成1.8.0版本,并編輯配置
$?git?checkout?v1.8.0 $?cp?config.yml.example?config.yml這里最重要的是將gitlab_url修改成gitlab的訪問域名。形如:http://test.gitlab.com/
筆者注:如果gitlab是使用https訪問,則需將http替換成https,配置文件中的self_signed_cert要修改成true,否則gitlab shell在通過api和gitlab進行通信的時候就會出現錯誤,導致項目push出錯。因為后面配置web服務器的時候是使用ssl,所以這里要按照ssl的方式配置。
Tips: 另外如果使用的域名是測試域名,不要忘記在系統的/etc/hosts做域名映射。如果自己有DNS服務器,則不需要綁定hosts
安裝一些需要的目錄和文件
$?./bin/install5、安裝數據庫
筆者這里使用的是msyql,關于PostgreSQL的安裝請參考原文檔。
安裝mysql并設置開機啟動:
?此處我選擇安裝MySQL的二進制包:安裝參考文檔:http://douya.blog.51cto.com/6173221/1579986設置mysql root賬號的密碼:
$?mysqladmin??-uroot?password?'your?password'創建新用戶和數據庫給gitlab使用
#?登錄數據庫 $?mysql?-u?root?-p #?輸入root密碼 #?為gitlab創建使用用戶 CREATE?USER?'gitlab'@'localhost'?IDENTIFIED?BY?'gitlab賬號的密碼'; #?創建gitlaba使用的數據庫 CREATE?DATABASE?IF?NOT?EXISTS?`gitlabhq_production`?DEFAULT?CHARACTER?SET?`utf8`?COLLATE?`utf8_unicode_ci`; #?給予gitlab用戶權限 GRANT?SELECT,?LOCK?TABLES,?INSERT,?UPDATE,?DELETE,?CREATE,?DROP,?INDEX,?ALTER?ON?`gitlabhq_production`.*?TO?'gitlab'@'localhost'; #?登出數據庫 \q6、安裝GitLab
將GitLab安裝在git的家目錄下:
$?su?- $?su?-?gita、克隆GitLab并切換分支到6-3-stable
#?克隆GitLab $?git?clone?https://github.com/gitlabhq/gitlabhq.git?gitlab #?進入gitlab目錄 $?cd?/home/git/gitlab #?切換到6-3-stable分支??,需要的可以切換到5.0穩定版? $?git?checkout?6-3-stableb、配置項目
#?復制配置文件 $?cp?config/gitlab.yml.example?config/gitlab.yml #?修改配置文件中的訪問域名(your_domain_name為項目的訪問域名) $?sed?-i?'s|localhost|your_domain_name|g'?config/gitlab.yml\設定log和tmp目錄所有者和權限$?chown?-R?git?log/$?chown?-R?git?tmp/$?chmod?-R?u+rwX?log/$?chmod?-R?u+rwX?tmp/#?創建gitlab-satellites目錄$?mkdir?/home/git/gitlab-satellites#?創建tmp/pids/和tmp/sockets/目錄,確保gitlab有相應的權限$?mkdir?tmp/pids/$?mkdir?tmp/sockets/$?chmod?-R?u+rwX?tmp/pids/$?chmod?-R?u+rwX?tmp/sockets/#?創建public/uploads目錄$?mkdir?public/uploads$?chmod?-R?u+rwX?public/uploads#?復制unicorn配置$?cp?config/unicorn.rb.example?config/unicorn.rb#?編輯unicorn配置(筆者這里采用默認配置)$?vim?config/unicorn.rb#?配置git的用戶和郵件$?git?config?--global?user.name?"GitLab"$?git?config?--global?user.email?"gitlab@your_domain_name"$?git?config?--global?core.autocrlf?input這邊的配置比較復雜,細心些就行了。
c、配置數據庫訪問文件
$?cp?config/database.yml.mysql?config/database.yml編輯config/database.yml,設置其中連接數據庫的賬號密碼,筆者的配置部分如下:
##?PRODUCTION#production:adapter:?mysql2encoding:?utf8reconnect:?falsedatabase:?gitlabhq_productionpool:?10username:?gitlabpassword:?"gitlab"#?host:?localhost#?socket:?/tmp/mysql.sock修改其中username和password就可以了,其中密碼就是上面數據庫步驟中創建gitlab用戶的密碼。
確保該文件只有git賬號有權限讀取。
$?chmod?o-rwx?config/database.ymld、安裝Gems
$?sudo??gem?install?charlock_holmes?--version?'0.6.9.4'??此時會遇到一個錯誤,由于在國內無法訪問國外網站原因 [root@gitlab?gitlab]#?gem?install?charlock_holmes?--version?'0.6.9.4'ERROR:??Could?not?find?a?valid?gem?'charlock_holmes'?(=?0.6.9.4),?here?is?why:Unable?to?download?data?from?https://rubygems.org/?-?Errno::ECONNRESET:?Connection?reset?by?peer?-?SSL_connect?(https://rubygems.org/specs.4.8.gz) 解決辦法: 1, cd??/home/git/gitlab vim?Gemfile 更改 source?https://rubygems.org/? 為:?? source?"?https://ruby.taobao.org/?" 2, gem?sources?-r??https://rubygems.org/? gem?sources?-a?https://ruby.taobao.org/? [root@gitlab?gitlab]#?gem?sources?-l ***?CURRENT?SOURCES?***https://ruby.taobao.org/ $再次運行,便成功安裝 [root@gitlab?gitlab]#?gem?install?charlock_holmes?--version?'0.6.9.4' $ exit?退出root用戶安裝mysql包
$?cd?/home/git/gitlab/ [git@Git?gitlab]$??bundle?install?--deployment?--without?development?test?postgres?puma?aws 此時還會出現一個問題 [git@Git?gitlab]$?bundle?install?--deployment?--without?development?test?postgres?puma?aws -bash:?bundle:?command?not?found 解決方案: [git@Git?gitlab]$?sudo???gem?install?bundler???此不需要用root來安裝此時出現第二個錯誤: [git@Git?gitlab]$??bundle?install?--deployment?--without?development?test?postgres?puma?aws Don't?run?Bundler?as?root.?Bundler?can?ask?for?sudo?if?it?is?needed,?and?installing?your?bundle?as?root?will?break?this?application?for?all?non-root?users?on?this?machine. Fetching?gem?metadata?from?https://ruby.taobao.org/........ Fetching?version?metadata?from?https://ruby.taobao.org/.. Could?not?find?modernizr-2.6.2?in?any?of?the?sources 解決方法: 1, [git@gitlab?gitlab]$?vim?Gemfile gem?"modernizr",????????"2.6.2" 更改改為: gem?"modernizr-rails",??"2.7.1" 2, [git@gitlab?gitlab]$?vim?Gemfile.lock 將modernizr?(2.6.2) 更改改為:modernizr-rails?(2.7.1)將modernizr?(=?2.6.2) 更改改為:modernizr-rails?(=?2.7.1) #重新執行: [git@gitlab?gitlab]$?bundle?install?--deployment?--without?development?test?postgres?puma?aws 此時遇到新的錯誤:An?error?occurred?while?installing?rake?(10.1.0),?and?Bundler?cannot?continue. Make?sure?that?`gem?install?rake?-v?'10.1.0'`?succeeds?before?bundling. 解決辦法: su?-? [root@gitlab?gitlab]#?gem?install?rake?-v?'10.1.0' 此時用root執行? [root@gitlab?gitlab]#?????bundle?install?--deployment?--without?development?test?postgres?puma?awse、初始化數據和激活高級功能
$?cd?/home/git/gitlab $?bundle?exec?rake?gitlab:setup?RAILS_ENV=production這步完成后,會生一個默認的管理員賬號:
Administrator?account?created:login.........root password......5iveL!fef、安裝啟動腳本
$?su?- $wget?-O?/etc/init.d/gitlab?https://raw.github.com/gitlabhq/gitlab-recipes/master/init/sysvinit/centos/gitlab-unicorn$?chmod?+x?/etc/init.d/gitlab$?chkconfig?--add?gitlab開機時啟動
$?chkconfig?gitlab?ong、檢測應用程序狀態
$?su?-?git $?cd?gitlab/bundle?exec?rake?gitlab:check?RAILS_ENV=production???先檢查安裝環境是否成功、$?bundle?exec?rake?gitlab:env:info?RAILS_ENV=production $?exit debug模式啟動gitlab bundle?exec?rails?s?-e?production可以查看到系統、Ruby、GitLab和GitLab Shell的版本和其他信息。
啟動GitLab實例
$?service?gitlab?start 出現問題? [root@git?~]#?/etc/init.d/gitlab?start Stopping?unicorn:??????????????????????????????????????????[FAILED] Stopping?sidekiq:??????????????????????????????????????????[FAILED] Starting?unicorn:?bash:?bin/web:?No?such?file?or?directory[FAILED] Starting?sidekiq:?bash:?bin/background_jobs:?No?such?file?or?directory[FAILED]解決方案 [root@git?gitlab]#??cd?/home/git/gitlabcp?-r??script/?bin [root@git?gitlab]#/etc/init.d/gitlab?start Starting?unicorn:??????????????????????????????????????????[??OK??] Starting?sidekiq:??????????????????????????????????????????[??OK??]h、查看應用更加詳細的信息
$?su?-?git $?cd?gitlab/ $?bundle?exec?rake?gitlab:check?RAILS_ENV=production [git@gitlab?gitlab]$?bundle?exec?rake?gitlab:check?RAILS_ENV=production Checking?Environment?...Git?configured?for?git?user??...?yes Has?python2??...?yes python2?is?supported?version??...?yesChecking?Environment?...?FinishedChecking?GitLab?Shell?...GitLab?Shell?version?>=?1.7.9???...?OK?(1.8.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 update?hook?up-to-date??...?yes update?hooks?in?repos?are?links:?...?can't?check,?you?have?no?projects 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?successfulChecking?GitLab?Shell?...?FinishedChecking?Sidekiq?...Running??...?yes Number?of?Sidekiq?processes?...?1Checking?Sidekiq?...?FinishedChecking?GitLab?...Database?config?exists??...?yes Database?is?SQLite?...?no All?migrations?up??...?yes 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??...?noTry?fixing?it:Redownload?the?init?scriptFor?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?projects Projects?have?satellites??...?can't?check,?you?have?no?projects Redis?version?>=?2.0.0??...?yes Your?git?bin?path?is?"/usr/bin/git" Git?version?>=?1.7.10???...?noTry?fixing?it:Update?your?git?to?a?version?>=?1.7.10?from?1.7.1Please?fix?the?error?above?and?rerun?the?checks.Checking?GitLab?...?Finished這里會提示一個Init script up-to-date的錯誤,如下:
Init?script?up-to-date??...?no Try?fixing?it: Redownload?the?init?scriptFor?more?information?see: doc/install/installation.md?in?section?"Install?Init?Script"Please?fix?the?error?above?and?rerun?the?checks.原文說明不用介意這個問題,以及git的版本,hooks 咱都不影響使用
7、安裝web服務器
筆者選擇的是nginx,關于apache方面的請參考原文檔
此處我選擇的是tengine?編譯安裝 1,安裝省略,因為很簡單 2,tengine的配置如下:| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | user??????????????root?git; worker_processes??2; error_log??logs/error.log; pid????????logs/nginx.pid; events?{ ????worker_connections??1024; } http?{ ????include??????mime.types; ????default_type??application/octet-stream; ????log_format??main??'$remote_addr?-?$remote_user?[$time_local]?"$request"?' ??????????????????????'$status?$body_bytes_sent?"$http_referer"?' ??????????????????????'"$http_user_agent"?"$http_x_forwarded_for"'; ?????access_log??logs/access.log??main; upstream?gitlab?{ ??server?unix:/home/git/gitlab/tmp/sockets/gitlab.socket; } server?{ ??listen?*:80?default_server;????????? ??server_name?your-domain ??server_tokens?off;???? ??root?/home/git/gitlab/public; ??client_max_body_size?5m; ??location?/?{ ????#?serve?static?files?from?defined?root?folder;. ????#?@gitlab?is?a?named?location?for?the?upstream?fallback,?see?below ????try_files?$uri?$uri/index.html?$uri.html?@gitlab; ??} ??#?if?a?file,?which?is?not?found?in?the?root?folder?is?requested, ??#?then?the?proxy?pass?the?request?to?the?upsteam?(gitlab?unicorn) ??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; ??} } } |
啟動nginx:
| 1 2 3 4 | root@gitlab?tengine]#?/usr/local/tengine/sbin/nginx?-t? the?configuration?file?/usr/local/tengine/conf/nginx.conf?syntax?is?ok configuration?file?/usr/local/tengine/conf/nginx.conf?test?is?successful [root@gitlab?tengine]#?/usr/local/tengine/sbin/nginx |
?訪問成果:
去開始哈皮吧~~~?
參考資料:http://www.centoscn.com/image-text/install/2015/0320/4929.html
############### 郵件通知########################
?你Linux系統使用的是postfix郵箱,而且配置文件能是默認,并且使用mail可以發郵件,所以執行以下,確保可以發郵件
1. 首先是拷貝Gitlab自帶的example
cd?/home/git/gitlab sudo?-u?git?-H?cp?config/initializers/smtp_settings.rb.sample?config/initializers/smtp_settings.rb
2. 然后用我們自己的郵箱替換example中的郵箱
sudo?-u?git?-H?vim?config/initializers/smtp_settings.rb
一鍵安裝路徑:
cd ?/opt/gitlab-8.5.7-0
vim apps/gitlab/htdocs/config/environments/production.rb?
這里提供163和騰訊企業郵箱兩種配置方式,注意將下面的123456替換成自己的密碼
163郵箱:
if?Rails.env.production? ??Gitlab::Application.config.action_mailer.delivery_method?=?:smtp ??ActionMailer::Base.smtp_settings?=?{ ????address:?"smtp.163.com", ????port:?25, ????user_name:?"wpgitlab", ????password:?"123456", ????domain:?"163.com", ????authentication:?:plain, ????enable_starttls_auto:?true ??} end
QQ郵箱:
3. 修改gitlab.yml
cd?/home/git/gitlabsudo?-u?git?-H?vim?config/gitlab.yml
一鍵安裝路徑:
cd ?/opt/gitlab-8.5.7-0
vim apps/gitlab/htdocs/config/gitlab.yml
將默認郵箱修改為自己的郵箱
163:
##?Email?settings ????#?Email?address?used?in?the?"From"?field?in?mails?sent?by?GitLab ????email_from:?wpgit@163.com
騰訊企業郵箱:
##?Email?settings ????#?Email?address?used?in?the?"From"?field?in?mails?sent?by?GitLab ????email_from:?wangpeng@scnee.com
4. 修改后。重啟gitlab
本文出自 “crazy_sir” 博客,請務必保留此出處http://douya.blog.51cto.com/6173221/1726333
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀
總結
以上是生活随笔為你收集整理的在centos6.5中安装 GitLab 全过程和问题记录的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: gitlab 安装报错:Could no
- 下一篇: 牛逼哄哄的SLAM技术 即将颠覆哪些领域