SonarQube系列 目錄
- SonarQube (1) 基本環(huán)境搭建
- SonarQube (2) sonar runner安裝配置
- SonarQube (3) C++插件安裝與規(guī)則配置
- SonarQube (4) 運(yùn)行一個(gè)Sample
- SonarQube (5) 集成至Jenkins
- SonarQube (終) Gitlab提交代碼自動(dòng)化測(cè)試
環(huán)境
系統(tǒng): CentOS 7.1
數(shù)據(jù)庫(kù): PostgreSQL 9.2.18 (環(huán)境搭建見(jiàn):CentOS7下PostgreSQL搭建與配置)
SonarQube下載
移步官網(wǎng),下載SonarQube-version.zip
Postgres 配置
創(chuàng)建sonar用戶
切換到postgres用戶
$ su postgres
創(chuàng)建sonar用戶
$ createuser -P -s -e sonar
創(chuàng)建sonar數(shù)據(jù)庫(kù)
連接數(shù)據(jù)庫(kù)
$ psql
創(chuàng)建sonar數(shù)據(jù)庫(kù)
create database sonar owner=sonar;
查看創(chuàng)建后的數(shù)據(jù)庫(kù)
\l
Sonar配置
解壓
將sonarqube
壓縮包解壓至 /etc/sonar
修改sql連接配置
打開(kāi)sonar.properties
# vi /etc/sonar/conf/sonar.properties
設(shè)置如下內(nèi)容
sonar.jdbc.username=sonar
sonar.jdbc.password=YOUR_PASSWORD
sonar.jdbc.url=jdbc:postgresql://localhost/sonar
sonar.web.javaOpts=-server
啟動(dòng)Sonar服務(wù)
注意:必須在普通用戶下啟動(dòng)Sonar聪建!
$ /etc/sonarqube/bin/[OS]/sonar.sh console
訪問(wèn)Sonar頁(yè)面
localhost:9000
將Sonar作為服務(wù)啟動(dòng)
添加服務(wù)啟動(dòng)腳本
新建/etc/init.d/sonar
# vi /etc/init.d/sonar
添加如下內(nèi)容
#!/bin/sh
#
# rc file for SonarQube
#
# chkconfig: 345 96 10
# description: SonarQube system (www.sonarsource.org)
#
### BEGIN INIT INFO
# Provides: sonar
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: SonarQube system (www.sonarsource.org)
# Description: SonarQube system (www.sonarsource.org)
### END INIT INFO
/usr/bin/sonar $*
設(shè)置隨系統(tǒng)啟動(dòng)
$ sudo ln -s /etc/sonarqube-5.6.7/bin/linux-x86-64/sonar.sh /usr/bin/sonar
$ sudo chmod 755 /etc/init.d/sonar
$ sudo chkconfig --add sonar
重啟Sonar服務(wù)
# service sonar restart