1、启动时日志中提示
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
错误原因:因为安全问题elasticsearch 不让用root用户直接运行
解决方法:liunx创建新用户sonarUser,使用该用户(sonarUser)运行sonar即可。
步骤:
1、创建用户
[root@iZbp1bb2egi7w0ueys548qZ logs]# adduser sonarUser
2、设置密码,输入两次密码
[root@iZbp1bb2egi7w0ueys548qZ logs]# passwd sonarUser
3、进入到sonarqube-6.7.6目录的上一级更改sonarqube目录的用户组为sonarUser
[root@bogon local]# chown -R sonarUser:sonarUser sonarqube-6.7.6
4、重新启动sonar,要使用新建的用户启动
su sonarUser ./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端口,但是Jenkins把9001端口占用了
解决:修改sonar.properties文件的ES端口,或者Jenkins端口修改为8082
3、修改完上面的问题后启动提示:没有权限
Caused by: java.io.IOException: Cannot run program "/usr/local/jdk1.8.0_191/jre/bin/java" (in directory "/usr/local/sonarqube-6.7.6"): error=13, Permission denied
解决:修改目录权限
chmod 777 /usr/local/jdk1.8.0_191/jre/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/** sonar.java.source=1.8 sonar.java.target=1.8 # 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、运行一段时间后服务挂掉
查看sonar.log日志
[root@bogon logs]# tail -f sonar.log at org.sonar.application.AppFileSystem.reset(AppFileSystem.java:62) at org.sonar.application.App.start(App.java:55) at org.sonar.application.App.main(App.java:78) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.tanukisoftware.wrapper.WrapperSimpleApp.run(WrapperSimpleApp.java:240) at java.lang.Thread.run(Thread.java:748) <-- Wrapper Stopped --> Wrapper Started as Daemon Launching a JVM... Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved. 2019.05.13 10:57:59 INFO app[][o.s.a.AppFileSystem] Cleaning or creating temp directory /usr/local/sonarqube-7.4/temp WrapperSimpleApp: Encountered an error running main: java.nio.file.AccessDeniedException: /usr/local/sonarqube-7.4/temp/conf/es/elasticsearch.yml java.nio.file.AccessDeniedException: /usr/local/sonarqube-7.4/temp/conf/es/elasticsearch.yml
提示这个文件访问没有权限:java.nio.file.AccessDeniedException: /usr/local/sonarqube-7.4/temp/conf/es/elasticsearch.yml
原来是之前可能不小心用root启动过会创建temp目录,该目录为root用户所有,当使用自己创建的sonarUser用户启动时就会报错,
解决:
修改此目录的所属用户组
chown -R sonarUser:sonarUser /usr/local/sonarqube-7.4/temp