gitlab 搭建 備份 升級 遷移恢復

gitlab搭建

1.安裝依賴項

suo apt update
sudo apt upgrade -y
sudo apt install ca-certificates curl openssh-server postfix

2.添加gitlab-ce存儲庫

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

3.安裝gitlab-ce

sudo apt update

sudo EXTERNAL_URL="http://gitlab.example.com" apt -y install gitlab-ce

?在執(zhí)行命令之前讥脐,將gitlab.example.com替換為你的實際域名醉者。完成后,通過運行以下命令啟動GitLab實例:


sudo gitlab-ctl reconfigure

配置后應啟動所有的GitLab服務:

gitlab 備份

停止用戶連接

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-ctl stop nginx

創(chuàng)建備份

gitlab-rake gitlab:backup:create

如果出錯請檢查權限問題 我的是默認root
可以加sudo重新試一下

gitlab升級

gitlab普通升級就正常升級就可以了
?升級不能跨越大版本號窥岩,因此只能升級到當前大版本號到最高版本甲献,
方可升級到下一個大版本號

如果是跨大版本升級要嚴格按照官方指導的升級順序進行
參考:
https://docs.gitlab.com/ce/policy/maintenance.html

先停止用戶連接
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-ctl stop nginx

創(chuàng)建備份:
gitlab-rake gitlab:backup:create

然后安裝升級
例如我從清華軟件源下載好的deb安裝包
直接dpkg -i 安裝就行了
rpm包也是
也可以直接在線升級
完事重啟
sudo gitlab-ctl restart

gitlab遷移恢復

1.執(zhí)行備份數(shù)據(jù)
2.在目標機器中搭建與執(zhí)行備份相同版本的gitlab
?版本一定要相同
3.將備份的tar包復制到目標機器備份目錄
?默認路徑為:/var/opt/gitlab/backups/
4.恢復數(shù)據(jù)

依然要把這些服務停掉
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-ctl stop nginx

然后執(zhí)行
gitlab-rake gitlab:backup:restore BACKUP=備份文件gitlab_backup.tar前面的數(shù)字

正常情況下就是以上這些步驟了
如果你整個過程順順利利的那么到這里就結束了

但是我的過程中充滿了曲折
以下是我遇到的一些錯誤
僅以記錄供參考


處理gitlab升級時的錯誤

錯誤信息
錯誤原因:端口占用
修改默認端口
找到gitlab.rb這個配置文件
external_url 'http://你的域名:8082'
把最后的端口修改成別空的端口
使配置生效

gitlab-ctl reconfigure

重新啟動GitLab

gitlab-ctl restart
即可生效

備份時遇到的錯誤

Dumping database ... 
Dumping PostgreSQL database gitlabhq_production ... pg_dump: [archiver (db)] connection to database "gitlabhq_production" failed: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/opt/gitlab/postgresql/.s.PGSQL.5432"?
[FAILED]
Backup failed
原因:

postgresql 沒有啟動
參考https://www.tlanyan.me/deal-gitlab-upgrade-error/

解決辦法
sudo gitlab-ctl start postgresql

reconfigure過程中的一個錯誤

  * execute[/opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8] action run
    [execute] The files belonging to this database system will be owned by user "gitlab-psql".
              This user must also own the server process.
              
              initdb: invalid locale settings; check LANG and LC_* environment variables
    
    ================================================================================
    Error executing action `run` on resource 'execute[/opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8]'
    ================================================================================
    
    Mixlib::ShellOut::ShellCommandFailed
    ------------------------------------
    Expected process to exit with [0], but received '1'
    ---- Begin output of /opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8 ----
    STDOUT: The files belonging to this database system will be owned by user "gitlab-psql".
    This user must also own the server process.
    STDERR: initdb: invalid locale settings; check LANG and LC_* environment variables
    ---- End output of /opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8 ----
    Ran /opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8 returned 1
    
    Resource Declaration:
    ---------------------
    # In /opt/gitlab/embedded/cookbooks/cache/cookbooks/postgresql/recipes/enable.rb
    
     80: execute "/opt/gitlab/embedded/bin/initdb -D #{node['postgresql']['data_dir']} -E UTF8" do
     81:   user postgresql_username
     82:   not_if { pg_helper.bootstrapped? }
     83: end
     84: 
    
    Compiled Resource:
    ------------------
    # Declared in /opt/gitlab/embedded/cookbooks/cache/cookbooks/postgresql/recipes/enable.rb:80:in `from_file'
    
    execute("/opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8") do
      action [:run]
      default_guard_interpreter :execute
      command "/opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8"
      backup 5
      declared_type :execute
      cookbook_name "postgresql"
      recipe_name "enable"
      user "gitlab-psql"
      domain nil
      not_if { #code block }
    end
    
    System Info:
    ------------
    chef_version=14.13.11
    platform=debian
    platform_version=9.9
    ruby=ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
    program_name=/opt/gitlab/embedded/bin/chef-client
    executable=/opt/gitlab/embedded/bin/chef-client
    

Running handlers:
There was an error running gitlab-ctl reconfigure:

execute[/opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8] (postgresql::enable line 80) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of /opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8 ----
STDOUT: The files belonging to this database system will be owned by user "gitlab-psql".
This user must also own the server process.
STDERR: initdb: invalid locale settings; check LANG and LC_* environment variables
---- End output of /opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8 ----
Ran /opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8 returned 1

Running handlers complete
Chef Client failed. 6 resources updated in 07 seconds
解決辦法
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
sudo dpkg-reconfigure locales
reconfigure過程中的另一個錯誤

在升級完成 執(zhí)行gitlab-ctl reconfigure的時候出現(xiàn)

Error executing action `run` on resource 'execute[initctl status gitlab-runs
解決辦法

參照的這個
http://www.doc88.com/p-2542809540436.html
我也沒看太懂原理
反正好使 回頭再研究

截圖

至此 gitlab總算啟動起來了
感謝google&baidu各路大神
以上

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市颂翼,隨后出現(xiàn)的幾起案子晃洒,更是在濱河造成了極大的恐慌慨灭,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,277評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件球及,死亡現(xiàn)場離奇詭異缘挑,居然都是意外死亡,警方通過查閱死者的電腦和手機桶略,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評論 3 393
  • 文/潘曉璐 我一進店門语淘,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人际歼,你說我怎么就攤上這事惶翻。” “怎么了鹅心?”我有些...
    開封第一講書人閱讀 163,624評論 0 353
  • 文/不壞的土叔 我叫張陵吕粗,是天一觀的道長。 經(jīng)常有香客問我旭愧,道長颅筋,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,356評論 1 293
  • 正文 為了忘掉前任输枯,我火速辦了婚禮议泵,結果婚禮上,老公的妹妹穿的比我還像新娘桃熄。我一直安慰自己先口,他們只是感情好,可當我...
    茶點故事閱讀 67,402評論 6 392
  • 文/花漫 我一把揭開白布瞳收。 她就那樣靜靜地躺著碉京,像睡著了一般。 火紅的嫁衣襯著肌膚如雪螟深。 梳的紋絲不亂的頭發(fā)上谐宙,一...
    開封第一講書人閱讀 51,292評論 1 301
  • 那天,我揣著相機與錄音界弧,去河邊找鬼凡蜻。 笑死,一個胖子當著我的面吹牛夹纫,可吹牛的內容都是我干的咽瓷。 我是一名探鬼主播设凹,決...
    沈念sama閱讀 40,135評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼舰讹,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了闪朱?” 一聲冷哼從身側響起月匣,我...
    開封第一講書人閱讀 38,992評論 0 275
  • 序言:老撾萬榮一對情侶失蹤钻洒,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后锄开,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體素标,經(jīng)...
    沈念sama閱讀 45,429評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,636評論 3 334
  • 正文 我和宋清朗相戀三年萍悴,在試婚紗的時候發(fā)現(xiàn)自己被綠了头遭。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,785評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡癣诱,死狀恐怖计维,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情撕予,我是刑警寧澤鲫惶,帶...
    沈念sama閱讀 35,492評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站实抡,受9級特大地震影響欠母,放射性物質發(fā)生泄漏。R本人自食惡果不足惜吆寨,卻給世界環(huán)境...
    茶點故事閱讀 41,092評論 3 328
  • 文/蒙蒙 一赏淌、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧啄清,春花似錦猜敢、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至添寺,卻和暖如春胯盯,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背计露。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評論 1 269
  • 我被黑心中介騙來泰國打工博脑, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人票罐。 一個月前我還...
    沈念sama閱讀 47,891評論 2 370
  • 正文 我出身青樓叉趣,卻偏偏與公主長得像,于是被迫代替她去往敵國和親该押。 傳聞我的和親對象是個殘疾皇子疗杉,可洞房花燭夜當晚...
    茶點故事閱讀 44,713評論 2 354

推薦閱讀更多精彩內容