使用非嵌入式数据库时,SonarQube 无法 运行 和 Ubuntu。 (弹性搜索启动失败)

SonarQube not able to run with Ubuntu when using non embedded database. (elastic search failed to start)

我试图在我的 Ubuntu 机器 运行 Ubuntu 18.04 (JDK 11) 中设置 SonarQube 8 和 8.1。 我面临一个很可能与 ElasticSearch 有关的特定问题。每当我尝试使用 sonar.sh 启动命令启动 SonarQube 时,它​​都会失败,并在 es.log 和 sonar.log

中出现以下错误
ERROR: [1] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]

在此处发布之前,我尝试了多种方法,但其中 none 帮助我解决了这个问题。我尝试过的东西如下。

  1. 尝试在 /etc/security/limits.conf

    中设置值
    user  -  nofile  65535
    
  2. 尝试在 /etc/sysctl.conf

    中设置值
    vm.max_map_count=262144
    fs.file-max=65536
    

即使更改了这些系统文件后,我也无法启动 SonarQube,每次都会出现上述相同的错误。

请注意:

只有当我尝试将 SonarQube 与外部数据库一起使用时才会发生这种情况,它与嵌入式 H2 数据库完全可以正常工作,但是每当我启用任何外部数据库(尝试过 MSSQL 和 Postgres)时,我都会遇到同样的问题。

经过大量搜索后,我终于发现在 Ubuntu 中,您需要在 /etc/systemd/system.conf/etc/systemd/user.conf 中添加以下行以更改默认打开文件限制。

要添加的行

DefaultLimitNOFILE=65536