您好,欢迎来到伴沃教育。
搜索
您的当前位置:首页04 - SonarQube部署

04 - SonarQube部署

来源:伴沃教育

目录

  • SonarQube的架构和集成
  • 部署 SonarQube

SonarQube的架构和集成


架构
SonarQube 做代码审查,主要包括两部分:SonarQube ServerSonarQube Plugins,其中 SonarQube Server 主要是用来处理代码分析报告并把结果存储到 SonarQube Database 中,其中的分析报告来自构建或者持续继承环境的 SonarQube Scanners 的扫描结果。 集成

部署 SonarQube 服务


SonarQube的部署分两步

  • 安装 SonarQube Server
  • 安装 Plugin

安装 SonarQube Server

环境要求

  • CentOS
  • JDK 8
  • MySQL 5.6 | 5.7
  • UTF8 charset
  • InnoDB storage engine
  • Chrome | IE 11 | Firefox

安装配置数据库

安装MySQL数据库,并创建所需数据库

mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci; 
mysql> CREATE USER 'sonar' IDENTIFIED BY 'sonar';
mysql> GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
mysql> GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';
mysql> FLUSH PRIVILEGES;

安装SonarCube(CentOS服务器)

//下载 SonarQube 5.6 L.T.S.
$ sudo wget -O /opt/sonarqube-5.6.4.zip 
// 解压 sonarqube
$ sudo cd /opt/ && unzip /sonarqube-5.6.4.zip
// 重命名目录
$ sudo mv sonarqube-5.6.4 sonar

配置数据库连接

编辑配置文件 /opt/sonar/conf/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 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

#----- 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

修改服务WEB配置(可选)

编辑配置文件 /opt/sonar/conf/sonar.properties

sonar.web.host=0.0.0.0  // 默认所有IP可访问
sonar.web.port=9000  // 默认端口
sonar.web.context=  // 默认上下文 /

配置防火墙

// 添加8080端口(Jenkins默认服务端口)到防火墙
$ sudo firewall-cmd --permanent --add-port=9000/tcp
$ sudo firewall-cmd --reload

启动服务

$ sudo cd /opt/sonar/bin/linux-x86-64
$ sudo ./sonar.sh start

浏览器访问 SonarQube

  • 用户名/密码:admin/admin
  • 访问地址:http://10.10.4.171:9000

安装插件


在线安装

进入菜单:Administration - System - Update Center


Paste_Image.png Paste_Image.png

建议安装的插件清单:

  • Chinese Pack: 汉化插件
  • : Launch analysis from the command line
  • Launch analysis of projects
  • : Launch analysis from Ant
  • : Launch analysis from Maven with minimal configuration
  • : Launch Gradle analysis
  • : Launch analysis from Jenkins
  • Checkstyle

离线安装

生成 Token

Paste_Image.png
点击更新 Token,输入名称,生成Token,后面在Gradle构建脚本中集成代码审查时会用到
Paste_Image.png

FAQ


  • SonarQube 启动报错:Unsupported major.minor version 52.0
【解决办法】
下载使用最新的JDK

  • SonarQuber 启动报错:Cannot create PoolableConnectionFactory (Table 'performance_schema.session_variables' doesn't exist)
【解决办法】
在数据库节点上执行已下两个命令:
# mysql_upgrade -u root -p --force
# systemctl restart mysqld

参考资料

Copyright © 2019- bangwoyixia.com 版权所有 湘ICP备2023022004号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务