如何配置 gitlab 以使用现有的 postgres 服务器

How to configure gitlab to use existing postgres server

默认安装 Gitlab 时,Nginx 和 Postgres .. 无论您是否已经安装,都会安装它们。所以因为我已经有了这两个,我正在尝试配置 gitlab 来使用它们,我已经为 Nginx 做了这个,使用:

$ vi /etc/gitlab/gitlab.rb:

# Disable GitLab's nginx completely
nginx['enable'] = false

# Set external web user which is 'nginx' on CentOS 7
web_server['external_users'] = ['nginx']

但我需要知道如何做同样的事情 postgres

根据 this doc,将其放入 /etc/gitlab/gitlab.rb :

# Disable the built-in Postgres
postgresql['enable'] = false

# Fill in the values for database.yml
gitlab_rails['db_adapter'] = 'postgresql'
gitlab_rails['db_encoding'] = 'utf8'
gitlab_rails['db_host'] = '127.0.0.1'
gitlab_rails['db_port'] = '5432'
gitlab_rails['db_username'] = 'foo'
gitlab_rails['db_password'] = 'bar'

和 运行 此命令应用此值:sudo gitlab-ctl reconfigure。如果您选择外部数据库,还需要为您的数据库播种。此命令将使用 omnibus-gitlab 执行此操作:sudo gitlab-rake gitlab:setup

Pierre 的解决方案适用于新安装,但如果数据库中已有数据,则需要迁移。最干净、最安全的方法是创建一个备份,其中也包含数据库:

gitlab-rake gitlab:backup:create

备份文件将位于 /var/opt/gitlab/backups

或者,您可以尝试:

sudo -u gitlab-psql /opt/gitlab/embedded/bin/pg_dumpall --username=gitlab-psql --host=/var/opt/gitlab/postgresql

然后您可以将数据库导入现有的 Postgres 实例:

psql -f /tmp/database.sql

那么你也需要重新配置并重启:

gitlab-ctl start && gitlab-ctl reconfigure && gitlab-ctl restart

它以 start 开头,因为你需要确保 GitLab 是 运行。这是因为,无论听起来多么奇怪,如果 GitLab 停止,reconfigure 就会失败:

Errno::ENOENT: No such file or directory - connect(2) for /var/opt/gitlab/redis/redis.socket

这有点违反直觉,因为传统上您会在实例停止时更改配置。


但是 无论是迁移还是全新安装,第一次 GitLab 升级都会出现问题:

gitlab preinstall: Automatically backing up only the GitLab SQL database (excluding everything else!)
Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... pg_dump: server version: 10.4; pg_dump version: 9.6.8
pg_dump: aborting because of server version mismatch
Backup failed
[FAILED]

按照它的指示,您必须:

sudo touch /etc/gitlab/skip-auto-migrations

所以现在包更新成功了,但是 GitLab 还是不行,你得再来一次:

gitlab-ctl reconfigure

要自动执行此操作:

yum install yum-plugin-post-transaction-actions
echo 'gitlab-ce:any:/bin/gitlab-ctl reconfigure' > /etc/yum/post-actions/gitlab-ce.action

有关所有细节,请参阅: