因辦公室環(huán)境網(wǎng)絡(luò)調(diào)整,近期計(jì)劃將gitlab從內(nèi)網(wǎng)機(jī)房遷移至公有云。遷移過程做了一下簡單的記錄,希望對各位同行有所幫助。
創(chuàng)新互聯(lián)專注于新絳網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供新絳營銷型網(wǎng)站建設(shè),新絳網(wǎng)站制作、新絳網(wǎng)頁設(shè)計(jì)、新絳網(wǎng)站官網(wǎng)定制、小程序定制開發(fā)服務(wù),打造新絳網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供新絳網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
舊服務(wù)器A | centos6.9 | 10.1.2.10 | gitlab-ce-8.16.0-ce.0.el6.x86_64 |
---|---|---|---|
新服務(wù)器B | centos6.9 | 192.168.100.10 | gitlab-ce-8.16.0-ce.0.el6.x86_64 |
一、遷移基本思路
1、采購公有云服務(wù)器,自帶公網(wǎng)IP、加入onlyyou安全組。
2、安全組開放80端口(所有辦公網(wǎng)出口、v隧p道n(公))、9000端口(所有辦公網(wǎng)出口、v隧p道n(公)、以及Jks、其他測試服公網(wǎng)IP)。
3、搭建同版本Git服務(wù)。
4、發(fā)布公告,暫停git服務(wù)
5、將完整備份導(dǎo)入新Git。
6、利用iptables映射9000端口至3303(iptables -t nat -A PREROUTING -p tcp --dport 9000 -j REDIRECT --to-ports 3303)。(注:9000為之前frp的遠(yuǎn)程端口,3303為服務(wù)器B的ssh端口)
7、DNS解析(git.bd.com):刪除辦公網(wǎng)DNS的解析記錄,修改公網(wǎng)DNS解析記錄至服務(wù)器B公網(wǎng)IP。
二、操作步驟
2.1、備份
1.備份服務(wù)器A中的git數(shù)據(jù),具體備份操作命令
[root@serverA ~]# gitlab-rake gitlab:backup:create STRATEGY=copy
備份文件在/var/opt/gitlab/backups/下,假設(shè)備好的文件為1568659149_2019_03_17_10.6.4_gitlab_backup.tar
注:在備份期間需禁止對gitlab進(jìn)行任何操作
2.2、新服務(wù)器搭建gitlab
為了備份可用,新服務(wù)器上使用跟原服務(wù)器相同的版本
如果舊服務(wù)器已是最新版,可以在新服務(wù)器直接使用yum安裝.
如果安裝最新版本,采用以下方式安裝即可
`[root@serverB ~]# yum install gitlab-ce`
本人采用的是指定的相同的版本來進(jìn)行安裝的
1.因不是最新版本,需要從https://packages.gitlab.com/gitlab/gitlab-ce上下載所需的版本,此處因?yàn)榘惭b系統(tǒng)為centos6,所以下載el6版本
或者使用服務(wù)器A中的yum源文件
`[root@serverB ~]# cat /etc/yum.repos.d/gitlab_gitlab-ce.repo`
[gitlab_gitlab-ce]
name=gitlab_gitlab-ce
baseurl=https://packages.gitlab.com/gitlab/gitlab-ce/el/6/$basearch
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
[gitlab_gitlab-ce-source]
name=gitlab_gitlab-ce-source
baseurl=https://packages.gitlab.com/gitlab/gitlab-ce/el/6/SRPMS
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
2.安裝git
[root@serverB ~]# `yum -y install git`
3.安裝gitlib
[root@serverB ~]# ```
EXTERNAL_URL="http://gitlab.example.com" yum install -y gitlab-ce-10.6.4-ce.0.el6.x86_64
```
4、修改配置
安裝好后,修改/etc/gitlab/gitlab.rb
external_url 'http://gitlab.example.com'
其上所有的http://gitlab.example.com改成自己要使用的gitlab地址
在/var/opt/gitlab/nginx/conf/gitlab-http.conf 中修改所需端口
在/var/opt/gitlab/nginx/conf/nginx.conf 中增加
include /var/opt/gitlab/nginx/conf/custom.conf;
端口是為了跟原來的環(huán)境保持一致,比如原來的是54444,這里也修改成一樣的即可
custom.conf 是自己定義的白名單,比如:
allow 110.110.110.110;
deny all;
server {
server_name default;
listen *:80;
location / {
proxy_pass http://127.0.0.1:54444;
}
}
重新配置升效
[root@serverB ~]# gitlab-ctl reconfigure
2.3、拷貝備份
將備份從服務(wù)器A拷到新服務(wù)器B的/var/opt/gitlab/backups/下,此步從服務(wù)器A上操作
[root@serverA ~]# scp /var/opt/gitlab/backups/1568659149_2019_03_17_10.6.4_gitlab_backup.tar root@192.168.100.10:/var/opt/gitlab/backups/
修改備份文件權(quán)限,以免恢復(fù)備份時(shí)出現(xiàn)權(quán)限不足的情況
[root@serverB ~]# chown git:git 1568659149_2019_03_17_10.6.4_gitlab_backup.tar
[root@serverB ~]# chmod 777 1568659149_2019_03_17_10.6.4_gitlab_backup.tar
2.4、恢復(fù)備份
此步參考官方文檔https://docs.gitlab.com/ce/raketasks/backup_restore.html#restore-for-omnibus-installations
1.停止數(shù)據(jù)相服務(wù)
[root@serverB ~]# gitlab-ctl stop unicorn
[root@serverB ~]# gitlab-ctl stop sidekiq
[root@serverB ~]# gitlab-ctl status
2.恢復(fù)備份
此處命令結(jié)尾使用的是上面拷貝過來的文件名,但不是全名,取其_gitlab之前的名稱即可
最開始的時(shí)候,會提示輸入yes,直接輸入即可
[root@serverB ~]# gitlab-rake gitlab:backup:restore BACKUP=1568659149_2019_03_17_10.6.4
Unpacking backup ... done
Before restoring the database, we will remove all existing
tables to avoid future upgrade problems. Be aware that if you have
custom tables in the GitLab database these tables and all data will be
removed.
```
**Do you want to continue (yes/no)? yes**
```
Removing all tables. Press `Ctrl-C` within 5 seconds to abort
Cleaning the database ...
done
Restoring database ...
Restoring PostgreSQL database gitlabhq_production ... SET
SET
SET
SET
.......
Put GitLab hooks in repositories dirs [DONE]
done
Restoring uploads ...
done
Restoring builds ...
done
Restoring artifacts ...
done
Restoring pages ...
done
Restoring lfs objects ...
done
This will rebuild an authorized_keys file.
You will lose any data stored in authorized_keys file.
**Do you want to continue (yes/no)? no ##這里如果保留舊的權(quán)限,輸入no
**Quitting...
3.重置服務(wù)
[root@serverB ~]# gitlab-ctl restart
[root@serverB ~]# gitlab-rake gitlab:check SANITIZE=true
三、郵件功能確認(rèn)
關(guān)于gitlab是否可以正常發(fā)送郵件,需要做好確認(rèn)。
舊環(huán)境中,serverA中的配置使用的是25端口,但是公有云服務(wù)器默認(rèn)是屏蔽25端口的,發(fā)送郵件就會出現(xiàn)如下報(bào)錯。
最初配置為:
[root@serverB ~]# grep -v "#" /etc/gitlab/gitlab.rb | grep -v "^$"
external_url 'http://git.bd.com'
nginx['listen_port'] = 54444
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['gitlab_shell_ssh_port'] = 9000
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "git@bd.com"
gitlab_rails['smtp_password'] = "88888888"
gitlab_rails['smtp_domain'] = "exmail.qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['gitlab_email_from'] = 'git@bd.com'
user["git_user_email"] = "git@bd.com"
nginx['custom_nginx_config'] = "include /var/opt/gitlab/nginx/conf/custom.conf;"
gitlab_ci['backup_path'] = "/gitlab_backup"
[root@serverB ~]#
測試發(fā)送郵件功能
[root@serverB ~]# gitlab-rails console
Loading production environment (Rails 4.2.10)
irb(main):001:0> Notify.test_email("ch@bd.com","title","gitlab").deliver_now
Notify#test_email: processed outbound mail in 180.0ms
Sent mail to ch@bd.com (1885.3ms)
Date: Thu, 19 Sep 2019 19:05:27 +0800
From: GitLab <git@bd.com>
Reply-To: GitLab <noreply@git.bd.com>
To: ch@bd.com
Message-ID: <5d8360f7d0fae_79823fbf26cdb1b033298@serverB.mail>
Subject: title
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Auto-Submitted: auto-generated
X-Auto-Response-Suppress: All
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>gitlab</p></body></html>
Net::OpenTimeout: execution expired
from /opt/gitlab/embedded/lib/ruby/2.3.0/net/smtp.rb:542:in initialize'<br/>from /opt/gitlab/embedded/lib/ruby/2.3.0/net/smtp.rb:542:in
open'
from /opt/gitlab/embedded/lib/ruby/2.3.0/net/smtp.rb:542:in tcp_socket'<br/>from /opt/gitlab/embedded/lib/ruby/2.3.0/net/smtp.rb:552:in
block in do_start'
from /opt/gitlab/embedded/lib/ruby/2.3.0/timeout.rb:101:in timeout'<br/>from /opt/gitlab/embedded/lib/ruby/2.3.0/net/smtp.rb:551:in
do_start'
from /opt/gitlab/embedded/lib/ruby/2.3.0/net/smtp.rb:521:in start'<br/>from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/network/delivery_methods/smtp.rb:109:in
start_smtp_session'
from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/network/delivery_methods/smtp.rb:100:in deliver!'<br/>from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:2160:in
do_delivery'
from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:260:in block in deliver'<br/>from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/actionmailer-4.2.10/lib/action_mailer/base.rb:543:in
block in deliver_mail'
from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/activesupport-4.2.10/lib/active_support/notifications.rb:164:in block in instrument'<br/>from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/activesupport-4.2.10/lib/active_support/notifications/instrumenter.rb:20:in
instrument'
from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/activesupport-4.2.10/lib/active_support/notifications.rb:164:in instrument'<br/>from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/actionmailer-4.2.10/lib/action_mailer/base.rb:541:in
deliver_mail'
from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:260:in deliver'<br/>from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/actionmailer-4.2.10/lib/action_mailer/message_delivery.rb:85:in
deliver_now'
from (irb):1
from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/railties-4.2.10/lib/rails/commands/console.rb:110:in start'<br/>from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/railties-4.2.10/lib/rails/commands/console.rb:9:in
start'
from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:68:in console'<br/>from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:39:in
run_command!'
from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/railties-4.2.10/lib/rails/commands.rb:17:in <top (required)>'<br/>from bin/rails:9:in
require'
from bin/rails:9:in `<main>'
經(jīng)過排查分析,25端口已經(jīng)被統(tǒng)一關(guān)閉,需要使用安全傳輸層協(xié)議進(jìn)行發(fā)送郵件。
修改配置為
[root@serverB ~]# grep -v "#" /etc/gitlab/gitlab.rb | grep -v "^$"
external_url 'http://git.bd.com'
nginx['listen_port'] = 54444
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['gitlab_shell_ssh_port'] = 9000
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_tls'] = true
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "git@bd.com"
gitlab_rails['smtp_password'] = "88888888"
gitlab_rails['smtp_domain'] = "exmail.qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['gitlab_email_from'] = 'git@bd.com'
user["git_user_email"] = "git@bd.com"
nginx['custom_nginx_config'] = "include /var/opt/gitlab/nginx/conf/custom.conf;"
gitlab_ci['backup_path'] = "/gitlab_backup"
[root@serverB ~]#
修改后執(zhí)行g(shù)itlab-ctl reconfigure
確認(rèn)可以發(fā)送郵件:
[root@serverB ~]# gitlab-rails console
Loading production environment (Rails 4.2.10)
irb(main):001:0> Notify.test_email("ch@bd.com","title","gitlab").deliver_now
Notify#test_email: processed outbound mail in 180.0ms
Sent mail to ch@bd.com (1885.3ms)
Date: Thu, 19 Sep 2019 19:05:27 +0800
From: GitLab <git@bd.com>
Reply-To: GitLab <noreply@git.bd.com>
To: ch@bd.com
Message-ID: <5d8360f7d0fae_79823fbf26cdb1b033298@serverB.mail>
Subject: title
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Auto-Submitted: auto-generated
X-Auto-Response-Suppress: All
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>gitlab</p></body></html>
=> #<Mail::Message:70089965796760, Multipart: false, Headers: <Date: Thu, 19 Sep 2019 19:05:27 +0800>, <From: GitLab <git@bd.com>>, <Reply-To: GitLab <noreply@git.bd.com>>, <To: ch@bd.com>, <Message-ID: <5d8360f7d0fae_79823fbf26cdb1b033298@serverB.mail>>, <Subject: title>, <Mime-Version: 1.0>, <Content-Type: text/html; charset=UTF-8>, <Content-Transfer-Encoding: 7bit>, <Auto-Submitted: auto-generated>, <X-Auto-Response-Suppress: All>>
irb(main):002:0
若發(fā)送不成功請看下是否配置user['git_user_email'],若以上都配置了請查看云服務(wù)器安全組有沒有開放465端口。
四、驗(yàn)證方法:
辦公網(wǎng)環(huán)境驗(yàn)證ssh協(xié)議命令行操作及Web頁面打開情況。 ##通過
辦公網(wǎng)v隧p道n環(huán)境驗(yàn)證ssh協(xié)議命令行操作及Web頁面打開情況。 ##通過
公網(wǎng)環(huán)境驗(yàn)證ssh協(xié)議命令行操作及Web頁面禁止訪問和打開情況。 ##通過,公網(wǎng)禁止訪問
公網(wǎng)v隧p道n環(huán)境驗(yàn)證ssh協(xié)議命令行操作及Web頁面打開情況。 ##通過
網(wǎng)站題目:gitlab遷移實(shí)踐
轉(zhuǎn)載注明:http://muchs.cn/article24/piodce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號、云服務(wù)器、小程序開發(fā)、網(wǎng)站內(nèi)鏈、微信小程序、軟件開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)