Jenkins--第三關:Gitlab安裝和配置


一、概述

  首先,你要知道Gitlab/Github不是Git.

  Git是版本控制系統,Github是在線的基於Git的代碼托管服務。.

  Github同時提供付費賬戶和免費賬戶。這兩種賬戶都可以創建公開的代碼倉庫,但是付費賬戶也可以創建私有的代碼倉庫。

  Gitlab是一個開源的版本管理系統,實現一個自托管的Git項目倉庫,可通過Web界面進行訪問公開的或者私人項目。

二、安裝Git(非必須,系統一般有安裝git 1.7)Git必看書籍Pro Git這本書(也可以看其電子版)絕對是Git入門和進深的不二選擇。

英文版:https://git-scm.com/book/en/v2

中文版:https://git-scm.com/book/zh/v2

1、依賴關系

yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum -y install gcc* perl-ExtUtils-MakeMaker xmlto asciidoc
# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
# tar zxvf libiconv-1.14.tar.gz
# cd libiconv-1.14
# ./configure --prefix=/usr/local/libiconv
# make -j 4 && make -j 4 install

2、安裝

# yum remove git
#注意,如果系統升級了python要修改/usr/bin/asciidoc 第一行
為“#!/usr/bin/env python2” 。 /// (/usr/bin/python2)
# tar zxvf v2.12.1.tar.gz
# cd git-2.12.1
# make configure
# ./configure --prefix=/usr/local/git --with-iconv=/usr/local/libiconv
# make -j 4 all doc
# make -j 4 install install-doc install-html
# echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
# echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/profile.d/git.sh
# source /etc/bashrc // source /etc/profile

查看版本號
# git --version

git version 2.12.1

完成后,你可以使用 Git 來獲取 Git 的升級:

 # git clone git://git.kernel.org/pub/scm/git/git.git

三、安裝Gitlab

官方詳細解釋:https://about.gitlab.com/downloads/#centos6

1. 准備
#On Centos 6 and 7, the commands below will also open HTTP and SSH access in the system firewall.
#這句是用來做防火牆的。避免用戶通過ssh方式和http來訪問
lokkit -s http -s ssh

 yum -y install curl openssh-server openssh-clients postfix cronie
 service postfix start
 chkconfig postfix on
 lokkit -s http -s ssh
service postfix start
chkconfig postfix on
ss -tnlp
#無法啟動則查看日志 tail -f /var/log/maillog

2. 安裝
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo yum -y install gitlab-ce

#If you are not comfortable installing the repository through a piped script, you can find the entire script here and select and download the package manually and install using
#https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/
curl -LJO https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/6/gitlab-ce-XXX.rpm/download
rpm -i gitlab-ce-XXX.rpm

3. 啟動和配置
#對GitLab進行編譯。
gitlab-ctl reconfigure

	#Running handlers:
	#Running handlers complete
	#Chef Client finished, 108/329 resources updated in 01 minutes 12 seconds
	#gitlab Reconfigured!
#查看狀態
gitlab-ctl status
	run: gitlab-workhorse: (pid 5359) 134s; run: log: (pid 5190) 161s
	run: logrotate: (pid 5281) 149s; run: log: (pid 5280) 149s
	run: nginx: (pid 5236) 155s; run: log: (pid 5235) 155s
	run: postgresql: (pid 3547) 854s; run: log: (pid 2415) 1703s
	run: redis: (pid 3555) 853s; run: log: (pid 2278) 1714s
	run: sidekiq: (pid 5144) 167s; run: log: (pid 5143) 167s
	run: unicorn: (pid 5089) 173s; run: log: (pid 5088) 173s
ps -ef|grep unicorn
	root       5087   2230  0 09:38 ?        00:00:00 runsv unicorn
	root       5088   5087  0 09:38 ?        00:00:00 svlogd -tt /var/log/gitlab/unicorn
	git        5089   5087  0 09:38 ?        00:00:00 /bin/bash /opt/gitlab/embedded/bin/gitlab-unicorn-wrapper
	git        5107      1  2 09:38 ?        00:00:11 unicorn master -D -E production -c /var/opt/gitlab/gitlab-rails/etc/unicorn.rb /opt/gitlab/embedded/service/gitlab-rails/config.ru
	git        5271   5107  0 09:39 ?        00:00:00 unicorn worker[0] -D -E production -c /var/opt/gitlab/gitlab-rails/etc/unicorn.rb /opt/gitlab/embedded/service/gitlab-rails/config.ru
	git        5274   5107  0 09:39 ?        00:00:00 unicorn worker[1] -D -E production -c /var/opt/gitlab/gitlab-rails/etc/unicorn.rb /opt/gitlab/embedded/service/gitlab-rails/config.ru 

  

#登錄gitlab
#第一次登錄gitlab,需要為root用戶修改密碼,root用戶也是gitlab的超級管理員

#解決 80 端口被占用 和GitLab頭像無法正常顯示
#原因:gravatar被牆 解決辦法: 編輯 /etc/gitlab/gitlab.rb,將井號刪除
gitlab_rails['gravatar_plain_url'] = 'http://gravatar.duoshuo.com/avatar/%{hash}?s=%{size}&d=identicon'
#並且
external_url 'http://192.168.18.41:8888'

#external_url 'http://192.168.18.13'  //測試物理機直接用得80端口,不推薦。
#然后在命令行執行:

gitlab-ctl reconfigure
gitlab-rake cache:clear RAILS_ENV=production
#gitlab-ctl reconfigure 會生成N多配置,請探索“/var/opt/gitlab/”。
#直接nginx配置可以變更端口,但是GitLab頭像無法正常顯示。
#若有讀者發現變更端口后正常顯示頭像的方法請一定要分享給大家。
#配置文件:/var/opt/gitlab/nginx/conf/gitlab-http.conf

#然后事實上默認就生成有upstream gitlab-workhorse,所以改改listen的端口就足以。

upstream gitlab {
	server unix:/var/opt/gitlab/gitlab-workhorse/socket;
}
server {
    #偵聽的9999端口,端口我改過N多個所有不用在意這條注釋。
    listen       8888;
    server_name  *.renn.top;
    location / {
        proxy_pass   http://gitlab;    #在這里設置一個代理,和upstream的名字一樣
        #以下是一些反向代理的配置可刪除
        proxy_redirect             off;
        #后端的Web服務器可以通過X-Forwarded-For獲取用戶真實IP
        proxy_set_header           Host $host;
        proxy_set_header           X-Real-IP $remote_addr;
        proxy_set_header           X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size       10m; #允許客戶端請求的最大單文件字節數
        client_body_buffer_size    128k; #緩沖區代理緩沖用戶端請求的最大字節數
        proxy_connect_timeout      300; #nginx跟后端服務器連接超時時間(代理連接超時)
        proxy_send_timeout         300; #后端服務器數據回傳時間(代理發送超時)
        proxy_read_timeout         300; #連接成功后,后端服務器響應時間(代理接收超時)
        proxy_buffer_size          4k; #設置代理服務器(nginx)保存用戶頭信息的緩沖區大小
        proxy_buffers              4 32k; #proxy_buffers緩沖區,網頁平均在32k以下的話,這樣設置
        proxy_busy_buffers_size    64k; #高負荷下緩沖大小(proxy_buffers*2)
        proxy_temp_file_write_size 64k; #設定緩存文件夾大小,大於這個值,將從upstream服務器傳
    }
}

End

以下內容是我從網上找的並整理,請原諒粗心的我已忘記出處(畢竟閱讀了30+的文章)。

部分翻譯自官方的E文,有不准確處望諒解。

-------------------------------------
運維
# 啟動所有 gitlab 組件:
sudo gitlab-ctl start
# 停止所有 gitlab 組件:
sudo gitlab-ctl stop
# 重啟所有 gitlab 組件:
sudo gitlab-ctl restart
# 查看服務狀態
sudo gitlab-ctl status
# 啟動服務
sudo gitlab-ctl reconfigure
# 修改默認的配置文件
sudo vim /etc/gitlab/gitlab.rb
# 查看版本
sudo cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
# echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
# sysctl -p
# echo never > /sys/kernel/mm/transparent_hugepage/enabled
# 檢查gitlab
gitlab-rake gitlab:check SANITIZE=true --trace
# 查看日志
sudo gitlab-ctl tail

備份恢復

#Gitlab 創建備份
#使用Gitlab一鍵安裝包安裝Gitlab非常簡單, 同樣的備份恢復與遷移也非常簡單,用一條命令即可創建完整的Gitlab備份:
gitlab-rake gitlab:backup:create
#以上命令將在/var/opt/gitlab/backups目錄下創建一個名稱類似為xxxxxxxx_gitlab_backup.tar的壓縮包, 這個壓縮包就是Gitlab整個的完整部分, 其中開頭的xxxxxx是備份創建的時間戳。

Gitlab 修改備份文件默認目錄

#修改/etc/gitlab/gitlab.rb來修改默認存放備份文件的目錄:
gitlab_rails['backup_path'] = '/mnt/backups'
#修改后使用gitlab-ctl reconfigure命令重載配置文件。

備份
0 2 * * * /usr/bin/gitlab-rake gitlab:backup:create
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create

恢復
#首先進入備份 gitlab 的目錄,這個目錄是配置文件中的 gitlab_rails['backup_path'] ,默認為 /var/opt/gitlab/backups 。
#然后停止 unicorn 和 sidekiq ,保證數據庫沒有新的連接,不會有寫數據情況。

# 停止相關數據連接服務
# ok: down: unicorn: 0s, normally up
gitlab-ctl stop unicorn
# ok: down: sidekiq: 0s, normally up
gitlab-ctl stop sidekiq

# 從xxxxx編號備份中恢復
# 然后恢復數據,xxxxx為備份文件的時間戳
gitlab-rake gitlab:backup:restore BACKUP=xxxxxx

# 啟動Gitlab
sudo gitlab-ctl start
----------------------------------------


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM