1、启动时日志中提示
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
错误原因:因为安全问题elasticsearch 不让用root用户直接运行
解决方法:liunx创建新用户sonar,使用该用户(sonar)运行sonar即可。
步骤:
1、创建用户
[root@localhost ~]# adduser sonar
2、设置密码,输入两次密码
[root@localhost ~]# passwd sonar
3、进入到sonarqube目录的上一级更改sonarqube-XXX目录的用户组为sonar
[root@localhost opt]# chown -R sonar:sonar sonarqube-XXX
4、重新启动sonar,要使用新建的用户启动
su sonar
./sonar.sh restart
2、启动时提示端口占用
org.elasticsearch.bootstrap.StartupException: BindTransportException[Failed to bind to [9001]]; nested: BindException[Address already in use];
Caused by: java.net.BindException: Address already in use
原因:sonarqube需要使用9000端口,elasticsearch使用的是9001端口,但是其他程序把9001端口占用了
解决:修改sonar.properties文件的ES端口,或者将其他占用该端口的程序的端口修改为8082
3、修改完上面的问题后启动提示:没有权限
Caused by: java.io.IOException: Cannot run program "/usr/lib/jvm/java-11-openjdk-11.0.8.10-0.el7_8.x86_64/bin/java" (in directory "/opt/sonarqube-XXX"): error=13, Permission denied
解决:修改目录权限
chmod 777 /usr/lib/jvm/java-11-openjdk-11.0.8.10-0.el7_8.x86_64/bin/java
再次启动,没有报错
4、报错:ERROR: Please provide compiled classes of your project with sonar.java.binaries property
原因:最新版本的sonarQube6.5以上的版本只能扫描class文件
解决:新版本的需要在项目根目录下的sonar-project.properties文件新增属性sonar.java.binaries
指定class编译路径
# must be unique in a given SonarQube instance
sonar.projectKey=cynomys:0.0.1
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=cynomys
sonar.projectVersion=0.0.1
# Path is relative to the sonar-project.properties file. Replace "" by "/" on Windows.
# This property is optional if sonar.modules is set.
sonar.sources=.
sonar.exclusions=**/test/**,**/target/**
# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
sonar.java.binaries=/root/.jenkins/workspace/e-content/e-content-controller/target/classes
5、运行一段时间后服务挂掉或者启动不起来
wrapper | --> Wrapper Started as Console
wrapper | Launching a JVM...
jvm 1 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
jvm 1 | Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved.
jvm 1 |
jvm 1 | 2020.09.14 23:51:49 INFO app[][o.s.a.AppFileSystem] Cleaning or creating temp directory /opt/sonarqube-8.4.2.36762/temp
jvm 1 | 2020.09.14 23:51:49 INFO app[][o.s.a.es.EsSettings] Elasticsearch listening on /127.0.0.1:9001
jvm 1 | 2020.09.14 23:51:49 ERROR app[][o.s.a.p.ManagedProcessHandler] Fail to launch process [es]
jvm 1 | java.lang.IllegalStateException: Cannot write Elasticsearch yml settings file
jvm 1 | at org.sonar.application.es.EsYmlSettings.writeToYmlSettingsFile(EsYmlSettings.java:53)
jvm 1 | at org.sonar.application.ProcessLauncherImpl.writeConfFiles(ProcessLauncherImpl.java:151)
jvm 1 | at org.sonar.application.ProcessLauncherImpl.launch(ProcessLauncherImpl.java:84)
jvm 1 | at org.sonar.application.SchedulerImpl.lambda$tryToStartProcess$2(SchedulerImpl.java:196)
jvm 1 | at org.sonar.application.process.ManagedProcessHandler.start(ManagedProcessHandler.java:73)
jvm 1 | at org.sonar.application.SchedulerImpl.tryToStartProcess(SchedulerImpl.java:194)
jvm 1 | at org.sonar.application.SchedulerImpl.tryToStartEs(SchedulerImpl.java:146)
jvm 1 | at org.sonar.application.SchedulerImpl.tryToStartAll(SchedulerImpl.java:138)
jvm 1 | at org.sonar.application.SchedulerImpl.schedule(SchedulerImpl.java:112)
jvm 1 | at org.sonar.application.App.start(App.java:69)
jvm 1 | at org.sonar.application.App.main(App.java:98)
jvm 1 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
jvm 1 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
jvm 1 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
jvm 1 | at java.base/java.lang.reflect.Method.invoke(Method.java:566)
jvm 1 | at org.tanukisoftware.wrapper.WrapperSimpleApp.run(WrapperSimpleApp.java:240)
jvm 1 | at java.base/java.lang.Thread.run(Thread.java:834)
jvm 1 | Caused by: java.nio.file.AccessDeniedException: /opt/sonarqube-8.4.2.36762/temp/conf/es/elasticsearch.yml
jvm 1 | at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)
jvm 1 | at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
提示这个文件访问没有权限:Caused by: java.nio.file.AccessDeniedException: /opt/sonarqube-8.4.2.36762/temp/conf/es/elasticsearch.yml
原来是之前可能不小心用root启动过会创建temp目录,该目录为root用户所有,当使用自己创建的sonar用户启动时就会报错,
解决:
修改此目录的所属用户组(我一般就让整个sonarqube-8.4.2.36762文件夹都具有权限,这句命令要用root用户执行,再切换到sonar用户启动sonar就可以啦)
chown -R sonar:sonar /opt/sonarqube-8.4.2.36762/temp
6、启动失败,es只读
排查web.log日志,发现ES写索引异常,报错ClusterBlockException[blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];
es进入“只读”模式,只允许删除。
ES说明文档中有写明,当ES数据所在目录磁盘空间使用率超过90%后,ES将修改为只读状态,不允许写入
解决:查看自己电脑上sonarqube所在目录的磁盘空间,发现果然已经超过90%了,清理磁盘空间后再进行分析,结果就显示的成功