Linux安装SonarQube和sonar-scanner详细安装及配置
生活随笔
收集整理的這篇文章主要介紹了
Linux安装SonarQube和sonar-scanner详细安装及配置
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
文章目錄
- 技術選型
- 一、快速入門
- 1.1 上傳、解壓、創(chuàng)建用戶、啟動
- 1.2 創(chuàng)建用戶(elasticsearch不能以root用戶啟動),并賦予權限
- 1.3 切換用戶,啟動SonarQube
- 1.4. 瀏覽器驗證
- 二、配置數(shù)據(jù)庫信息:
- 2.1 編輯sonar.properties文件
- 2.2 添加數(shù)據(jù)庫信息,用于啟動SonarQube時,創(chuàng)建表
- 2.3 案例演示
- 三、sonar-scanner安裝配置
- 3.1 上傳、解壓
- 3.2 配置環(huán)境變量
- 3.3 編輯配置文件,添加數(shù)據(jù)庫配置信息
- 四、上傳項目至掃描目錄+掃描項目
- 4.1 上傳項目
- 4.2 在項目根目錄下面創(chuàng)建sonar-project.properties配置文件
- 4.3 執(zhí)行掃描
技術選型
| 代碼分析 | sonarqube-7.6 |
| 掃描器 | sonar-scanner-cli-3.3.0.1492 |
| 漢化包 | sonar-l10n-zh-plugin-1.26.jar |
一、快速入門
1.1 上傳、解壓、創(chuàng)建用戶、啟動
通過filezilla.exe、Xftp 6工具進行上傳
解壓命令:
例如:
unzip aa.zip1.2 創(chuàng)建用戶(elasticsearch不能以root用戶啟動),并賦予權限
#創(chuàng)建用戶 useradd sonar passwd sonar #賦予權限 chown -R sonar.sonar /app/sonarqube-7.61.3 切換用戶,啟動SonarQube
#切換至sonar用戶下啟動sonar su sonar #啟動 SonarQube cd /app/sonarqube-7.6/bin/linux-x86-64 ./sonar.sh start1.4. 瀏覽器驗證
測試地址:
http://192.168.88.xx:9000
用戶名:admin
密碼:admin
二、配置數(shù)據(jù)庫信息:
2.1 編輯sonar.properties文件
cd /app/sonarqube-6.7.6/conf/ vim sonar.properties2.2 添加數(shù)據(jù)庫信息,用于啟動SonarQube時,創(chuàng)建表
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false sonar.jdbc.username=root sonar.jdbc.password=root sonar.sorceEncoding=UTF-8注:以上是以root用戶來進行連接的,如果不想用root用戶連接,可以添加用戶,并賦予權限
2.3 案例演示
創(chuàng)建用戶為sonar
用戶名:sonar
密碼:sonar123
賦予sonar權限
刷新權限
三、sonar-scanner安裝配置
3.1 上傳、解壓
略
3.2 配置環(huán)境變量
編輯全局配置文件profile: vim /etc/profile #配置sonar-scanner export SONAR_RUNNER_HOME=/app/sonar-scanner-3.3 $SONAR_RUNNER_HOME/bin3.3 編輯配置文件,添加數(shù)據(jù)庫配置信息
編輯/app/sonar-scanner-3.3/conf/sonar-scanner.properties
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false sonar.jdbc.username=root sonar.jdbc.password=root sonar.sorceEncoding=UTF-8 sonar.login=admin sonar.password=admin四、上傳項目至掃描目錄+掃描項目
4.1 上傳項目
略
4.2 在項目根目錄下面創(chuàng)建sonar-project.properties配置文件
# must be unique in a given SonarQube instance sonar.projectKey=項目名稱 # this is the name displayed in the SonarQube UI sonar.projectName=項目名稱 sonar.projectVersion=1.0 sonar.java.binaries=target/classes sonar.sources=掃描文件目錄注:target/classes 此文件夾只有編譯后,才會生成,默認無此目錄,也可以將此目錄替換為掃描的路徑即可!
4.3 執(zhí)行掃描
在sonar-project.properties所在目錄 也就是 項目根目錄 執(zhí)行sonar-scanner就可以掃描了
./sonar-scannerLinux環(huán)境
windows環(huán)境
效果圖:
總結
以上是生活随笔為你收集整理的Linux安装SonarQube和sonar-scanner详细安装及配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux环境安装并配置Maven
- 下一篇: 统计一个字符在另一个字符串中出现的次数