SonarQube 安装步骤
- 确定 JDK 和 MySQL 已经成功安装。
- 下载 SonarQube 及工具 SonarQube Runner,下载地址:http://www.sonarqube.org/downloads/
- 解压文件,将下载的 SonarQube 和 SonarQube Runner 解压到指定的目录。
- 添加环境变量:
export SONAR_HOME=/home/huey/huey/sonar/sonarqube-5.0.1 export SONAR_RUNNER_HOME=/home/huey/huey/sonar/sonar-runner-2.4 export PATH=${SONAR_RUNNER_HOME}/bin:$PATH
- 数据库(MySQL)的配置:
CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci; CREATE USER ‘sonar‘ IDENTIFIED BY ‘sonar‘; GRANT ALL ON sonar.* TO ‘sonar‘@‘%‘ IDENTIFIED BY ‘sonar‘; GRANT ALL ON sonar.* TO ‘sonar‘@‘localhost‘ IDENTIFIED BY ‘sonar‘; FLUSH PRIVILEGES;
在创建数据库与用户后, 修改 sonar.properties 属性文件:
sonar.jdbc.username=sonar sonar.jdbc.password=sonar sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance sonar.jdbc.driverClassName=com.mysql.jdbc.Driver
- 根据数据库配置在 SonarQube Runner 的属性文件 sonar-runner.properties 取消对应的注释:
#Configure here general information about the environment, such as SonarQube DB details for example #No information about specific project should appear here #----- Default SonarQube server sonar.host.url=http://localhost:9000 #----- PostgreSQL sonar.jdbc.url=jdbc:postgresql://localhost/sonar #----- MySQL sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8 #----- Oracle #sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE #----- Microsoft SQLServer #sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor #----- Global database settings sonar.jdbc.username=sonar sonar.jdbc.password=sonar #----- Default source code encoding #sonar.sourceEncoding=UTF-8 #----- Security (when ‘sonar.forceAuthentication‘ is set to ‘true‘) sonar.login=admin sonar.password=admin
- 启动 SonarQube 服务(需要根据不同的平台选择相应的目录):
sh sonar.sh start
- 至此,已经能够使用 SonarQube,访问 http://localhost:9000
时间: 2024-09-30 16:16:40