【求助】项目下运行 sonar scanner报错

问题

使用容器部署 sonarqube, cd 项目主目录/sonarqube-scanner,
设置环境变量 SQ_HOST和 SQ_TOKEN后,执行命令:
sonar-scanner -Dsonar.host.url=$SQ_HOST -Dsonar.login=$SQ_TOKEN

###容器部署命令

docker network create sonarqube
# 创建容器数据库实例
docker run -d \
--network sonarqube \
--name sonarqube_postgres \
-e POSTGRES_USER=sonarqube \
-e POSTGRES_PASSWORD=sonarqube \
-e PGDATA=/var/lib/postgresql/data/pgdata \
-v /opt/postgresql_data:/var/lib/postgresql/data \
postgres

#es:
docker run -p 9200:9200 -p 9300:9300 --name elasticsearch \
-e "discovery.type=single-node" \
-e "cluster.name=elasticsearch" \
-v ${PWD}/plugins:/usr/share/elasticsearch/plugins \
-v ${PWD}/data:/usr/share/elasticsearch/data \
-d elasticsearch:7.14.0

#sonarqube容器
docker run -d \
--name sonarqube_liao \
--platform linux/x86_64 \
-p 9000:9000 -p 9092:9092 \
--network sonarqube \
--user $(id -u):$(id -g) \
-e SONARQUBE_JDBC_USERNAME=sonarqube \
-e SONARQUBE_JDBC_PASSWORD=sonarqube \
-e SONARQUBE_JDBC_URL="jdbc:postgresql://sonarqube_postgres/sonarqube" \
-e SONAR_SEARCH_JAVAADDITIONALOPTS="-Xms2g -Xmx2g" \
-e SONAR_SEARCH_JAVAADDITIONALOPTS="-Dbootstrap.system_call_filter=false" \
-e SONAR_WEB_JVM_OPTS="-Xms1g -Xmx1g" \
--ulimit nofile=524288:524288 \
-v ${PWD}/data:/opt/sonarqube/data \
-v ${PWD}/extensions:/opt/sonarqube/extensions \
-v ${PWD}/logs:/opt/sonarqube/logs \
sonarqube

报错信息

ERROR: Error during SonarScanner execution
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.sonarsource.scanner.api.internal.IsolatedClassloader@1bd4fdd-org.sonar.scanner.report.ReportPublisher': Unsatisfied dependency expressed through constructor parameter 7; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.sonarsource.scanner.api.internal.IsolatedClassloader@1bd4fdd-org.sonar.scanner.report.ActiveRulesPublisher': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ActiveRules' defined in org.sonar.scanner.rule.ActiveRulesProvider: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.sonar.api.batch.rule.internal.DefaultActiveRules]: Factory method 'provide' threw exception; nested exception is org.sonarqube.ws.client.HttpException: Error 500 on http://127.0.0.1:9000/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt,updatedAt,deprecatedKeys&activation=true&qprofile=AYWzHD0WB0eOT4lKKfUD&ps=500&p=1 : {"errors":[{"msg":"An error has occurred. Please contact your administrator"}]}

log文件:
启动报错.log (14.8 KB)

###sonarqube 容器的报错信息

2023.01.16 02:29:12 ERROR web[AYW0Obr72v4KqvxzAABJ][o.s.s.w.WebServiceEngine] Fail to process request http://127.0.0.1:9000/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt,updatedAt,deprecatedKeys&activation=true&qprofile=AYWzHD0WB0eOT4lKKfUD&ps=500&p=1
org.sonar.server.es.ElasticsearchException: Fail to execute es requestES search request 'SearchRequest{searchType=QUERY_THEN_FETCH, indices=[rules], indicesOptions=IndicesOptions[ignore_unavailable=false, allow_no_indices=true, expand_wildcards_open=true, expand_wildcards_closed=false, expand_wildcards_hidden=false, allow_aliases_to_multiple_indices=true, forbid_closed_indices=true, ignore_aliases=false, ignore_throttled=true], types=[rule], routing='null', preference='null', requestCache=null, scroll=null, maxConcurrentShardRequests=0, batchedReduceSize=512, preFilterShardSize=null, allowPartialSearchResults=null, localClusterAlias=null, getOrCreateAbsoluteStartMillis=-1, ccsMinimizeRoundtrips=true, enableFieldsEmulation=false, source={"from":0,"size":500,"query":{"bool":{"must":[{"match_all":{"boost":1.0}}],"filter":[{"bool":{"must":[{"bool":{"must":[{"terms":{"indexType":["rule"],"boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}},{"term":{"isExternal":{"value":false,"boost":1.0}}},{"terms":{"lang":["kubernetes"],"boost":1.0}},{"has_child":{"query":{"bool":{"must":[{"term":{"activeRule_ruleProfile":{"value":"AYWzHDyCB0eOT4lKKfT2","boost":1.0}}}],"adjust_pure_negative":true,"boost":1.0}},"type":"activeRule","score_mode":"none","min_children":1,"max_children":2147483647,"ignore_unmapped":false,"boost":1.0}},{"bool":{"must_not":[{"term":{"status":{"value":"REMOVED","boost":1.0}}}],"adjust_pure_negative":true,"boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}},"sort":[{"updatedAt":{"order":"desc"}},{"key.sortable_analyzer":{"order":"asc"}}]}}' on indices '[rules]' on types '[rule]'
	at org.sonar.server.es.EsClient.execute(EsClient.java:313)
	at org.sonar.server.es.EsClient.search(EsClient.java:134)
	at org.sonar.server.rule.index.RuleIndex.search(RuleIndex.java:178)
	at org.sonar.server.rule.ws.SearchAction.doSearch(SearchAction.java:268)
	at org.sonar.server.rule.ws.SearchAction.handle(SearchAction.java:187)
	at org.sonar.server.ws.WebServiceEngine.execute(WebServiceEngine.java:111)
	at org.sonar.server.platform.web.WebServiceFilter.doFilter(WebServiceFilter.java:84)
	at org.sonar.server.platform.web.MasterServletFilter$GodFilterChain.doFilter(MasterServletFilter.java:153)
	at org.sonar.server.platform.web.SonarLintConnectionFilter.doFilter(SonarLintConnectionFilter.java:66)
	at org.sonar.server.platform.web.MasterServletFilter$GodFilterChain.doFilter(MasterServletFilter.java:153)
	at org.sonar.server.platform.web.MasterServletFilter.doFilter(MasterServletFilter.java:116)
	at jdk.internal.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.apache.catalina.security.SecurityUtil.lambda$execute$0(SecurityUtil.java:280)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
	at java.base/javax.security.auth.Subject.doAsPrivileged(Subject.java:584)
	at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:311)
	at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:253)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:187)
	at org.apache.catalina.core.ApplicationFilterChain.lambda$doFilter$0(ApplicationFilterChain.java:145)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:143)
	at org.sonar.server.platform.web.UserSessionFilter.doFilter(UserSessionFilter.java:81)
	at org.sonar.server.platform.web.UserSessionFilter.doFilter(UserSessionFilter.java:68)
	at jdk.internal.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.apache.catalina.security.SecurityUtil.lambda$execute$0(SecurityUtil.java:280)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
	at java.base/javax.security.auth.Subject.doAsPrivileged(Subject.java:584)
	at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:311)
	at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:253)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:187)
	at org.apache.catalina.core.ApplicationFilterChain.lambda$doFilter$0(ApplicationFilterChain.java:145)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:143)
	at org.sonar.server.platform.web.CspFilter.doFilter(CspFilter.java:63)
	at jdk.internal.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.apache.catalina.security.SecurityUtil.lambda$execute$0(SecurityUtil.java:280)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
	at java.base/javax.security.auth.Subject.doAsPrivileged(Subject.java:584)
	at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:311)
	at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:253)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:187)
	at org.apache.catalina.core.ApplicationFilterChain.lambda$doFilter$0(ApplicationFilterChain.java:145)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:143)
	at org.sonar.server.platform.web.CacheControlFilter.doFilter(CacheControlFilter.java:76)
	at jdk.internal.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.apache.catalina.security.SecurityUtil.lambda$execute$0(SecurityUtil.java:280)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
	at java.base/javax.security.auth.Subject.doAsPrivileged(Subject.java:584)
	at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:311)
	at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:253)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:187)
	at org.apache.catalina.core.ApplicationFilterChain.lambda$doFilter$0(ApplicationFilterChain.java:145)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:143)
	at org.sonar.server.platform.web.SecurityServletFilter.doHttpFilter(SecurityServletFilter.java:60)
	at org.sonar.server.platform.web.SecurityServletFilter.doFilter(SecurityServletFilter.java:47)
	at jdk.internal.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.apache.catalina.security.SecurityUtil.lambda$execute$0(SecurityUtil.java:280)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
	at java.base/javax.security.auth.Subject.doAsPrivileged(Subject.java:584)
	at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:311)
	at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:253)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:187)
	at org.apache.catalina.core.ApplicationFilterChain.lambda$doFilter$0(ApplicationFilterChain.java:145)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:143)
	at org.sonar.server.platform.web.RedirectFilter.doFilter(RedirectFilter.java:57)
	at jdk.internal.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.apache.catalina.security.SecurityUtil.lambda$execute$0(SecurityUtil.java:280)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
	at java.base/javax.security.auth.Subject.doAsPrivileged(Subject.java:584)
	at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:311)
	at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:253)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:187)
	at org.apache.catalina.core.ApplicationFilterChain.lambda$doFilter$0(ApplicationFilterChain.java:145)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:143)
	at org.sonar.server.platform.web.RequestIdFilter.doFilter(RequestIdFilter.java:66)
	at jdk.internal.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.apache.catalina.security.SecurityUtil.lambda$execute$0(SecurityUtil.java:280)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
	at java.base/javax.security.auth.Subject.doAsPrivileged(Subject.java:584)
	at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:311)
	at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:253)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:187)
	at org.apache.catalina.core.ApplicationFilterChain.lambda$doFilter$0(ApplicationFilterChain.java:145)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:143)
	at org.sonar.server.platform.web.RootFilter.doFilter(RootFilter.java:65)
	at jdk.internal.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.apache.catalina.security.SecurityUtil.lambda$execute$0(SecurityUtil.java:280)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
	at java.base/javax.security.auth.Subject.doAsPrivileged(Subject.java:584)
	at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:311)
	at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:253)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:187)
	at org.apache.catalina.core.ApplicationFilterChain.lambda$doFilter$0(ApplicationFilterChain.java:145)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:143)
	at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:109)
	at jdk.internal.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.apache.catalina.security.SecurityUtil.lambda$execute$0(SecurityUtil.java:280)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
	at java.base/javax.security.auth.Subject.doAsPrivileged(Subject.java:584)
	at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:311)
	at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:253)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:187)
	at org.apache.catalina.core.ApplicationFilterChain.lambda$doFilter$0(ApplicationFilterChain.java:145)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:143)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:177)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at ch.qos.logback.access.tomcat.LogbackValve.invoke(LogbackValve.java:256)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.sonar.server.app.SecureErrorReportValve.invoke(SecureErrorReportValve.java:38)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:891)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1784)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.elasticsearch.ElasticsearchStatusException: Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]
	at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:178)
	at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:2484)
	at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:2461)
	at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:2184)
	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:2137)
	at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:2105)
	at org.elasticsearch.client.RestHighLevelClient.search(RestHighLevelClient.java:1367)
	at org.sonar.server.es.EsClient.lambda$search$1(EsClient.java:134)
	at org.sonar.server.es.EsClient.execute(EsClient.java:311)
	... 147 common frames omitted
	Suppressed: org.elasticsearch.client.ResponseException: method [POST], host [http://localhost:9001], URI [/rules/rule/_search?typed_keys=true&max_concurrent_shard_requests=5&search_type=query_then_fetch&batched_reduce_size=512], status line [HTTP/1.1 400 Bad Request]
{"error":{"root_cause":[{"type":"query_shard_exception","reason":"[has_child] no join field has been configured","index_uuid":"cFIl478AQ0CtqvK2C0ToEw","index":"rules"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"rules","node":"0R0CngLKRfSPCSdL4DRY9w","reason":{"type":"query_shard_exception","reason":"[has_child] no join field has been configured","index_uuid":"cFIl478AQ0CtqvK2C0ToEw","index":"rules"}}]},"status":400}
		at org.elasticsearch.client.RestClient.convertResponse(RestClient.java:347)
		at org.elasticsearch.client.RestClient.performRequest(RestClient.java:313)
		at org.elasticsearch.client.RestClient.performRequest(RestClient.java:288)
		at org.elasticsearch.client.RestHighLevelClient.performClientRequest(RestHighLevelClient.java:2699)
		at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:2171)
		... 152 common frames omitted

log 文件:
sonarqube.log (165.4 KB)

环境

macos,java11

辛苦老师帮忙看一下,感谢~

容器的 log 里主要信息是这个
Caused by: org.elasticsearch.ElasticsearchStatusException: Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]

这里是官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html#fielddata-disabled-text-fields

将 [type] 字段的 fielddata 设置为 true 试一试

{
  "properties": {
    "type": {
      "type":     "text",
      "fielddata": true
    }
  }
}

发一下你启动容器的机器配置

macOS BigSur 版本 11.2.3

MacBook Pro Retina 处理器 2.2GHZ 四核 Intel Core i7

内存 16GB 1600 MHz DDR3

监视器看看你运行docker和启动sonar以后你那边机器的内存资源怎么样

启动 docker 之前,使用内存 4.23GB,启动 docker 之后使用内存 11.71GB,运行 sonar 之后 使用内存11.98GB。docker desktop-advanced 设置的内存是 6GB

你把docker的内存调大试试看。可能是内存不够

调到了 10GB 和 12GB 分别看了下还是报错。。