前提:版本信息---> sonarqube-7.0,jdk1.8,mysql5.7
sonar服务器安装好后,由于公司内网限制端口访问,所以在修改sonar.properties,端口由默认9000改为6xxxx
#sonar.web.port=60001
防火墙已关闭,端口60001已开放(首先排查这两点,排查后还是不行往下看)
查看linux信息为64位
# uname -a
Linux localhost.localdomain 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
排查问题看日志顺序:sonar.log-->es.log-->web.log
问题1:sonarqube启动时, log目录下的es.log报错:
java.lang.RuntimeException: can not run elasticsearch as root
解决1:sonarqube不能以root用户运行,需另外创建普通用户
1) 创建新用户sonar
# adduser sonar
2) 为sonar创建密码
# passwd sonar
3 )修改sonarqube的目录和用户组为sonar
# chown -R sonar:sonar sonarqube-xxx
注意: sonarqube-xxx为sonarqube安装好的绝对路径
4) 修改sonar引用的jdk的目录和用户组为sonar
#chown -R sonar:sonar jdk-xx
注意: jdk-xx为jdk安装好的绝对路径
4.1)配置wrapper.conf的wrapper.java.command=xxx/jdk-xxx/bin/java
4.2)sonar用户的环境变量文件~/.bash_profile配置与wrapper.conf相同
5)修改sonarqube-xx/bin/linux-x86-64/sonar.sh第48行为:RUN_AS_USER=sonar
问题2:sonarqube启动时报错WrapperSimpleApp: Encountered an error running main: java.nio.file.AccessDeniedException
解决2:删除sonarqube temp目录下的所有文件
问题3:用普通用户sonar启动后,浏览器还是不能访问,打开sonar.log,sonar启动后自动关闭:
2019.12.19 14:57:48 INFO app[][o.s.a.AppFileSystem] Cleaning or creating temp directory /usr/local/sonar/server/sonarqube-7.0/temp
2019.12.19 14:57:48 INFO app[][o.s.a.es.EsSettings] Elasticsearch listening on /127.0.0.1:9001
2019.12.19 14:57:48 INFO app[][o.s.a.p.ProcessLauncherImpl] Launch process[[key='es', ipcIndex=1, logFilenamePrefix=es]] from [/usr/local/sonar/server/sonarqube-7.0/elasticsearch]: /usr/local/sonar/server/sonarqube-7.0/elasticsearch/bin/elasticsearch -Epath.conf=/usr/local/sonar/server/sonarqube-7.0/temp/conf/es
2019.12.19 14:57:48 INFO app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
2019.12.19 14:57:50 INFO app[][o.e.p.PluginsService] no modules loaded
2019.12.19 14:57:50 INFO app[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2019.12.19 14:58:04 INFO app[][o.s.a.SchedulerImpl] Process[es] is up
2019.12.19 14:58:04 INFO app[][o.s.a.p.ProcessLauncherImpl] Launch process[[key='web', ipcIndex=2, logFilenamePrefix=web]] from [/usr/local/sonar/server/sonarqube-7.0]: /usr/java/jdk1.8.0_11/jre/bin/java -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/usr/local/sonar/server/sonarqube-7.0/temp -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -cp ./lib/common/*:./lib/server/*:/usr/local/sonar/server/sonarqube-7.0/lib/jdbc/mysql/mysql-connector-java-5.1.42.jar org.sonar.server.app.WebServer /usr/local/sonar/server/sonarqube-7.0/temp/sq-process7155272747250216309properties
2019.12.19 14:58:27 INFO app[][o.s.a.SchedulerImpl] Process [web] is stopped
2019.12.19 14:58:27 WARN app[][o.s.a.p.AbstractProcessMonitor] Process exited with exit value [es]: 143
2019.12.19 14:58:27 INFO app[][o.s.a.SchedulerImpl] Process [es] is stopped
2019.12.19 14:58:27 INFO app[][o.s.a.SchedulerImpl] SonarQube is stopped
解决3:根据提示查看es.log,显示如下图
说明数据库连接失败,仔细比对conf/sonar.properties里数据库连接配置,
没问题,我的mysql和sonar服务器安装在同一虚拟机内,填localhost是没问题的,死马当活马医尝试一下把localhost改为具体ip,保存退出后,在sonar用户下启动:./sonar.sh start
用指令./sonar.sh status查看
这次sonar成功启动
注意:
conf/sonar.properties里sonar.web.context=/sonar,则浏览器地址为:ip:port/sonar;
conf/sonar.properties里sonar.web.context=,则浏览器地址为:ip:port