sonar入门(安装篇)

SONAR下载地址:  https://www.sonarqube.org/downloads/    (本文版本:sonarqube-6.3)



下载完解压出来

根据你的电脑系统进到bin后的系统目录 (本文机器,64位WIN7)

用CMD命令进入 E:\Program File\sonarqube-6.3\bin\windows-x86-64后执行  StartSonar.bat


E:\Program File\sonarqube-6.3\bin\windows-x86-64>StartSonar.bat
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    | WrapperSimpleApp: Unable to locate the class org.sonar.application.App: java.lang.UnsupportedClassVersionError: org/sonar/application/App : Unsupport
ed major.minor version 52.0

jvm 1    |
jvm 1    | WrapperSimpleApp Usage:
jvm 1    |   java org.tanukisoftware.wrapper.WrapperSimpleApp {app_class} [app_arguments]
jvm 1    |
jvm 1    | Where:
jvm 1    |   app_class:      The fully qualified class name of the application to run.
jvm 1    |   app_arguments:  The arguments that would normally be passed to the
jvm 1    |                   application.
wrapper  | <-- Wrapper Stopped
请按任意键继续. . .


这种错误是因为JDK版本过低的问题,sonarqube-6.3需要JDK1.8+,所以电脑配置JDK1.8后,重新运行即可


在运行前先新建一个数据库

sonar入门(安装篇)

sonar入门(安装篇)sonar入门(安装篇)

在此我命名为sonar

接下来修改

conf/sonar.properties文件,主要添加数据库信息

sonar.jdbc.username=
sonar.jdbc.password=

sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance


如果没有配置好数据库则运行时会出现以下错误

E:\Program File\sonarqube-6.3\bin\windows-x86-64>StartSonar.bat
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    | 2017.08.25 15:48:52 INFO  app[][o.s.a.AppFileSystem] Cleaning or creating temp directory E:\Program File\sonarqube-6.3\temp
jvm 1    | 2017.08.25 15:48:53 INFO  app[][o.s.p.m.JavaProcessLauncher] Launch process[es]: E:\software\java\jdk1.8.0_121\jre\bin\java -Djava.awt.headless=true
-Xmx1G -Xms256m -Xss256k -Djna.nosys=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:
+HeapDumpOnOutOfMemoryError -Djava.io.tmpdir=E:\Program File\sonarqube-6.3\temp -javaagent:E:\software\java\jdk1.8.0_121\jre\lib\management-agent.jar -cp ./lib/
common/*;./lib/search/* org.sonar.search.SearchServer E:\Program File\sonarqube-6.3\temp\sq-process1206689812975548668properties
jvm 1    | 2017.08.25 15:49:05 INFO  app[][o.s.p.m.Monitor] Process[es] is up
jvm 1    | 2017.08.25 15:49:05 INFO  app[][o.s.p.m.JavaProcessLauncher] Launch process[web]: E:\software\java\jdk1.8.0_121\jre\bin\java -Djava.awt.headless=true
 -Dfile.encoding=UTF-8 -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -Djava.io.tmpdir=E:\Program File\sonarqube-6.3\temp -javaagent:E:\software\java\jdk1.8.
0_121\jre\lib\management-agent.jar -cp ./lib/common/*;./lib/server/*;E:\Program File\sonarqube-6.3\lib\jdbc\mysql\mysql-connector-java-5.1.39.jar org.sonar.serv
er.app.WebServer E:\Program File\sonarqube-6.3\temp\sq-process3901561166471593448properties
jvm 1    | Fri Aug 25 15:49:10 CST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+,
 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using
 SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide t
ruststore for server certificate verification.
jvm 1    | 2017.08.25 15:49:12 INFO  app[][o.s.p.m.Monitor] Process[es] is stopping
jvm 1    | 2017.08.25 15:49:12 ERROR app[][o.s.p.m.Monitor] Process[web] failed to start
jvm 1    | 2017.08.25 15:49:13 INFO  app[][o.s.p.m.Monitor] Process[es] is stopped
wrapper  | <-- Wrapper Stopped


弄好数据库配置后重新运行

我们可以看到脚本会往SONAR这个库创建很多表及自动插入一些数据

sonar入门(安装篇)sonar入门(安装篇)


执行成功的日志如下

E:\Program File\sonarqube-6.3\bin\windows-x86-64>StartSonar.bat
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    | 2017.08.25 15:50:42 INFO  app[][o.s.a.AppFileSystem] Cleaning or creating temp directory E:\Program File\sonarqube-6.3\temp
jvm 1    | 2017.08.25 15:50:42 INFO  app[][o.s.p.m.JavaProcessLauncher] Launch process[es]: E:\software\java\jdk1.8.0_121\jre\bin\java -Djava.awt.headless=true
-Xmx1G -Xms256m -Xss256k -Djna.nosys=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:
+HeapDumpOnOutOfMemoryError -Djava.io.tmpdir=E:\Program File\sonarqube-6.3\temp -javaagent:E:\software\java\jdk1.8.0_121\jre\lib\management-agent.jar -cp ./lib/
common/*;./lib/search/* org.sonar.search.SearchServer E:\Program File\sonarqube-6.3\temp\sq-process1379441345670336396properties
jvm 1    | 2017.08.25 15:50:53 INFO  app[][o.s.p.m.Monitor] Process[es] is up
jvm 1    | 2017.08.25 15:50:53 INFO  app[][o.s.p.m.JavaProcessLauncher] Launch process[web]: E:\software\java\jdk1.8.0_121\jre\bin\java -Djava.awt.headless=true
 -Dfile.encoding=UTF-8 -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -Djava.io.tmpdir=E:\Program File\sonarqube-6.3\temp -javaagent:E:\software\java\jdk1.8.
0_121\jre\lib\management-agent.jar -cp ./lib/common/*;./lib/server/*;E:\Program File\sonarqube-6.3\lib\jdbc\mysql\mysql-connector-java-5.1.39.jar org.sonar.serv
er.app.WebServer E:\Program File\sonarqube-6.3\temp\sq-process8409360607056740017properties
jvm 1    | Fri Aug 25 15:50:57 CST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+,
 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using
 SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide t
ruststore for server certificate verification.
jvm 1    | Fri Aug 25 15:50:57 CST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+,
 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using
 SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide t
ruststore for server certificate verification.
jvm 1    | Fri Aug 25 15:51:06 CST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+,
 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using
 SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide t
ruststore for server certificate verification.
jvm 1    | Fri Aug 25 15:51:27 CST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+,
 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using
 SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide t
ruststore for server certificate verification.
jvm 1    | 2017.08.25 15:51:33 INFO  app[][o.s.p.m.Monitor] Process[web] is up
jvm 1    | 2017.08.25 15:51:33 INFO  app[][o.s.p.m.JavaProcessLauncher] Launch process[ce]: E:\software\java\jdk1.8.0_121\jre\bin\java -Djava.awt.headless=true
-Dfile.encoding=UTF-8 -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -Djava.io.tmpdir=E:\Program File\sonarqube-6.3\temp -javaagent:E:\software\java\jdk1.8.0
_121\jre\lib\management-agent.jar -cp ./lib/common/*;./lib/server/*;./lib/ce/*;E:\Program File\sonarqube-6.3\lib\jdbc\mysql\mysql-connector-java-5.1.39.jar org.
sonar.ce.app.CeServer E:\Program File\sonarqube-6.3\temp\sq-process3449682494564184520properties
jvm 1    | Fri Aug 25 15:51:37 CST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+,
 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using
 SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide t
ruststore for server certificate verification.
jvm 1    | Fri Aug 25 15:51:37 CST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+,
 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using
 SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide t
ruststore for server certificate verification.
jvm 1    | 2017.08.25 15:51:41 INFO  app[][o.s.p.m.Monitor] Process[ce] is up
jvm 1    | 2017.08.25 15:51:41 INFO  app[][o.s.application.App] SonarQube is up

jvm 1    | Fri Aug 25 15:52:07 CST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+,
 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using
 SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide t
ruststore for server certificate verification.


看到最后出现红色字体就说明SONAR启动成功了,我们测试一下


在浏览器输入http://localhost:9000


sonar入门(安装篇)

sonar入门(安装篇)

说明启动成功,登陆的话默认账号有admin/admin (用户信息保存在数据库表users)