公司的机房须要迁移,因此代码仓库也要跟着迁。这边先简单介绍下以前 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