前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >代码质量之Sonarqube安装 原

代码质量之Sonarqube安装 原

作者头像
克虏伯
发布2019-04-15 14:23:13
6520
发布2019-04-15 14:23:13
举报

注: 使用的Sonarqube版本是7.2,Sonarqube的官网

1. 下载安装包,我下载的是mac版本,下载后是个zip文件

2.解压zip文件,得到如下:

    注意,data和temp目录是sonarqube运行起来后自己创建的,data目录用于存储数据,temp是一些临时数据。

代码语言:javascript
复制
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路径,不要修改其它配置,默认就可。

代码语言:javascript
复制
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.properties

    由于sonarqube需要使用到数据库,所以修改连接数据库的账号密码,

代码语言:javascript
复制
# 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就会报错)。

代码语言:javascript
复制
#----- 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,十分的不建议修改这个端口。

代码语言:javascript
复制
# 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。

代码语言:javascript
复制
bin/macosx-universal-64/sonar.sh start

 技巧:

  •     sonar.sh后面的命令还可以是其它的,如下,status可以查看sonarqube是否正在运行。
代码语言:javascript
复制
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 }
  •     查看日志,特别是sonarqube启动不起来的时候,要查看日志,日志里面会有报错信息。
代码语言:javascript
复制
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,应该看到的就是中文管理界面的了。

代码语言:javascript
复制
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

(adsbygoogle = window.adsbygoogle || []).push({});

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018/06/19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档