sonar的配置安装

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

一 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,如需转载请自行联系原作者
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
4月前
|
Java 关系型数据库 jenkins
SonarQube-Jenkins问题汇总
SonarQube-Jenkins问题汇总
|
SQL 安全 IDE
SonarQube使用介绍
SonarQube使用介绍
1831 0
SonarQube使用介绍
|
关系型数据库 MySQL Linux
SonarQube启动不了的问题解决
SonarQube启动不了的问题解决
SonarQube启动不了的问题解决
|
前端开发 数据安全/隐私保护
SonarQube的LDAP配置
SonarQube的ldap配置
1489 0
SonarQube的LDAP配置
五分钟带你玩转sonar(五)教你使用SonarLint插件
五分钟带你玩转sonar(五)教你使用SonarLint插件
2454 0
五分钟带你玩转sonar(五)教你使用SonarLint插件
|
7月前
|
Oracle Java 关系型数据库
|
Java jenkins 持续交付
SonarQube安装遇到的常见报错问题启动不起来等
SonarQube安装遇到的常见报错问题启动不起来等
|
存储 Java 关系型数据库
Sonar环境搭建
Sonar环境搭建
254 0
Sonar环境搭建
|
存储 网络安全 数据库
服务器常用环境(Redmine,Gitlab,Svn,Testlink)安装及配置(二)
服务器常用环境(Redmine,Gitlab,Svn,Testlink)安装及配置(二)
服务器常用环境(Redmine,Gitlab,Svn,Testlink)安装及配置(二)
|
存储 关系型数据库 MySQL
服务器常用环境(Redmine,Gitlab,Svn,Testlink)安装及配置(四)
服务器常用环境(Redmine,Gitlab,Svn,Testlink)安装及配置(四)
服务器常用环境(Redmine,Gitlab,Svn,Testlink)安装及配置(四)