sonar的配置安装

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
云数据库 RDS PostgreSQL,高可用系列 2核4GB
简介:

一 Sonar 概述

Sonar 是一个用于代码质量管理的开放平台。通过插件机制,Sonar 可以集成不同的测试工具,代码分析工具,以及持续集成工具。

与持续集成工具(例如 Hudson/Jenkins 等)不同,Sonar 并不是简单地把不同的代码检查工具结果(例如 FindBugs,PMD 等)直接显示在 Web 页面上,而是通过不同的插件对这些结果进行再加工处理,通过量化的方式度量代码质量的变化,从而可以方便地对不同规模和种类的工程进行代码质量管理。

在对其他工具的支持方面,Sonar 不仅提供了对 IDE 的支持,可以在 Eclipse 和 IntelliJ IDEA 这些工具里联机查看结果;同时 Sonar 还对大量的持续集成工具提供了接口支持,可以很方便地在持续集成中使用 Sonar。

此外,Sonar 的插件还可以对 Java 以外的其他编程语言提供支持,对国际化以及报告文档化也有良好的支持。

二 Sonar 的安装

Sonar的相关下载和文档可以在下面的链接中找到:http://www.sonarqube.org/downloads/。需要注意最新版的Sonar需要至少JDK 1.8及以上版本。

 上篇文章我们已经可以成功的使用Git进行拉去,Sonar的功能就是来检查代码是否有BUG。除了检查代码是否有bug还有其他的功能,比如说:你的代码注释率是多少,代码有一些建议,编写语法的建议。所以我们叫质量管理

Sonar还可以给代码打分,并且引用了技术宅的功能(告诉你有很多地方没改)

Sonar 是 Codehaus 上面的一个开源项目,使用的是 LGPL V3 软件许可。我们可以在其官方网站上下载其源代码及安装包。

其源代码需要使用分布式版本控制软件 Git 进行检出(Check Out),命令行方式如下:

git clone git://github.com/SonarSource/sonar.git

基础环境安装

1
2
3
4
5
6
7
8
[root@linux-node1 ~] # yum install -y java-1.8.0
[root@linux-node1 ~] # cd /usr/local/src
软件包我们通过wget或者下载,rz上传到服务器
#软件包下载:https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-5.6.zip
 
[root@linux-node1 src] # unzip sonarqube-5.6.zip
[root@linux-node1 src] # mv sonarqube-5.6 /usr/local/
[root@linux-node1 src] # ln -s /usr/local/sonarqube-5.6/ /usr/local/sonarqube

数据库安装配置


Sonar 默认使用的是 Derby 数据库,但这个数据库一般用于评估版本或者测试用途。商用及对数据库要求较高时,建议使用其他数据库。Sonar 可以支持大多数主流关系型数据库(例如 Microsoft SQL Server, MySQL, Oracle, PostgreSQL 等)

本文以 mariadb 为例说明如何更改 Sonar 的数据库设置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
yum  install  -y mariadb mariadb-server
  [root@salt-node2 ~] # systemctl enable mariadb
  [root@salt-node2 ~] # systemctl start mariadb
   [root@salt-node2 ~] # mysql_secure_installation 
 
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
       SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
 
In order to log into MariaDB to secure it, we'll need the current
password  for  the root user.  If you've just installed MariaDB, and
you haven't  set  the root password yet, the password will be blank,
so you should just press enter here.
 
Enter current password  for  root (enter  for  none): 
ERROR 1045 (28000): Access denied  for  user  'root' @ 'localhost'  (using password: YES)
Enter current password  for  root (enter  for  none): 
OK, successfully used password, moving on...
 
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
 
Set root password? [Y /n ] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
  ... Success!
 
 
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created  for
them.  This is intended only  for  testing, and to  make  the installation
go a bit smoother.  You should remove them before moving into a
production environment.
 
Remove anonymous  users ? [Y /n ] y
  ... Success!
 
Normally, root should only be allowed to connect from  'localhost' .  This
ensures that someone cannot guess at the root password from the network.
 
Disallow root login remotely? [Y /n ] y
  ... Success!
 
By default, MariaDB comes with a database named  'test'  that anyone can
access.  This is also intended only  for  testing, and should be removed
before moving into a production environment.
 
Remove  test  database and access to it? [Y /n ] y
  - Dropping  test  database...
  ... Success!
  - Removing privileges on  test  database...
  ... Success!
 
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
 
Reload privilege tables now? [Y /n ] y
  ... Success!
 
Cleaning up...
 
All  done !  If you've completed all of the above steps, your MariaDB
installation should now be secure.
 
Thanks  for  using MariaDB!   
  [root@salt-node2 ~] # mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection  id  is 18
Server version: 5.5.52-MariaDB MariaDB Server
 
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
 
Type  'help;'  or  '\h'  for  help. Type  '\c'  to  clear  the current input statement.
 
MariaDB [(none)]>

配置数据库

1
2
3
4
5
6
7
8
9
10
11
MariaDB [(none)]> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.02 sec)
 
MariaDB [(none)]> GRANT ALL ON sonar.* TO  'sonar' @ 'localhost'  IDENTIFIED BY  'sonar@pw' ;
Query OK, 0 rows affected (0.01 sec)
 
MariaDB [(none)]>  GRANT ALL ON sonar.* TO  'sonar' @ '%'  IDENTIFIED BY  'sonar@pw' ;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

配置Sonar配置文件链接数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  [root@salt-node2 ~] # cd /usr/local/sonarqube/conf/
  [root@salt-node2  /usr/local/sonarqube/conf ] # ls
sonar.properties  wrapper.conf
  [root@salt-node2  /usr/local/sonarqube/conf ] # vim sonar.properties 
 
# Property values can:
# - reference an environment variable, for example sonar.jdbc.url= ${env:SONAR_JDBC_URL}
# - be encrypted. See http://redirect.sonarsource.com/doc/settings-encryption.html
 
#--------------------------------------------------------------------------------------------------
# DATABASE
#
# IMPORTANT: the embedded H2 database is used by default. It is recommended for tests but not for
# production use. Supported databases are MySQL, Oracle, PostgreSQL and Microsoft SQLServer.
 
# User credentials.
# Permissions to create tables, indices and triggers must be granted to JDBC user.
# The schema must be created first.
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar@pw
 
#----- Embedded Database (default)
# H2 embedded database server listening port, defaults to 9092
#sonar.embeddedDatabase.port=9092
#----- MySQL 5.6 or greater
# 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
sonar.jdbc.url=jdbc:mysql: //localhost :3306 /sonar ?useUnicode= true &characterEncoding=utf8&rewriteBatchedStatements= true &useConfigs=maxPerformance
  99  #sonar.web.host=0.0.0.0 配置监听地址
106  #sonar.web.port=9000 配置监听端口

配置Java访问数据库驱动(可选) 
  默认情况Sonar有自带的嵌入的数据库,那么你如果使用类是Oracle数据库,必须手动复制驱动类到${SONAR_HOME}/extensions/jdbc-driver/oracle/目录下,其它支持的数据库默认提供了驱动。其它数据库的配置可以参考官方文档: 
http://docs.sonarqube.org/display/HOME/SonarQube+Platform


启动sonar

1
<br>




本文转自 kesungang 51CTO博客,原文链接:http://blog.51cto.com/sgk2011/2069019,如需转载请自行联系原作者
相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
相关文章
|
安全 算法 物联网
MQTT 安全通信 SSL 双向认证 | 学习笔记
快速学习 MQTT 安全通信 SSL 双向认证
MQTT 安全通信 SSL 双向认证 | 学习笔记
|
Java p3c
sonar入门:使用阿里规范扫描代码质量
sonar入门:使用阿里规范扫描代码质量
2076 0
sonar入门:使用阿里规范扫描代码质量
|
8月前
|
存储 弹性计算 固态存储
阿里云服务器ESSD Entry系统盘测评IOPS、IO读写和时延性能参数
阿里云ESSD Entry云盘是新一代企业级云盘,具备高IOPS、低延迟特性,适合开发与测试场景。它提供10~32,768 GiB容量范围,最大IOPS达6,000,吞吐量150 MB/s,时延1~3 ms。支持按量付费和包年包月,性价比高,特别适合个人开发者和中小企业。详情及价格参考阿里云官网。
|
9月前
|
人工智能
Fancy123:华中科技和华南理工推出的3D网格生成技术
Fancy123是由华中科技大学和华南理工大学联合推出的3D网格生成技术,能够从单张图片生成高质量的3D网格。该技术通过即插即用的变形技术,解决了多视图图像的局部不一致性,提高了网格对输入图像的保真度,并确保了高清晰度。Fancy123在定性和定量实验中表现出色,能够无缝集成到现有的单图像到3D的方法中。
126 5
Fancy123:华中科技和华南理工推出的3D网格生成技术
|
10月前
|
SQL 存储 数据挖掘
快速入门:利用AnalyticDB构建实时数据分析平台
【10月更文挑战第22天】在大数据时代,实时数据分析成为了企业和开发者们关注的焦点。传统的数据仓库和分析工具往往无法满足实时性要求,而AnalyticDB(ADB)作为阿里巴巴推出的一款实时数据仓库服务,凭借其强大的实时处理能力和易用性,成为了众多企业的首选。作为一名数据分析师,我将在本文中分享如何快速入门AnalyticDB,帮助初学者在短时间内掌握使用AnalyticDB进行简单数据分析的能力。
395 2
|
12月前
|
IDE Java 编译器
lombok编译遇到“找不到符号的问题”
【9月更文挑战第18天】当使用 Lombok 遇到 “找不到符号” 的问题时,可能是由于 Lombok 未正确安装、编译器不支持、IDE 配置不当或项目构建工具配置错误。解决方法包括确认 Lombok 安装、编译器支持,配置 IDE 和检查构建工具配置。通过这些步骤通常可解决问题,若问题仍存在,建议检查项目配置和依赖,或查看日志获取更多信息。
4626 2
|
弹性计算 运维 Shell
获取本机 MAC 地址
【4月更文挑战第29天】
204 1
|
存储 网络协议 网络安全
RTMP协议详解及Wiresahrk抓包分析(一)
RTMP协议详解及Wiresahrk抓包分析
1002 2
|
安全 大数据 网络安全
六、《图解HTTP》- 用户身份认证
六、《图解HTTP》- 用户身份认证
233 0
|
存储 Java 关系型数据库
Sonar环境搭建
Sonar环境搭建
417 0
Sonar环境搭建