注: 使用的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