注: 使用的Sonarqube版本是7.2,Sonarqube的官网。javascript
1. 下载安装包,我下载的是mac版本,下载后是个zip文件php
2.解压zip文件,获得以下:java
注意,data和temp目录是sonarqube运行起来后本身建立的,data目录用于存储数据,temp是一些临时数据。python
mjduan@mjduandeMacBook-Pro:/opt/software/code-tool/sonarqube/sonarqube-7.2 % ll total 16 -rw-r--r--@ 1 mjduan wheel 7.5K 6 18 09:31 COPYING drwxr-xr-x@ 8 mjduan wheel 256B 6 18 09:31 bin drwxr-xr-x@ 4 mjduan wheel 128B 6 19 11:32 conf drwxr-xr-x@ 5 mjduan wheel 160B 6 19 11:57 data drwxr-xr-x@ 11 mjduan wheel 352B 6 18 09:31 elasticsearch drwxr-xr-x@ 5 mjduan wheel 160B 6 19 12:05 extensions drwxr-xr-x@ 7 mjduan wheel 224B 6 18 09:35 lib drwxr-xr-x@ 8 mjduan wheel 256B 6 19 12:06 logs drwxr-xr-x@ 10 mjduan wheel 320B 6 19 12:21 temp drwxr-xr-x@ 23 mjduan wheel 736B 6 18 09:35 web
3.修改conf/wrapper.conf,将wrapper.java.command的值改成你本身的JDK路径,不要修改其它配置,默认就可。mysql
mjduan@mjduandeMacBook-Pro:/opt/software/code-tool/sonarqube/sonarqube-7.2 % more conf/wrapper.conf # Path to JVM executable. By default it must be available in PATH. # Can be an absolute path, for example: wrapper.java.command=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin/java wrapper.java.command=java ......
4.修改conf/sonar.propertiesgit
因为sonarqube须要使用到数据库,因此修改链接数据库的帐号密码,github
# User credentials. # Permissions to create tables, indices and triggers must be granted to JDBC user. # The schema must be created first. sonar.jdbc.username=root sonar.jdbc.password=密码
因为咱们使用的是MySQL,因此将sonar.jdbc.url的注释去掉,以后去数据库新建数据库sonar,这个是给sonarqube使用的。若是代码量大,强烈建议使用postgreSQL,特别是代码量较大时(我试过5万行Java代码时,链接MySQL就会报错)。web
#----- DEPRECATED #----- MySQL >=5.6 && <8.0 # Support of MySQL is dropped in Data Center Editions and deprecated in all other editions # Only InnoDB storage engine is supported (not myISAM). # Only the bundled driver is supported. It can not be changed. sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
conf/sonar.properties里面还有不少配置,好比配置端口sonar.web.port,这行默认是被注释的,端口默认使用的是9000,十分的不建议修改这个端口。sql
# Web context. When set, it must start with forward slash (for example /sonarqube). # The default value is root context (empty value). #sonar.web.context= # TCP port for incoming HTTP connections. Default value is 9000. sonar.web.port=9000
5. 启动Sonarqube,以后浏览器访问localhost:9000,若是出现登陆界面,默认的登陆用户名和密码都是admin和admin。typescript
bin/macosx-universal-64/sonar.sh start
技巧:
mjduan@mjduandeMacBook-Pro:/opt/software/code-tool/sonarqube/sonarqube-7.2 % bin/macosx-universal-64/sonar.sh Usage: bin/macosx-universal-64/sonar.sh { console | start | stop | restart | status | dump }
mjduan@mjduandeMacBook-Pro:/opt/software/code-tool/sonarqube/sonarqube-7.2 % ll logs total 592 -rw-r--r--@ 1 mjduan wheel 88B 6 18 09:31 README.txt -rw-r--r-- 1 mjduan wheel 88K 6 19 12:24 access.log -rw-r--r-- 1 mjduan wheel 4.6K 6 19 12:21 ce.log -rw-r--r-- 1 mjduan wheel 10K 6 19 12:19 es.log -rw-r--r-- 1 mjduan wheel 5.7K 6 19 12:19 sonar.log -rw-r--r-- 1 mjduan wheel 97K 6 19 12:19 web.log
6.Sonarqube界面是英文的,可使用中文语言包,
到Github上,下载最新的中文语言包,下载下来的jar放入extensions/plugins下,以下的sonar-l10n-zh-plugin-1.21.jar。以后重启Sonarqube,应该看到的就是中文管理界面的了。
mjduan@mjduandeMacBook-Pro:/opt/software/code-tool/sonarqube/sonarqube-7.2 % ll extensions/plugins total 71952 -rw-r--r--@ 1 mjduan wheel 224B 6 18 09:31 README.txt -rw-r--r--@ 1 mjduan wheel 1.5M 6 14 17:29 sonar-csharp-plugin-7.2.0.5463.jar -rw-r--r--@ 1 mjduan wheel 1.5M 6 14 16:26 sonar-flex-plugin-2.4.0.1222.jar -rw-r--r--@ 1 mjduan wheel 3.7M 6 15 14:50 sonar-go-plugin-1.1.0.1612.jar -rw-r--r--@ 1 mjduan wheel 7.8M 6 14 17:29 sonar-java-plugin-5.4.0.14284.jar -rw-r--r--@ 1 mjduan wheel 3.2M 6 14 16:26 sonar-javascript-plugin-4.1.0.6085.jar -rw-r--r--@ 1 mjduan staff 40K 6 19 12:16 sonar-l10n-zh-plugin-1.21.jar -rw-r--r--@ 1 mjduan wheel 293K 6 14 17:29 sonar-ldap-plugin-2.2.0.608.jar -rw-r--r--@ 1 mjduan wheel 2.4M 6 14 16:26 sonar-php-plugin-2.13.0.3107.jar -rw-r--r--@ 1 mjduan wheel 1.5M 6 14 16:26 sonar-python-plugin-1.10.0.2131.jar -rw-r--r--@ 1 mjduan wheel 2.5M 6 14 17:29 sonar-scm-git-plugin-1.4.1.1128.jar -rw-r--r--@ 1 mjduan wheel 6.9M 6 14 16:26 sonar-scm-svn-plugin-1.7.0.1017.jar -rw-r--r--@ 1 mjduan wheel 2.0M 6 15 14:50 sonar-typescript-plugin-1.7.0.2893.jar -rw-r--r--@ 1 mjduan wheel 1.7M 6 14 17:29 sonar-xml-plugin-1.5.1.1452.jar