Caused by: java.lang.RuntimeException: can not run elasticsearch as root
錯誤緣由:由於安全問題elasticsearch 不讓用root用戶直接運行java
解決方法:liunx建立新用戶sonarUser,使用該用戶(sonarUser)運行sonar便可。bootstrap
步驟:安全
一、建立用戶app
[root@iZbp1bb2egi7w0ueys548qZ logs]# adduser sonarUser
二、設置密碼,輸入兩次密碼elasticsearch
[root@iZbp1bb2egi7w0ueys548qZ logs]# passwd sonarUser
三、進入到sonarqube-6.7.6目錄的上一級更改sonarqube目錄的用戶組爲sonarUseride
[root@bogon local]# chown -R sonarUser:sonarUser sonarqube-6.7.6
四、從新啓動sonar,要使用新建的用戶啓動this
su sonarUser ./sonar.sh restart
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端口占用了spa
解決:修改sonar.properties文件的ES端口,或者Jenkins端口修改成8082.net
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
解決:修改目錄權限rest
chmod 777 /usr/local/jdk1.8.0_191/jre/bin/java
再次啓動,沒有報錯,訪問一下
緣由:最新版本的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
查看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