sonarqube 版本 9.9/10.3 和 elastisreach 在 Ubuntu 22 上使用 postgresql 12.6 - elastic search 退出退出值 [ElasticSearch]: 78

问题描述 投票:0回答:1

我在 ubuntu linux (ubuntu 20) 上安装了 SonarQube

目前我使用的是SonarQube版本9.9.3 (之前我安装了 SonarQube 10.3.0.82913 也遇到了同样的问题,所以我退回了一个版本并安装了 9.9.3.79811)

返回9.9.3后问题仍然存在

我正在使用 openjdk 17.0.8.1 2023-08-24 和 PostgreSQL 12.16 (Ubuntu 12.16-0ubuntu0.20.04.1)

我遵循的步骤如下

  1. 搭建了一个 Ubuntu linux 版本 20.2 服务器并创建了一个名为“sonaruser”的 Linux 用户

  2. 使用apt安装了openjdk 17.0.8.1 2023-08-24

  3. 使用apt安装了PostgreSQL 12.16

  4. 下载 SONAR zip 文件 sonarqube-9.9.3.79811 并将其解压缩到路径 /opt/sonarqube-9.9.3.79811

  5. 将 /opt/sonarqube-9.9.3.79811 及其所有子内容的所有权更改为“sonaruser”

  6. 通过 PSQL 数据库超级用户运行一组以下数据库命令

    CREATE DATABASE sonardb;
    CREATE USER sonaruser with password 'sonarpass';
    ALTER USER sonaruser SET search_path to sonarschema;
    GRANT ALL PRIVILEGES  ON DATABASE sonardb TO sonaruser```
    
    
  7. 以linux用户sonaruser登录linux,然后以sonaruser登录postgres;之后运行以下命令

    USE sonardb; CREATE SCHEMA IF NOT EXISTS sonarschema;

  8. 更改文件 opt/sonarqube-9.9.3.79811/conf/sonar.properties 中的配置如下

    sonar.jdbc.username=sonaruser
    sonar.jdbc.password=sonarpass
    sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonardb? 
    currentSchema=sonarschema
    sonar.web.host=0.0.0.0
    sonar.web.context=/sonarqube
    sonar.web.port=9000 ```
    
    
  9. 完成上述所有操作后,我通过运行命令启动 sonarqube

    /opt/sonarqube/bin/linux-x86-64/sonar.sh

然而,这始终在日志中给出错误,如下

```[o.a.h.i.n.c.MainClientExec] [exchange: 1] start execution
2023.11.22 13:56:20 DEBUG app[][o.a.h.c.p.RequestAddCookies] CookieSpec 
selected: default
2023.11.22 13:56:20 DEBUG app[][o.a.h.c.p.RequestAuthCache] Re-using 
cached 'basic' auth scheme for http://127.0.0.1:9001
2023.11.22 13:56:20 DEBUG app[][o.a.h.c.p.RequestAuthCache] No 
credentials for preemptive authentication
2023.11.22 13:56:20 DEBUG app[][o.a.h.i.n.c.InternalHttpAsyncClient] 
[exchange: 1] Request connection for {}->http://127.0.0.1:9001
2023.11.22 13:56:20 DEBUG app[] 
[o.a.h.i.n.c.PoolingNHttpClientConnectionManager] Connection request: 
[route: {}->http://127.0.0.1:9001][total kept alive: 0; route 
allocated: 0 of 10; total allocated: 0 of 30]
2023.11.22 13:56:20 DEBUG app[] 
[o.a.h.i.n.c.PoolingNHttpClientConnectionManager] Connection request 
failed
java.net.ConnectException: Connection refused
at java.base/sun.nio.ch.Net.pollConnect(Native Method)
at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)
at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:946)
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvent(DefaultConnectingIOReactor.java:174)
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:148)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:351)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:221)
at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64)
at java.base/java.lang.Thread.run(Thread.java:833)
...
2023.11.22 13:56:20 DEBUG app[][o.e.c.RestClient] added [[host=http://127.0.0.1:9001]] to blacklist
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvent(DefaultConnectingIOReactor.java:174)
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:148)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:351)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:221)
at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64)
at java.base/java.lang.Thread.run(Thread.java:833)
...
2023.11.22 13:56:20 DEBUG app[][o.e.c.RestClient] added 
[[host=http://127.0.0.1:9001]] to blacklist 
...
...
2023.12.01 10:34:36 DEBUG app[][o.e.c.RestClient] updated 
[[host=http://127.0.0.1:9001]] already in blacklist
2023.12.01 10:34:36 WARN  app[][o.s.a.p.AbstractManagedProcess] 
Process exited with exit value [ElasticSearch]: 78```

有趣的部分是,当我删除 JDBC 配置并 让 SONARQUBE 从嵌入式数据库启动,然后这些错误就会消失,SONARQUBE 启动正常

我确实确定在 sonarqube 启动之前使用的 9000 或 9001 端口没有问题 我还确保防火墙已关闭

我确实使用 netcat 和 telnet 检查了端口 9000 和端口 9001 是否空闲,服务器可以侦听它们并且本地主机上的客户端可以连接

我也更改了日志级别以调试Elasticsearch。我在 /opt/sonarqube/log/nohup.log 中看到如下所示 - 这表示 Elasticsearch 能够成功绑定到端口 9001 并且 Sonarqube 也连接到它。但是在同一个日志中 - 一段时间后它显示“连接请求失败”

enter code here
2023.12.01 09:16:34 DEBUG app[][o.s.a.NodeLifecycle] main 
tryToMoveTo from INIT to STARTING => true
2023.12.01 09:16:34 DEBUG app[][o.s.a.p.ManagedProcessLifecycle] 
main tryToMoveTo ElasticSearch from INIT to STARTING => true
2023.12.01 09:16:34 INFO  app[][o.s.a.es.EsSettings] Elasticsearch 
listening on [HTTP: 127.0.0.1:9001, TCP: 127.0.0.1:38141]
2023.12.01 09:16:34 INFO  app[][o.s.a.ProcessLauncherImpl] Launch 
process[ELASTICSEARCH] from [/opt/sonarqube- 
9.9.3.79811/elasticsearch]: /opt/sonarqube- 
9.9.3.79811/elasticsearch/bin/elasticsearch
2023.12.01 09:16:34 DEBUG app[][o.s.a.p.ManagedProcessLifecycle] 
main tryToMoveTo ElasticSearch from STARTING to STARTED => true
2023.12.01 09:16:34 INFO  app[][o.s.a.SchedulerImpl] Waiting for 
Elasticsearch to be up and running
2023.12.01 09:16:34 DEBUG app[][o.s.a.e.EsConnectorImpl] Connected 
to Elasticsearch node: [127.0.0.1:9001]
.... 
....
....
2023.12.01 09:16:34 DEBUG app[][o.a.h.i.n.c.MainClientExec] 
[exchange: 1] start execution
2023.12.01 09:16:34 DEBUG app[][o.a.h.c.p.RequestAddCookies] 
CookieSpec selected: default
2023.12.01 09:16:34 DEBUG app[][o.a.h.c.p.RequestAuthCache] Re- 
using cached 'basic' auth scheme for http://127.0.0.1:9001
2023.12.01 09:16:34 DEBUG app[][o.a.h.c.p.RequestAuthCache] No 
credentials for preemptive authentication
2023.12.01 09:16:34 DEBUG app[] 
[o.a.h.i.n.c.InternalHttpAsyncClient] [exchange: 1] Request 
connection for {}->http://127.0.0.1:9001
2023.12.01 09:16:34 DEBUG app[] 
[o.a.h.i.n.c.PoolingNHttpClientConnectionManager] Connection 
request: [route: {}->http://127.0.0.1:9001][total kept alive: 0; 
route allocated: 0 of 10; total allocated: 0 of 30]
2023.12.01 09:16:34 DEBUG app[] 
[o.a.h.i.n.c.PoolingNHttpClientConnectionManager] Connection 
request failed
java.net.ConnectException: Connection refused
    at java.base/sun.nio.ch.Net.pollConnect(Native Method)
    at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)
....

[o.a.h.i.n.c.InternalHttpAsyncClient] [exchange: 1] connection request failed
2023.12.01 09:16:34 DEBUG app[][o.e.c.RestClient] request [GET http://127.0.0.1:9001/] failed
java.net.ConnectException: Connection refused
        at java.base/sun.nio.ch.Net.pollConnect(Native Method)
        at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)
        at 

最后这会导致与之前引用的相同的连接错误

IMO 问题是因为弹性搜索启动然后退出

我做错了什么,Sonarqube 没有在 postgresql JDBC 配置完成后启动?

衷心感谢您的指点/意见

尤格什

postgresql elasticsearch sonarqube
1个回答
0
投票

正如怀疑的那样,核心问题是由于elasticsearch正在退出 我提到了这个https://github.com/SonarSource/docker-sonarqube/issues/282 还有到 https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html

我设置了以下内容和 Elasticsearch,因此 sonarqube 开始工作

 "sysctl -w vm.max_map_count=262144"

要永久设置此值,请更新 /etc/sysctl.conf 中的 vm.max_map_count 设置。

要在重新启动后进行验证,请运行 sysctl vm.max_map_count。

© www.soinside.com 2019 - 2024. All rights reserved.