当前位置: 首页 > news >正文

SonarQube数据库配置

SonarQube部署完成后,在浏览器地址栏输入http://IP:9000可以进入登录页面,以本机运行为例,地址为http://127.0.0.1:9000/,默认登录名:admin,登录密码也是admin。登录后会要求设置密码:
修改密码
按要求设置新密码即可,系统要求如下:
pwd requirement
设置后即可登录系统:
index
从图中可见,如果用默认的嵌入式数据库(H2)的话,会有仅作测试用提示:

Embedded database should be used for evaluation purposes only. It doesn’t support scaling, upgrading to a new SonarQube Server version, or migration to another database engine.

插件安装

点击配置、应用市场:“Administration->Marketplace”,可以安装插件,这里我们以“Chinese Pack”中文语言包为例。
plugins
安装后界面变成了中文。此外应用市场Marketplace还有很多插件可以供我们使用,这个可以在使用过程中逐渐探索。安装完成后系统会要求重启(启用插件)或复原(回退):
marketplace restart
点击重启按钮“Restart Server”后,会自动重启服务:
backend
重启后系统需要重新登录:
login
登录后界面变成中文的了:
ch

数据库配置

SonarQube默认是H2数据库,但事实上它支持OraclePostgreSQLMicrosoft SQLServer,四种数据库,通过修改config文件夹下sonar.propertiessonar.jdbc.url属性,可以指向我们要使用的数据库。
整个sonar.properties文件的数据库配置部分摘录如下:

#--------------------------------------------------------------------------------------------------
# DATABASE
#
# IMPORTANT:
# - The embedded H2 database is used by default. It is recommended for tests but not for
#   production use. Supported databases are Oracle, PostgreSQL and Microsoft SQLServer.
# - Changes to database connection URL (sonar.jdbc.url) can affect SonarSource licensed products.

# 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.jdbc.password=

#----- Embedded Database (default)
# H2 embedded database server listening port, defaults to 9092
#sonar.embeddedDatabase.port=9092

#----- Oracle 19c/21c
# The Oracle JDBC driver must be copied into the directory extensions/jdbc-driver/oracle/.
# Only the thin client is supported, and we recommend using the latest Oracle JDBC driver. See
# https://jira.sonarsource.com/browse/SONAR-9758 for more details.
# If you need to set the schema, please refer to http://jira.sonarsource.com/browse/SONAR-5000
#sonar.jdbc.url=jdbc:oracle:thin:@localhost:1521/XE

#----- PostgreSQL 11 or greater
# By default the schema named "public" is used. It can be overridden with the parameter "currentSchema".
#sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube?currentSchema=my_schema

#----- Microsoft SQLServer 2014/2016/2017/2019/2022 and SQL Azure
# A database named sonar must exist and its collation must be case-sensitive (CS) and accent-sensitive (AS)
# Use the following connection string if you want to use integrated security with Microsoft Sql Server
# Do not set sonar.jdbc.username or sonar.jdbc.password property if you are using Integrated Security
# For Integrated Security to work, you have to install the Microsoft SQL JDBC Auth package
# Please refer to the online documentation https://docs.sonarsource.com/sonarqube
# for the exact procedure for this version of SonarQube.
#sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=sonar;integratedSecurity=true

# Use the following connection string if you want to use SQL Auth while connecting to MS Sql Server.
# Set the sonar.jdbc.username and sonar.jdbc.password appropriately.
#sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=sonar

#----- Connection pool settings
# The maximum number of active connections that can be allocated
# at the same time, or negative for no limit.
# The recommended value is 1.2 * max sizes of HTTP pools. For example if HTTP ports are
# enabled with default sizes (50, see property sonar.web.http.maxThreads)
# then sonar.jdbc.maxActive should be 1.2 * 50 = 60.
#sonar.jdbc.maxActive=60

# The minimum number of connections that can remain idle in the pool,
# without extra ones being created, or zero to create none.
#sonar.jdbc.minIdle=10

# The maximum number of milliseconds that the pool will wait (when there
# are no available connections) for a connection to be returned before
# throwing an exception, or <= 0 to wait indefinitely.
#sonar.jdbc.maxWait=8000

1. 支持的数据库
参考官方文档(Database requirements | SonarQube Community Build Documentation)及前述,我们可以看出,SonarQube支持以下数据库引擎:

数据库引擎安装要求
PostgreSQL版本:13-17(官方文档要求,实际上看配置文件,支持版本11及以上)
Microsoft SQLServer

官方文档版本要求:

2022 (MSSQL Server 16.0); 2019 (MSSQL Server 15.0); 2017 (MSSQL Server 14.0); 2016 (MSSQL Server 13.0),需要Micorsoft JDBC驱动(SonarQubelib目录已包含)

配置文件实际版本要求:

Microsoft SQLServer 2014/2016/2017/2019/2022 and SQL Azure

注:

  • 支持SQL Server Express版本
  • 支持WindowsSQL Server两种身份验证方式

Oracle

版本要求:23ai, 21C, 19C, XE Editions

推荐:最新版本的 Oracle JDBC驱动

注:

  • 不支持odbc14.jar驱动
  • 只支持thin模式,不支持OCI
  • 只支持MAX_STRING_SIZE=STANDARD参数,不支持EXTENDED
  • Oracle JDBC 驱动12.1.0.112.1.0.2有较大bug不推荐应用在SonarQube社区版中(点击可查看详情)

2. 修改数据库连接
Microsoft SQL Server为例,我们尝试对SonarQube连接的数据库进行配置。
(1)数据库创建
create db
ssms
需要注意的是,SonarQube要求大小写和强调差异(case-sensitive and accent-sensitive)敏感的排序规则,如:Chinese_PRC_CS_AS

ALTER DATABASE sonar COLLATE Chinese_PRC_CS_AS

collate
(2)数据库连接修改
根据config/sonar.properties配置文件的说明,修改连接指向后,表结构等内容会自动创建(要求具有相应权限)。
首先,我们设置数据库的用户名和密码:

sonar.jdbc.username=your_db_user
sonar.jdbc.password=your_db_password

接着,我们修改数据库连接字符串,对于SQL Server,其配置参考如下:

#----- Microsoft SQLServer 2014/2016/2017/2019/2022 and SQL Azure
# A database named sonar must exist and its collation must be case-sensitive (CS) and accent-sensitive (AS)
# Use the following connection string if you want to use integrated security with Microsoft Sql Server
# Do not set sonar.jdbc.username or sonar.jdbc.password property if you are using Integrated Security
# For Integrated Security to work, you have to install the Microsoft SQL JDBC Auth package
# Please refer to the online documentation https://docs.sonarsource.com/sonarqube
# for the exact procedure for this version of SonarQube.
#sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=sonar;integratedSecurity=true

# Use the following connection string if you want to use SQL Auth while connecting to MS Sql Server.
# Set the sonar.jdbc.username and sonar.jdbc.password appropriately.
#sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=sonar

我们可以选择集成安全模式(需要安装配套的包),或使用SQL Server自己的鉴权方式,本例为了简单我们选择后者,考虑本机连接,Encrypt属性设置为truetrustServerCertificate属性设置为true(信任服务器证书,使用自签名证书,否则会报错的):

sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=sonar;encrypt=true;trustServerCertificate=true

(3)修改后运行效果
重新启动SonarQube服务,我们可以观察到如下变化:
restart sonarqube
1)数据库相关对象自动创建了
db tables
2)密码需要重新设定登录
因为换了数据库,需要重新设置密码并登录。
relogin

从上图也可以看出不再提示测试数据库环境(H2)了。

总结

至此,我本机环境的SonarQube实现了数据库的更改,当然,在实际的应用中使用Docker容器安装Sonar会简便很多,但为了对这个工具有更多了解(踩更多的坑,更改数据库配置过程也遇到一些问题,参见这里),手工操作也是一个不错的体验。
接下来,我将尝试对这个工具做更多的学习、应用与探索。

相关文章:

  • 搭建网站用什么软件seo信息是什么
  • 一诺网站建设百度推广怎么收费的
  • 网站备案名称能重复吗成都建设网官网
  • 长沙专业网站制作服务价格社交媒体营销策略有哪些
  • 专业的网站建设设计价格网站开发报价方案
  • 营销型网站建设论坛网站设计与制作公司
  • Flutter之页面布局一
  • Kubernetes 集群搭建(一):k8s 从环境准备到 Calico 网络插件部署(1.16版本)
  • 常见的图像生成算法
  • 堆与二叉树的关系
  • Python四大核心数据结构深度解析:列表、元组、字典与集合
  • STM32F103C8T6实现 SG90 360 °电机转动
  • 积分赛——获取环境温度
  • PyTorch深度学习框架60天进阶学习计划 - 第36天:医疗影像诊断(一)
  • Unhandled exception: org.apache.poi.openxml4j.exceptions.InvalidFormatException
  • 混合精度策略在PBiCGStab算法中的应用
  • 数据蒸馏:Dataset Distillation by Matching Training Trajectories 论文翻译和理解
  • Redis数据结构之String
  • 蓝桥杯:对字符串处理常用知识笔记
  • 如何在Ubuntu上安装Dify
  • 控件主题效果添加程序设计
  • 【速写】SFT案例实操(以Qwen2.5-instruct-0.5B)
  • 24统计建模国奖论文写作框架(机器学习+图像识别类)
  • 搭建redis主从同步实现读写分离(原理剖析)
  • Day1:前端项目uni-app壁纸实战
  • Python-函数参数