一、问题描述
sonarqube以docker-compose方式运行,在jenkins集成sonarqube时,jenkins的任务输出框出现如下了错误:
java.lang.IllegalStateException: Unrecoverable indexation failures: 1 errors among 1 requests
at org.sonar.server.es.IndexingListener$1.onFinish(IndexingListener.java:39)
at org.sonar.server.es.BulkIndexer.stop(BulkIndexer.java:131)
at org.sonar.server.measure.index.ProjectMeasuresIndexer.doIndex(ProjectMeasuresIndexer.java:162)
at org.sonar.server.measure.index.ProjectMeasuresIndexer.indexOnAnalysis(ProjectMeasuresIndexer.java:87)
at org.sonar.ce.task.projectanalysis.step.IndexAnalysisStep.execute(IndexAnalysisStep.java:45)
at org.sonar.ce.task.step.ComputationStepExecutor.executeStep(ComputationStepExecutor.java:81)
at org.sonar.ce.task.step.ComputationStepExecutor.executeSteps(ComputationStepExecutor.java:72)
at org.sonar.ce.task.step.ComputationStepExecutor.execute(ComputationStepExecutor.java:59)
at org.sonar.ce.task.projectanalysis.taskprocessor.ReportTaskProcessor.process(ReportTaskProcessor.java:81)
at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.executeTask(CeWorkerImpl.java:212)
at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.run(CeWorkerImpl.java:194)
at org.sonar.ce.taskprocessor.CeWorkerImpl.findAndProcessTask(CeWorkerImpl.java:160)
at org.sonar.ce.taskprocessor.CeWorkerImpl$TrackRunningState.get(CeWorkerImpl.java:135)
at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:87)
at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:53)
at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:125)
at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:69)
at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:78)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
二、分析
1、找到sonarqube的日志
为了找到sonarqube的日志,可以进入sonarqube对应的docker-compose.yml文件同级目录,然后执行docker-compose logs -f
查看日志,也可以直接通过docker logs -f “容器ID”
来查看对应sonarqube容器的日志输出,可通过docker ps
来查看容器ID。
2、分析日志信息
查看snoarqube的日志后,发现上述问题是由于Elasticsearch error: cluster_block_exception [FORBIDDEN/12/index read-only / allow delete (api)], flood stage disk watermark exceeded
引起,此外还有flood stage disk watermark [95%] exceeded ... all indices on this node will marked read-only
的提示。
基于上述日志信息来查阅资料,得到大致原因是:sonarqube内部引用了Elasticsearch,而Elasticsearch设置了磁盘使用检查,会对磁盘空间进行监控,当磁盘剩余空间达到了 floodstage 阈值,会将所有相关索引强制置为只读。
三、解决
解决方法有以下3种,可依次尝试。
第一种:
1.通过docker exec -it “容器ID” bash
命令,可以进入sonarqube容器的bash命令行窗口,然后cd /opt/sonarqube/data
。
2. 删除es7文件夹。
第二种:
1.新建 elasticsearch.yml文件,文件内容为:
cluster.routing.allocation.disk.watermark.low: 90%
cluster.routing.allocation.disk.watermark.high: 95%
cluster.routing.allocation.disk.watermark.flood_stage: 99%
这里通过上述可以调整elasticsearch对磁盘空间检查。
2、在sonarqube对应的docker-compose.yml中加入对elasticsearch.yml的映射
version: '3.1'
services:
db:
image: postgres
container_name: db
ports:
- 5432:5432
networks:
- sonarnet
environment:
POSTGRES_USER: sonar
POSTGRES_PASSWORD: sonar
sonarqube:
image: sonarqube:8.9.10-community
container_name: sonarqube
depends_on:
- db
ports:
- 9000:9000
networks:
- sonarnet
environment:
- SONAR_JDBC_URL=jdbc:postgresql://db:5432/sonar
- SONAR_JDBC_USERNAME=sonar
- SONAR_JDBC_PASSWORD=sonar
volumes:
- /usr/local/software/sonarquber/elasticsearch.yml:/opt/sonarqube/elasticsearch/config/elasticsearch.yml
networks:
sonarnet:
driver: bridge
上面的/usr/local/software/sonarquber/elasticsearch.yml需要基于自己所建elasticsearch.yml所处目录进行修改。
3、先执行docker-compose down
,然后执行docker-compose up -d
,即可重新部署sonarquber。
第三种:
1、执行df -Th
,查看虚拟机的磁盘使用情况
这里发现系统根目录出现了空间不足的情况,比如:/dev/mapper/centos-root xfs 17G 14G 3.0G 82%
2、对系统根目录进行扩容
- 通过虚拟机软件新加一个物理磁盘,以vurtual box为例,为虚拟机新建一个新大小为80G的磁盘。
ls /dev/sd*
,查看磁盘的编号,发现新建磁盘编号为/dev/sdbpvcreate /dev/sdb
vgs
vgextend centos /dev/sdb
lvextend -L +20G /dev/mapper/centos-root
xfs_growfs /dev/mapper/centos-root
3、通过上述步骤发现已扩容成功
四、参考
- https://stackoverflow.com/questions/50609417/elasticsearch-error-cluster-block-exception-forbidden-12-index-read-only-all?rq=2
- https://stackoverflow.com/questions/74913401/sonarqube-unrecoverable-indexation-failures-1-errors-among-1-requests-check-el
- https://www.jianshu.com/p/e1867d618351
- https://www.cnblogs.com/feiyun126/p/7680534.html