docker创建sonar容器后,使用docker ps -a 检查发现sonar容器自动退出问题解决方法

文章讲述了用户在运行SonarQube7.9容器时遇到退出问题,原因在于宿主机的vm.max_map_count值过低。通过调整此参数并重启容器,解决了临时问题。后续需将设置永久化,以确保容器长期稳定运行。
摘要由CSDN通过智能技术生成

问题:

docker run -d --name sonarqube7.9 -p 9000:9000 --link postgres10 -e SONARQUBE_JDBC_URL=jdbc:postgresql://postgres10:5432/sonar -e SONARQUBE_JDBC_USERNAME=sonar -e SONARQUBE_JDBC_PASSWORD=123456 -v sonarqube_conf:/opt/sonarqube/conf -v sonarqube_extensions:/opt/sonarqube/extensions -v sonarqube_logs:/opt/sonarqube/logs -v sonarqube_data:/opt/sonarqube/data sonarqube

使用上面命令创建sonarqube7.9 容器后,使用docker ps -a 检查:
发现容器会exited,多次使用重启docker restart sonarqube7.9 依旧如此。

[root@master1 ~]# docker ps -a| grep sonar
c71794d64bdf  sonarqube  "/opt/sonarqube/bin/…"  4 minutes ago   Exited (0) 27 seconds ago                                                    sonarqube7.9

排查原因:

使用docker logs sonarqube7.9 命令查看该容器日志:

看到倒数第9行有关键报错:

bootstrap check failure [1] of [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[root@xianchaomaster1 ~]# docker logs sonarqube7.9
Dropping Privileges
2024.02.02 06:27:35 INFO  app[][o.s.a.AppFileSystem] Cleaning or creating temp directory /opt/sonarqube/temp
2024.02.02 06:27:35 INFO  app[][o.s.a.es.EsSettings] Elasticsearch listening on [HTTP: 127.0.0.1:9001, TCP: 127.0.0.1:44222]
2024.02.02 06:27:36 INFO  app[][o.s.a.ProcessLauncherImpl] Launch process[[key='es', ipcIndex=1, logFilenamePrefix=es]] from [/opt/sonarqube/elasticsearch]: /opt/sonarqube/elasticsearch/bin/elasticsearch
2024.02.02 06:27:36 INFO  app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
2024.02.02 06:27:37 INFO  es[][o.e.n.Node] version[7.16.2], pid[38], build[default/tar/2b937c44140b6559905130a8650c64dbd0879cfb/2021-12-18T19:42:46.604893745Z], OS[Linux/3.10.0-1160.71.1.el7.x86_64/amd64], JVM[Alpine/OpenJDK 64-Bit Server VM/11.0.12/11.0.12+7-alpine-r0]
2024.02.02 06:27:37 INFO  es[][o.e.n.Node] JVM home [/usr/lib/jvm/java-11-openjdk]
2024.02.02 06:27:37 INFO  es[][o.e.n.Node] JVM arguments [-XX:+UseG1GC, -Djava.io.tmpdir=/opt/sonarqube/temp, -XX:ErrorFile=../logs/es_hs_err_pid%p.log, -Des.networkaddress.cache.ttl=60, -Des.networkaddress.cache.negative.ttl=10, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -Djna.tmpdir=/opt/sonarqube/temp, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dio.netty.allocator.numDirectArenas=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Dlog4j2.formatMsgNoLookups=true, -Djava.locale.providers=COMPAT, -Dcom.redhat.fips=false, -Des.enforce.bootstrap.checks=true, -Xmx512m, -Xms512m, -XX:MaxDirectMemorySize=256m, -XX:+HeapDumpOnOutOfMemoryError, -Des.path.home=/opt/sonarqube/elasticsearch, -Des.path.conf=/opt/sonarqube/temp/conf/es, -Des.distribution.flavor=default, -Des.distribution.type=tar, -Des.bundled_jdk=false]
2024.02.02 06:27:37 INFO  es[][o.e.p.PluginsService] loaded module [analysis-common]
2024.02.02 06:27:37 INFO  es[][o.e.p.PluginsService] loaded module [lang-painless]
2024.02.02 06:27:37 INFO  es[][o.e.p.PluginsService] loaded module [parent-join]
2024.02.02 06:27:37 INFO  es[][o.e.p.PluginsService] loaded module [transport-netty4]
2024.02.02 06:27:37 INFO  es[][o.e.p.PluginsService] no plugins loaded
2024.02.02 06:27:37 INFO  es[][o.e.e.NodeEnvironment] using [1] data paths, mounts [[/opt/sonarqube/data (/dev/mapper/centos-root)]], net usable_space [34.5gb], net total_space [43.9gb], types [xfs]
2024.02.02 06:27:37 INFO  es[][o.e.e.NodeEnvironment] heap size [512mb], compressed ordinary object pointers [true]
2024.02.02 06:27:37 INFO  es[][o.e.n.Node] node name [sonarqube], node ID [KmZ3oFtJT9mJ943bXkiaTg], cluster name [sonarqube], roles [data_frozen, master, remote_cluster_client, data, data_content, data_hot, data_warm, data_cold, ingest]
2024.02.02 06:27:39 INFO  es[][o.e.t.NettyAllocator] creating NettyAllocator with the following configs: [name=unpooled, suggested_max_allocation_size=256kb, factors={es.unsafe.use_unpooled_allocator=null, g1gc_enabled=true, g1gc_region_size=1mb, heap_size=512mb}]
2024.02.02 06:27:39 INFO  es[][o.e.d.DiscoveryModule] using discovery type [zen] and seed hosts providers [settings]
2024.02.02 06:27:40 INFO  es[][o.e.g.DanglingIndicesState] gateway.auto_import_dangling_indices is disabled, dangling indices will not be automatically detected or imported and must be managed manually
2024.02.02 06:27:40 INFO  es[][o.e.n.Node] initialized
2024.02.02 06:27:40 INFO  es[][o.e.n.Node] starting ...
2024.02.02 06:27:40 INFO  es[][o.e.t.TransportService] publish_address {127.0.0.1:44222}, bound_addresses {127.0.0.1:44222}
2024.02.02 06:27:40 INFO  es[][o.e.b.BootstrapChecks] explicitly enforcing bootstrap checks

ERROR: [1] bootstrap checks failed. You must address the points described in the following [1] lines before starting Elasticsearch.
bootstrap check failure [1] of [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
ERROR: Elasticsearch did not exit normally - check the logs at /opt/sonarqube/logs/sonarqube.log
2024.02.02 06:27:40 INFO  es[][o.e.n.Node] stopping ...
2024.02.02 06:27:40 INFO  es[][o.e.n.Node] stopped
2024.02.02 06:27:40 INFO  es[][o.e.n.Node] closing ...
2024.02.02 06:27:40 INFO  es[][o.e.n.Node] closed
2024.02.02 06:27:40 WARN  app[][o.s.a.p.AbstractManagedProcess] Process exited with exit value [es]: 78
2024.02.02 06:27:40 INFO  app[][o.s.a.SchedulerImpl] Process[es] is stopped
2024.02.02 06:27:40 INFO  app[][o.s.a.SchedulerImpl] SonarQube is stopped

解决方法:

该报错意为宿主机的 vm.max_map_count 内核参数数值过小,最少需要262144。

在宿主机执行 sysctl -w vm.max_map_count=262144(临时生效) 调大数值后,

重启容器 docker start sonarqube7.9

经检查容器一段时间后依旧运行正常

[root@master1 ~]# docker ps | grep sonar
1119020ffe7a   sonarqube   "/opt/sonarqube/bin/…"   14 minutes ago      Up 8 minutes       0.0.0.0:9000->9000/tcp, :::9000->9000/tcp   sonarqube7.9

接下来需要把vm.max_map_count数值调为永久生效,
vim /etc/sysctl.conf
加入一行
vm.max_map_count=262144
保存即可,下次重启会自动生效

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值