公司的機房須要遷移,因此代碼倉庫也要跟着遷。這邊先簡單介紹下以前 GitLab 的搭建和使用狀況。html
在遷移以前 GitLab 已經已經運行了一段時間,整個代碼倉庫的數據量大約在 22G 左右,GitLab 基於 rpm 的方式進行安裝,代碼數據天天進行全量備份,備份數據保留 7 天,備份的數據沒有申請 NAS 備份,而是備份在系統的一個數據分區上面。系統沒有加監控,我接手的時候,上面的數據備份分區都已經滿了,可是系統運維人員都不知道,致使後面的數據備份都是失敗的。python
上面就是老 GitLab 大體的狀況。遷移的方案:git
在開始安裝配置前,先來介紹下 GitLab 的總體架構,熟悉以後對後續的安裝、配置和運維都頗有幫助。sql
遷移以前,你要給你的新的 GitLab 服務器的硬件作合理的配置選擇。shell
關於內存和 CPU 的配置,官網給出的推薦配置:數據庫
根據本身的用戶量,作出合理的選擇。vim
關於存儲的配置,我這邊根據現有的GitLab 上的數據量選擇了1T的存儲緩存
GitLab 官網有詳細介紹安裝方式。由於咱們的機器是在內網區域,不能鏈接互聯網,也爲了和以前的安裝方式保持一致,因此選擇 RPM 包的安裝方式。(若是是初次安裝的話能夠考慮使用 Docker 的安裝方式)bash
GitLab 的 RPM 包下載地址可使用清華大學的鏡像。服務器
下載以前你最好看下以前的版本,下載的版本最好是和以前一致,防止數據不兼容。
通常使用下面命令查看版本。
[root@localhost gitlab]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION 12.1.1
通常 GitLab 上都會保存公司的核心代碼,因此建議安裝在公司的內網區域。
# rpm 包方式安裝 [root@i-lobhuk71 upload]# rpm -ivh ./gitlab-ce-12.1.1-ce.0.el7.x86_64.rpm --force warning: ./gitlab-ce-12.1.1-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY error: Failed dependencies: policycoreutils-python is needed by gitlab-ce-12.1.1-ce.0.el7.x86_64 # 出現上面的錯誤,是由於缺乏policycoreutils-python,安裝依賴 [root@i-lobhuk71 upload]# yum install policycoreutils-python # 再次執行 [root@i-lobhuk71 upload]# rpm -ivh ./gitlab-ce-12.1.1-ce.0.el7.x86_64.rpm --force warning: ./gitlab-ce-12.1.1-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY Preparing... ################################# [100%] Updating / installing... 1:gitlab-ce-12.1.1-ce.0.el7 ################################# [100%] It looks like GitLab has not been configured yet; skipping the upgrade script. *. *. *** *** ***** ***** .****** ******* ******** ******** ,,,,,,,,,***********,,,,,,,,, ,,,,,,,,,,,*********,,,,,,,,,,, .,,,,,,,,,,,*******,,,,,,,,,,,, ,,,,,,,,,*****,,,,,,,,,. ,,,,,,,****,,,,,, .,,,***,,,, ,*,. _______ __ __ __ / ____(_) /_/ / ____ _/ /_ / / __/ / __/ / / __ `/ __ \ / /_/ / / /_/ /___/ /_/ / /_/ / \____/_/\__/_____/\__,_/_.___/ Thank you for installing GitLab! GitLab was unable to detect a valid hostname for your instance. Please configure a URL for your GitLab instance by setting `external_url` configuration in /etc/gitlab/gitlab.rb file. Then, you can start your GitLab instance by running the following command: sudo gitlab-ctl reconfigure For a comprehensive list of configuration options please see the Omnibus GitLab readme https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md # 初始化Gitlab命令(保存配置或從新載入配置): [root@i-lobhuk71 upload] gitlab-ctl reconfigure
執行完上面的命令後,能夠看到下面的目錄結構:
# Gitlab服務的啓停管理 啓動服務: gitlab-ctl start 中止服務: gitlab-ctl stop 重啓服務: gitlab-ctl restart 查看狀態: gitlab-ctl status # Gitlab的supervisor方式啓動服務 服務啓動命令: systemctl start gitlab-runsvdir.service 服務中止命令: systemctl stop gitlab-runsvdir.service 服務重啓命令: systemctl restart gitlab-runsvdir.service 服務開機啓動命令: systemctl enable gitlab-runsvdir.service 取消開機啓動命令: systemctl disable gitlab-runsvdir.service 服務查看命令: systemctl list-unit-files # 能夠查看到gitlab全部插件的日誌狀況 Gitlab服務日誌查看:/usr/bin/gitlab-ctl tail
通過上面的配置已經能夠經過 IP 地址(安裝服務器的IP)訪問了,首次訪問會讓你建立管理員密碼(帳號默認是root)。
external_url
編輯/etc/gitlab/gitlab.rb
,修改其中的external_url
配置:
## GitLab URL ##! URL on which GitLab will be reachable. ##! For more details on configuring external_url see: ##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab ## 這邊配置成本機的IP地址就能夠了 external_url 'http://10.2.xx.xx'
clone地址
將克隆地址改爲域名(http形式,不是https形式)
編輯/var/opt/gitlab/gitlab-rails/etc/gitlab.yml
,將下面的host改爲域名。
最後執行 gitlab-ctl restart
命令使之配置生效,注意不要執行 gitlab-ctl reconfigure
。
[root@gitlab ~] vim /etc/gitlab/gitlab.rb ...... gitlab_rails['ldap_enabled'] = true gitlab_rails['ldap_servers'] = YAML.load <<-EOS # remember to close this block with 'EOS' below main: # 'main' is the GitLab 'provider ID' of this LDAP server label: '哈哈集團-Gitlab登陸入口' host: '192.168.10.141' port: 389 uid: 'userPrincipalName' method: 'plain' # "tls" or "ssl" or "plain" allow_username_or_email_login: false bind_dn: 'cn=王一,ou=技術運維部,dc=kevin,dc=com' password: '9oGlYkgDzhp5k6JZ' active_directory: true base: 'ou=技術運維部,dc=kevin,dc=com' user_filter: '' EOS # 接着執行下面命令,使上面配置生效: # 這裏最好使用該命令,表示重載配置。不要使用"gitlab-ctl restart"重啓服務,不然可能出現500報錯! [root@gitlab ~]# gitlab-ctl reconfigure # 而後執行下面命令,檢查LDAP信息是否成功同步過來 [root@gitlab ~]# gitlab-rake gitlab:ldap:check Checking LDAP ... Server: ldapmain LDAP authentication... Success LDAP users with access to your GitLab server (only showing the first 100 results) DN: CN=李某某,OU=技術運維部,DC=kevin,DC=com userPrincipalName: limoumou@kevin.com DN: CN=李二,OU=技術運維部,DC=kevin,DC=com userPrincipalName: lier@kevin.com DN: CN=lier1,OU=技術運維部,DC=kevin,DC=com userPrincipalName: lier1@kevin.com DN: CN=test,OU=技術運維部,DC=kevin,DC=com userPrincipalName: test@kevin.com DN: CN=王一,OU=技術運維部,DC=kevin,DC=com userPrincipalName: wangyi@kevin.com DN: CN=張三,OU=技術運維部,DC=kevin,DC=com userPrincipalName: zhangsan@kevin.com DN: CN=張三,OU=網絡,OU=技術運維部,DC=kevin,DC=com userPrincipalName: zhangsan02@kevin.com DN: CN=趙四,OU=網絡,OU=技術運維部,DC=kevin,DC=com userPrincipalName: zhaosi@kevin.com Checking LDAP ... Finished
設置 GitLab 備份目錄
能夠經過/etc/gitlab/gitlab.rb
配置文件來修改默認存放備份文件的目錄
# /var/opt/gitlab/backups 修改成你想存放備份的目錄便可, 修改完成以後使用gitlab-ctl reconfigure命令重載配置文件便可. gitlab_rails['backup_path']="/var/opt/gitlab/backups"
設置定時任務(crontab -e)
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create
重啓crontab
systemctl restart crond
設置備份的天數
編輯/etc/gitlab/gitlab.rb文件。
###! The duration in seconds to keep backups before they are allowed to be deleted ### keep 2 days gitlab_rails['backup_keep_time'] = 172800
# 中止相關數據鏈接服務 gitlab-ctl stop unicorn gitlab-ctl stop sidekiq # 從1628100892_2021_08_05_12.1.1_gitlab_backup.tar 備份中恢復 gitlab-rake gitlab:backup:restore BACKUP=1628100892_2021_08_05_12.1.1 # 啓動Gitlab gitlab-ctl start
須要注意的是 NAS 盤是有寫入權限的,GitLab 生成的文件默認的用戶和用戶組都是git:git,因此在申請nas盤的時候須要將寫入權限配置給git:git。
問題描述
PG::ConnectionBad: 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"?
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:49:inblock (3 levels) in <top (required)>' /opt/gitlab/embedded/bin/bundle:23:in
load'
/opt/gitlab/embedded/bin/bundle:23:in `'
Tasks: TOP => gitlab:db:configure
(See full trace by running task with --trace)
————————————————
版權聲明:本文爲CSDN博主「ArvinWoo」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處連接及本聲明。
原文連接: https://blog.csdn.net/qq_37595946/article/details/86534961
解決方法:
一、按住CTRL+C強制結束
二、先中止 gitlab ,命令: sudo gitlab-ctl stop
三、執行命令: sudo chmod 755 /var/opt/gitlab/postgresql
四、執行命令:sudo systemctl restart gitlab-runsvdir
五、再次配置:sudo gitlab-ctl reconfigure
六、啓動便可:sudo gitlab-ctl restart