1. 程式人生 > >sonar環境搭建

sonar環境搭建

optional ont link password 目錄 netstat ann utf aid

本文主要在Linux環境操作,Centos7.2

1.java 1.8.0安裝及環境變量配置

安裝及配置參考:

http://jingyan.baidu.com/article/d5c4b52bebcb64da570dc571.html

2.mysql:5.6.36安裝及配置

數據庫安裝采用二進制安裝mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz,參考如下

http://jingyan.baidu.com/article/a378c9609eb652b3282830fd.html

修改配置文件/etc/my.cnf
default-storage-engine=INNODB
innodb_buffer_pool_size=256M
innodb_log_file_size=256M
max_allowed_packet=100M
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

本地 Mysql 創建數據庫

CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
本地 Mysql 創建用戶並分配權限
CREATE USER ‘sonar‘ IDENTIFIED BY ‘sonar‘;
GRANT ALL PRIVILEGES ON *.* TO ‘sonar‘@‘%‘ IDENTIFIED BY ‘sonar‘ WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO ‘sonar‘@‘localhost‘ IDENTIFIED BY ‘sonar‘ WITH GRANT OPTION;
FLUSH PRIVILEGES;

3.sonar版本:6.5

下載地址:https://www.sonarqube.org/downloads/

unzip sonarqube-6.5.zip

修改配置文件/etc/profile

export SONAR_HOME=/usr/local/sonarqube-6.5

export PATH=/jboss/apache-jmeter-2.10/bin/:$JAVA_HOME/bin://usr/local/mysql5.6.36/bin:$SONAR_HOME/bin/linux-x86-64:$MAVEN_HOME/bin:$SONAR_SCANNER_HOME/bin:/u01/ant1.9.9/bin:$PATH

修改完成後,source /etc/profile
修改conf下配置文件

3.1、修改 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&useSSL=false
3.2 啟動服務

/usr/local/sonarqube-6.5/bin/linux-x86-64/目錄下

./sonar.sh start

查看是否啟動:netstat -pantu |grep 9000

http://localhost:9000登陸頁面,默認登陸admin,密碼:admin

4. 下載sonar-scanner3.0

添加環境變量:

export SONAR_SCANNER_HOME=/usr/local/sonar-scanner-3.0

export PATH=/jboss/apache-jmeter-2.10/bin/:$JAVA_HOME/bin://usr/local/mysql5.6.36/bin:$SONAR_HOME/bin/linux-x86-64:$MAVEN_HOME/bin:$SONAR_SCANNER_HOME/bin:/u01/ant1.9.9/bin:$PATH

5.代碼管理:svn,目前把需要掃描的下載到/u01/svn/目錄下
5.1.在src目錄下增加sonar-project.properites

# must be unique in a given SonarQube instance
sonar.projectKey=pcWeb
# this is the name displayed in the SonarQube UI
sonar.projectName=pcWeb
sonar.projectVersion=1.0

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional if sonar.modules is set.
# If not set, SonarQube starts looking for source code from the directory containing
# the sonar-project.properties file.
sonar.sources=.
sonar.java.binaries=.
sonar.language=java
# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
# Additional Parameters
sonar.my.propety=value
sonar.core.codeCoveragePlugin=jacoco
sonar.jacoco.reportPath=/u01/report/workspace/sonar/target
sonar.jcoco.itReportPath=/u01/report/workspace/sonar/target
sonar.dynamicAnalysis=reuseReports


6. 執行sonar-scanner

7. 進入http://localhost:9000頁面

技術分享

sonar環境搭建