You need to enable JavaScript to run this app. 配置HTTP基本/摘要认证的Gerrit 3.2.3服务启动失败排查
优惠活动
大模型
产品
解决方案
定价
更多

配置HTTP基本/摘要认证的Gerrit 3.2.3服务启动失败排查

Gerrit 3.2.3 HTTP认证集成部署启动故障排查

部署背景

在环境中部署集成HTTP认证模式的Gerrit 3.2.3版本,完成Gerrit与前置反向代理Apache2的全量配置后,出现Gerrit服务启动失败问题。

核心配置内容

Gerrit站点配置(gerrit.config)

[gerrit]
        basePath = git
        canonicalWebUrl = http://10.20.30.40:8444/
        serverId = ed568797-ae0c-4e44-a5ac-4a419df2349e
[container]
        javaOptions = "-Dflogger.backend_factory=com.google.common.flogger.backend.log4j.Log4jBackendFactory#getInstance"
        javaOptions = "-Dflogger.logging_context=com.google.gerrit.server.logging.LoggingContext#getInstance"
        user = gerrit
        javaHome = /usr/lib/jvm/java-8-openjdk-amd64/jre
[index]
        type = lucene
[auth]
        type = HTTP
[receive]
        enableSignedPush = false
[sendemail]
        smtpServer = mail.example.com
        smtpServerPort = 587
        smtpEncryption = TLS
        smtpUser = whoami
[sshd]
        listenAddress = *:29418
[httpd]
        listenUrl = http://*:8081/
[cache]
        directory = cache

Apache2站点配置(/etc/apache2/sites-enabled/000-default.conf)

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>
Listen 8444
<VirtualHost *:8444>
  ServerName 10.20.30.40
  ProxyRequests Off
  ProxyVia Off
  ProxyPreserveHost On

  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>
  <Location "/">
      AuthType Digest
      AuthName "realm"
      AuthDigestDomain /
      AuthDigestProvider file
      AuthUserFile /var/www/html/htpasswd

      # These 3 lines below for basic authentication:
      # AuthGroupFile /dev/null
      # AuthBasicProvider file
      # AuthUserFile '/home/stl/passwords'
      Require valid-user
  </Location>
  AllowEncodedSlashes On
  ProxyPass / http://10.20.30.40:8081/
</VirtualHost>

#vim: syntax=apache ts=4 sw=4 sts=4 sr noet
#vim: syntax=apache ts=4 sw=4 sts=4 sr noet

故障表现

  • Apache2服务可通过sudo service apache2 start命令正常启动,无任何配置报错
  • 执行gerrit_site/bin/gerrit.sh start命令启动Gerrit时,运行日志显示内置Jetty服务尝试绑定0.0.0.0:8081端口时触发BindException异常,提示Address already in use,最终导致HTTP守护进程无法正常拉起

根因定位与解决

  • 故障初期没法快速定位端口冲突的来源,逐文件核对Apache全量配置时发现,除了当前站点配置中书写的Listen 8444外,还在Apache全局配置文件ports.conf中冗余添加了同个端口的监听配置
  • 双处同端口监听配置叠加,触发了Apache进程的端口绑定逻辑异常,间接占用了Gerrit配置的8081端口资源
  • 移除ports.conf中冗余的Listen 8444配置项后,依次重启Apache与Gerrit服务,Gerrit即可正常对外提供服务

内容的提问来源于stack exchange,提问作者SSB

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.25 16:06:05