GitLab安裝和升級(jí)
1.gitlab-ce安裝
這里使用的環(huán)境是Ubantu 16.04 LTS,注意gitlab-ce 鏡像僅支持 x86-64 架構(gòu)
中燥。我們使用的清華大學(xué)開源軟件鏡像站提供的版本叛本,國(guó)內(nèi)站點(diǎn)速度很快。
首先信任 GitLab 的 GPG 公鑰:
curl https://packages.gitlab.com/gpg.key 2> /dev/null | sudo apt-key add - &>/dev/null
把軟件源配置寫進(jìn) /etc/apt/sources.list.d/gitlab-ce.list
deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu xenial main
安裝 gitlab-ce:
sudo apt-get update
sudo apt-get install gitlab-ce
如果是centOS抑淫,那么信任軟件源需要新建 /etc/yum.repos.d/gitlab-ce.repo胳搞,內(nèi)容為:
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
然后進(jìn)行安裝:
sudo yum makecache
sudo yum install gitlab-ce
如果需要指定版本安裝:
# 查看可用版本
yum list gitlab-ce --showduplicates| sort -r
# 安裝指定版本
yum -y install docker-ce-17.06.0.ce
配置生效啟動(dòng)服務(wù):
gitlab-ctl reconfigure
gitlab-ctl restart
2.版本升級(jí)
升級(jí)需要先關(guān)閉部分服務(wù):
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-ctl stop nginx
升級(jí)命令與安裝命令相同
sudo apt-get update
sudo apt-get install gitlab-ce
然后重置配置和服務(wù)重啟
gitlab-ctl reconfigure
gitlab-ctl restart
服務(wù)器遷移
1.備份數(shù)據(jù)
首先備份原GIT服務(wù)器數(shù)據(jù)
gitlab-rake gitlab:backup:create RAILS_ENV=production
注:默認(rèn)備份后文件一般位于/var/opt/gitlab/backups/卸例,文件名類似:1513578325_2017_12_18_gitlab_backup.tar
然后備份配置文件:
/etc/gitlab/gitlab.rb #配置文件須備份
/var/opt/gitlab/nginx/conf #nginx配置文件
/etc/postfix/main.cfpostfix #郵件配置備份
2.復(fù)制備份文件到新服務(wù)器
使用遠(yuǎn)程拷貝命令復(fù)制文件到新的服務(wù)器
scp /var/opt/gitlab/backups/1513578325_2017_12_18_gitlab_backup.tar username@src_ip:/var/opt/gitlab/backups
3.新GitLab服務(wù)數(shù)據(jù)恢復(fù)
注意:需要保證新服務(wù)器的版本與舊服務(wù)器一致
查詢版本:
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
執(zhí)行命令進(jìn)行數(shù)據(jù)恢復(fù):
#cd /var/opt/gitlab/backups
#gitlab-rake gitlab:backup:restore BACKUP=備份文件編號(hào)
#gitlab-rake gitlab:backup:restore BACKUP=1502357536_2019_04_14_11.9.8
注:BACKUP的時(shí)間點(diǎn)必須與原服務(wù)器備份后的文件名一致
4.重啟服務(wù)檢測(cè)數(shù)據(jù)恢復(fù)情況
sudo gitlab-ctl restart
sudo gitlab-rake gitlab:check SANITIZE=true
如果check命令出現(xiàn)錯(cuò)誤称杨,說明備份的GitLab服務(wù)和新的GitLab服務(wù)版本不匹配,請(qǐng)安裝正確的版本
修改服務(wù)端口號(hào)
修改nginx端口:
sudo vi /etc/gitlab/gitlab.rb
nginx['listen_port'] = 8081
sudo vi /var/opt/gitlab/nginx/conf/gitlab-http.conf
server {
listen *:8081;
修改unicorn端口:
sudo vi /etc/gitlab/gitlab.rb
unicorn['port'] = 3648
sudo vi /var/opt/gitlab/gitlab-rails/etc/unicorn.rb
listen "127.0.0.1:3648", :tcp_nopush => true
保存配置筷转,重啟:
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
sudo gitlab-ctl status
修改默認(rèn)端口號(hào)后出現(xiàn)502問題恢復(fù)列另,可能是權(quán)限問題,嘗試以下命令來解決:
# chmod -R 777 /var/log/gitlab
# gitlab-ctl tail unicorn
修改HTTP連接方式中的IP和端口
修改gitlab.yml文件
cd /opt/gitlab/embedded/service/gitlab-rails/config
vim gitlab.yml
修改host和port
host:要修改的IP
port:要修改的端口
重啟gitlab
gitlab-ctl restart
郵件通知功能設(shè)置
為郵件通知功能配置smtp服務(wù)和發(fā)件郵箱:
vim /etc/gitlab/gitlab.rb
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.ym.163.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "xxuser@163.com"
gitlab_rails['smtp_password'] = "xxpassword"
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = :login
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['gitlab_email_from'] = "xxuser@163.com"
user["git_user_email"] = "xxuser@163.com"
重置配置:
sudo gitlab-ctl reconfigure
如有問題可以查看日志:
gitlab-ctl tail
使用gitlab-rails console測(cè)試郵件功能:
username@hostname$ gitlab-rails console
username@hostname$ Notify.test_email('xxxxx@xxx.com','Message Subject','message Body').deliver_now
常見問題
1.頁面500問題解決
在升級(jí)過后旦装,或者恢復(fù)配置之后页衙,對(duì)項(xiàng)目進(jìn)行刪除修改等操作會(huì)出現(xiàn)失敗,報(bào)500阴绢,這是因?yàn)樯?jí)造成gitlab數(shù)據(jù)庫中token參數(shù)錯(cuò)誤店乐,需要重置,方法入下呻袭, 對(duì)指定id的項(xiàng)目將token設(shè)置為null
root@gitserver:/etc/gitlab# sudo gitlab-rails dbconsole
psql (9.6.11)
Type "help" for help.
gitlabhq_production=> UPDATE projects SET runners_token = null, runners_token_encrypted = null WHERE id = 5 ;
UPDATE 1
2.升級(jí)500問題錯(cuò)誤
前面高興的太早眨八,訪問GitLab發(fā)現(xiàn)報(bào)500錯(cuò)誤,觀察log得知大意為DB數(shù)據(jù)關(guān)系錯(cuò)誤左电,需要升級(jí)數(shù)據(jù)庫關(guān)系
輸入以下指令查看數(shù)據(jù)升級(jí)狀態(tài)
sudo gitlab-rake db:migrate:status
果然發(fā)現(xiàn)有一些顯示為Down廉侧,顯示為Up即表示正常同,再執(zhí)行數(shù)據(jù)庫關(guān)系升級(jí)
sudo gitlab-rake db:migrate
執(zhí)行完成再重復(fù)重建篓足、重啟命令段誊,問題解決
3.配置加載阻塞:
安裝過程中執(zhí)行g(shù)itlab-ctl reconfigure,出現(xiàn)長(zhǎng)時(shí)間卡住的情況:
運(yùn)行:sudo systemctl restart gitlab-runsvdir栈拖;
再次執(zhí)行:sudo gitlab-ctl reconfigure
4.修改注冊(cè)權(quán)限問題報(bào)500:
https://gitlab.com/gitlab-org/gitlab-ce/issues/56403
參考文章: