Jenkins (四) - 搭建 Docker SonarQube

Jenkins (四) - 搭建 Docker SonarQube

拉取 SonarQube

$ docker pull sonarqube

拉取 postgres

$ $ docker pull postgres

运行 postgres

$ docker run -itd \
-e TZ=Asia/Shanghai
-e POSTGRES_USER=tester \
-e POSTGRES_PASSWORD=123456 \
-p 5432:5432 \
-v /home/tester/data/docker/postgresql/data:/var/lib/postgresql/data \
--name postgres postgres

运行 SonarQube

SonarQube 默认使用h2数据库,通过配置 SONAR_JDBC_URL, SONAR_JDBC_PASSWORD, SONAR_JDBC_USERNAME 替换为postgres.

$ docker run -d \
--name sonarqube \
-e TZ=Asia/Shanghai \
-e SONAR_JDBC_USERNAME=tester \
-e SONAR_JDBC_PASSWORD=123456 \
-e SONAR_JDBC_URL=jdbc:postgresql://192.168.56.102:5432/sonarqube \
-v /home/tester/data/docker/sonarqube/extensions:/opt/sonarqube/extensions \
-v /home/tester/data/docker/sonarqube/logs:/opt/sonarqube/logs \
-v /home/tester/data/docker/sonarqube/data:/opt/sonarqube/data \
-v /home/tester/data/docker/sonarqube/conf:/opt/sonarqube/conf \
-p 9000:9000 \
--name sonarqube sonarqube

查看sonarqube是否已运行成功

$ docker ps 

启动可能会出错,出错查看文末 启动失败

验证postgres连接

在这里插入图片描述

登入SonarQube

http://192.168.56.102:9000
默认账号密码: admin/admin
在这里插入图片描述
更改密码为 123456
在这里插入图片描述

启动失败

第一次启动一般都会失败,可以通过查看web.log, es.log分析原因。

$ cd /home/tester/data/docker/sonarqube/logs
$ ls -l

web.log

2024.04.04 01:21:42 INFO  app[][o.s.a.es.EsSettings] Elasticsearch listening on [HTTP: 127.0.0.1:9001, TCP: 127.0.0.1:37975]
2024.04.04 01:21:42 INFO  app[][o.s.a.ProcessLauncherImpl] Launch process[ELASTICSEARCH] from [/opt/sonarqube/elasticsearch]: /opt/java/openjdk/bin/java -Xms4m -Xmx64m -XX:+UseSerialGC -Dcli.name=server -Dcli.script=./bin/elasticsearch -Dcli.libs=lib/tools/server-cli -Des.path.home=/opt/sonarqube/elasticsearch -Des.path.conf=/opt/sonarqube/temp/conf/es -Des.distribution.type=tar -cp /opt/sonarqube/elasticsearch/lib/*:/opt/sonarqube/elasticsearch/lib/cli-launcher/* org.elasticsearch.launcher.CliToolLauncher
2024.04.04 01:21:42 INFO  app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
2024.04.04 01:21:50 WARN  app[][o.s.a.p.AbstractManagedProcess] Process exited with exit value [ElasticSearch]: 78
2024.04.04 01:21:50 INFO  app[][o.s.a.SchedulerImpl] Process[ElasticSearch] is stopped
2024.04.04 01:21:50 INFO  app[][o.s.a.SchedulerImpl] SonarQube is stopped

如果遇到es启动失败,多半是由于vm.max_map_count 过小。记得查看es.log,通常es.log会有对应的错误提示。

es.log

2024.04.04 01:21:50 INFO  es[][o.e.t.TransportService] publish_address {127.0.0.1:37975}, bound_addresses {127.0.0.1:37975}
2024.04.04 01:21:50 INFO  es[][o.e.b.BootstrapChecks] explicitly enforcing bootstrap checks
2024.04.04 01:21:50 ERROR es[][o.e.b.Elasticsearch] node validation exception
[1] bootstrap checks failed. You must address the points described in the following [1] lines before starting Elasticsearch. For more information see [https://www.elastic.co/guide/en/elasticsearch/reference/8.11/bootstrap-checks.html]
bootstrap check failure [1] of [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]; for more information see [https://www.elastic.co/guide/en/elasticsearch/reference/8.11/_maximum_map_count_check.html]
2024.04.04 01:21:50 WARN  es[][o.e.n.Node] unexpected exception while waiting for http server to close
java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Can't move to stopped state when not started
	at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:?]
	at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:?]
	at org.elasticsearch.node.Node.prepareForClose(Node.java:1776) ~[elasticsearch-8.11.0.jar:?]
	at org.elasticsearch.bootstrap.Elasticsearch.shutdown(Elasticsearch.java:468) ~[elasticsearch-8.11.0.jar:?]
	at java.lang.Thread.run(Unknown Source) ~[?:?]
Caused by: java.lang.IllegalStateException: Can't move to stopped state when not started
	at org.elasticsearch.common.component.Lifecycle.canMoveToStopped(Lifecycle.java:128) ~[elasticsearch-8.11.0.jar:?]
	at org.elasticsearch.common.component.AbstractLifecycleComponent.stop(AbstractLifecycleComponent.java:73) ~[elasticsearch-8.11.0.jar:?]
	at org.elasticsearch.node.Node.lambda$prepareForClose$59(Node.java:1768) ~[elasticsearch-8.11.0.jar:?]
	at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:?]

解决方案

  • 临时修改
# 查看vm.max_map_count
$ sudo sysctl -a | grep vm.max_map_count
vm.max_map_count = 65530
# 更新vm.max_map_count
$ sudo sysctl -w vm.max_map_count=262144
vm.max_map_count = 262144
  • 永久修改
$ vim /etc/sysctl.conf

Reference: 来自官方说明

Continuing from the previous point, to use mmap effectively, Elasticsearch also requires the ability to create many memory-mapped areas. The maximum map count check checks that the kernel allows a process to have at least 262,144 memory-mapped areas and is enforced on Linux only. To pass the maximum map count check, you must configure vm.max_map_count via sysctl to be at least 262144.

相关推荐

  1. cloudfoundryjenkins

    2024-04-07 11:44:02       20 阅读
  2. jenkins

    2024-04-07 11:44:02       13 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-07 11:44:02       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-07 11:44:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-07 11:44:02       20 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-07 11:44:02       20 阅读

热门阅读

  1. 如何使用Arduino IDE对STM32F103C8T6进行编程

    2024-04-07 11:44:02       15 阅读
  2. vue3+elementUiPlus+弹框

    2024-04-07 11:44:02       12 阅读
  3. 每日OJ题_回文串dp④_力扣132. 分割回文串 II

    2024-04-07 11:44:02       16 阅读
  4. https安全锁出现感叹号的原因

    2024-04-07 11:44:02       16 阅读
  5. redis的List详细介绍

    2024-04-07 11:44:02       13 阅读
  6. Ubuntu Desktop - Rename a file or folder

    2024-04-07 11:44:02       14 阅读
  7. 数据库关系数据结构

    2024-04-07 11:44:02       13 阅读