Sonar安装

1. JDK1.8安装

安装jdk1.8这里省略。

2. SonarQube 部署

su - jenkins #为了在jenkins中集成sonar,所以安装在jenkins用户下
cd /data/jenkins
wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-6.3.zip
unzip sonarqube-6.3.zip
ln -s /data/jenkins/sonarqube-6.3 /data/jenkins/sonarqube

3. 准备mysql数据库

安装mysql这里省略 创建数据库sonar

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

4. 修改sonar配置

修改sonar.properties的数据库连接

# cd /data/jenkins/sonarqube/conf
# vim 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

5. 启动sonarqube

cd /data/jenkins/sonarqube/bin/linux-x86-64
./sonar.sh start

6. 安装sonar插件

sonar有很多插件,安装插件只需要将插件下载到extensions/plugins目录下然后重启sonar就可以了<br/> 安装汉化插件

cd /data/jenkins/sonarqube/extensions/plugins
wget https://github.com/SonarQubeCommunity/sonar-l10n-zh/releases/download/sonar-l10n-zh-plugin-1.11/sonar-l10n-zh-plugin-1.11.jar

重启sonarqube

cd /data/jenkins/sonarqube/bin/linux-x86-64
./sonar.sh restart

7. 安装 Sonar Scanner

cd /data/jenkins
wget https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-2.6.0.zip
unzip sonar-scanner-2.6.0.zip
ln -s /data/jenkins/sonar-scanner-2.6.0/ /data/jenkins/sonar-scanner

8. 配置sonar-scanner

# vim /usr/local/sonar-scanner/conf/sonar-scanner.properties
sonar.host.url=http://localhost:9000
sonar.sourceEncoding=UTF-8

Sonar安装

相关推荐