Configuring GitLab application (Rails)
原文:https://docs.gitlab.com/ee/administration/high_availability/gitlab.html
- First GitLab application server
- Extra configuration for additional GitLab application servers
- Enable Monitoring
- Troubleshooting
- Upgrading GitLab HA
Configuring GitLab application (Rails)
本节介绍如何配置 GitLab 应用程序(Rails)组件.
注意:底部附近还有一些其他配置,用于其他 GitLab 应用程序服务器. 在继续安装 GitLab 之前,阅读并理解这些其他步骤非常重要.注意:建议尽可能通过NFS使用Gitaly 的 Cloud Object Storage 服务 ,以提高性能.
如有必要,请使用以下命令安装 NFS 客户端实用程序软件包:
# Ubuntu/Debian apt-get install nfs-common # CentOS/Red Hat yum install nfs-utils nfs-utils-lib
- 在
/etc/fstab
指定必要的 NFS 导出./etc/fstab
的确切内容取决于您选择配置 NFS 服务器的方式. 有关示例和各种选项,请参见NFS 文档 .
- 在
创建共享目录. 这些可能会有所不同,具体取决于您的 NFS 安装位置.
mkdir -p /var/opt/gitlab/.ssh /var/opt/gitlab/gitlab-rails/uploads /var/opt/gitlab/gitlab-rails/shared /var/opt/gitlab/gitlab-ci/builds /var/opt/gitlab/git-data
- 使用GitLab 下载中的 步骤 1 和 2下载/安装 Omnibus GitLab. 不要完成下载页面上的其他步骤.
创建/编辑
/etc/gitlab/gitlab.rb
并使用以下配置. 确保更改external_url
以匹配最终的 GitLab 前端 URL. 根据您的 NFS 配置,您可能需要更改某些 GitLab 数据位置. 有关各种情况的/etc/gitlab/gitlab.rb
配置值,请参见NFS 文档 . 下面的示例假定您已在默认数据位置中添加了 NFS 挂载. 此外,给出的 UID 和 GID 只是示例,您应该使用首选值进行配置.external_url 'https://gitlab.example.com' # Prevent GitLab from starting if NFS data mounts are not available high_availability['mountpoint'] = '/var/opt/gitlab/git-data' # Disable components that will not be on the GitLab application server roles ['application_role'] nginx['enable'] = true # PostgreSQL connection details gitlab_rails['db_adapter'] = 'postgresql' gitlab_rails['db_encoding'] = 'unicode' gitlab_rails['db_host'] = '10.1.0.5' # IP/hostname of database server gitlab_rails['db_password'] = 'DB password' # Redis connection details gitlab_rails['redis_port'] = '6379' gitlab_rails['redis_host'] = '10.1.0.6' # IP/hostname of Redis server gitlab_rails['redis_password'] = 'Redis Password' # Ensure UIDs and GIDs match between servers for permissions via NFS user['uid'] = 9000 user['gid'] = 9000 web_server['uid'] = 9001 web_server['gid'] = 9001 registry['uid'] = 9002 registry['gid'] = 9002
注意:为了保持 HA 群集之间链接的统一性,第一个应用程序服务器上的
external_url
以及其他应用程序服务器应指向用户将用来访问 GitLab 的外部 URL. 在典型的 HA 设置中,这将是负载平衡器的 URL,它将把流量路由到 HA 群集中的所有 GitLab 应用程序服务器.注意:如上例所示,当在external_url
指定https
时,GitLab 会假定您在/etc/gitlab/ssl/
具有 SSL 证书. 如果没有证书,NGINX 将无法启动. 有关更多信息,请参见NGINX 文档 .注意:最好在初始重新配置 GitLab 之前设置uid
和gid
. 如果在初始重新配置后设置,Omnibus 将不会递归chown
目录.
First GitLab application server
在第一台应用程序服务器上,运行:
sudo gitlab-ctl reconfigure
这应该编译配置并初始化数据库. 在下一步之前,不要在其他应用程序服务器上运行此命令.
Extra configuration for additional GitLab application servers
其他的 GitLab 服务器( 在第一个 GitLab 服务器之后配置的服务器)需要一些额外的配置.
配置共享机密. 这些值可以从
/etc/gitlab/gitlab-secrets.json
的主要 GitLab 服务器/etc/gitlab/gitlab-secrets.json
. 在运行上述步骤中的第一次reconfigure
之前,将此文件复制到辅助服务器.gitlab_shell['secret_token'] = 'fbfb19c355066a9afb030992231c4a363357f77345edd0f2e772359e5be59b02538e1fa6cae8f93f7d23355341cea2b93600dab6d6c3edcdced558fc6d739860' gitlab_rails['otp_key_base'] = 'b719fe119132c7810908bba18315259ed12888d4f5ee5430c42a776d840a396799b0a5ef0a801348c8a357f07aa72bbd58e25a84b8f247a25c72f539c7a6c5fa' gitlab_rails['secret_key_base'] = '6e657410d57c71b4fc3ed0d694e7842b1895a8b401d812c17fe61caf95b48a6d703cb53c112bc01ebd197a85da81b18e29682040e99b4f26594772a4a2c98c6d' gitlab_rails['db_key_base'] = 'bf2e47b68d6cafaef1d767e628b619365becf27571e10f196f98dc85e7771042b9203199d39aff91fcb6837c8ed83f2a912b278da50999bb11a2fbc0fba52964'
- 运行
touch /etc/gitlab/skip-auto-reconfigure
以防止数据库迁移在升级时运行. 只有主 GitLab 应用程序服务器才能处理迁移.
- 运行
推荐配置主机密钥. 将主应用程序服务器上
/etc/ssh/
的内容(私钥和公钥)复制到所有辅助服务器上的/etc/ssh
. 这样可以防止访问负载平衡器后面的高可用性群集中的服务器时出现虚假的中间人攻击警报.运行
sudo gitlab-ctl reconfigure
来编译配置.
注意:发生更新并执行数据库迁移后,您将需要重新启动 GitLab 应用程序节点.
Enable Monitoring
在 GitLab 12.0 中引入 .
如果启用了监视,则必须在所有 GitLab 服务器上将其启用.
Make sure to collect
CONSUL_SERVER_NODES
, which are the IP addresses or DNS records of the Consul server nodes, for the next step. Note they are presented asY.Y.Y.Y consul1.gitlab.example.com Z.Z.Z.Z
创建/编辑
/etc/gitlab/gitlab.rb
并添加以下配置:Enable service discovery for Prometheus
consul['enable'] = true consul['monitoring_service_discovery'] = true
Replace placeholders
Y.Y.Y.Y consul1.gitlab.example.com Z.Z.Z.Z
with the addresses of the Consul server nodes
consul['configuration'] = { retry_join: %w(Y.Y.Y.Y consul1.gitlab.example.com Z.Z.Z.Z), }
Set the network addresses that the exporters will listen on
node_exporter['listen_address'] = '0.0.0.0:9100' gitlab_workhorse['prometheus_listen_addr'] = '0.0.0.0:9229' sidekiq['listen_address'] = "0.0.0.0" puma['listen'] = '0.0.0.0'
Add the monitoring node's IP address to the monitoring list that allows it to
scrape the NGINX metrics. Replace placeholder
monitoring.gitlab.example.com
withthe address and/or subnets gathered from the monitoring node(s).
gitlab_rails['monitoring_whitelist'] = ['monitoring.gitlab.example.com', '127.0.0.0/8'] nginx['status']['options']['allow'] = ['monitoring.gitlab.example.com', '127.0.0.0/8']
- 运行
sudo gitlab-ctl reconfigure
来编译配置.
警告:如果运行 Unicorn,则在
gitlab.rb
更改unicorn['listen']
并运行sudo gitlab-ctl reconfigure
后,收到HUP
后,Unicorn 可能需要较长的时间才能完成重新加载. 有关更多信息,请参见问题 .- 运行
Troubleshooting
mount: wrong fs type, bad option, bad superblock on
您尚未安装必要的 NFS 客户端实用程序. 请参阅上面的步骤 1.
mount: mount point /var/opt/gitlab/... does not exist
NFS 服务器上不存在此特定目录. 确保共享已导出并且存在于 NFS 服务器上,然后尝试重新安装.
Upgrading GitLab HA
可以在不停机的情况下升级 GitLab HA 安装,但是必须仔细协调升级过程,以免发生故障. 有关更多详细信息,请参见Omnibus GitLab 多节点升级文档 .
阅读更多有关高可用性配置的信息: