溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

MySQL5.7+SonarQube7.4+SonarScanner4.2安裝與使用

發(fā)布時(shí)間:2020-06-09 19:10:17 來(lái)源:網(wǎng)絡(luò) 閱讀:633 作者:清風(fēng)與你 欄目:軟件技術(shù)

一、系統(tǒng)環(huán)境:
RedHat6.4(JDK1.8+MySQL5.7.12+SonarQube7.4),win10(SonarScanner4.2)

二、安裝并配置MySQL
1.下載
http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar
2.安裝
安裝前檢查服務(wù)器是否已安裝MySQL,如已安裝則將其卸載:

[root@otms_mq04 ~]# rpm -qa|grep mysql
mysql-libs-5.1.71-1.el6.x86_64
[root@otms_mq04 ~]# rpm -e --nodeps mysql-libs-5.1.66-2.el6_3.x86_64

將下載的文件解壓:

[root@otms_mq04 ~]# tar -xf mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar
[otms@otms_mq04 software]$ ll
total 960712
-rw-r--r-- 1 otms otms 457492480 Dec 2 11:17 mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar
-rw-r--r-- 1 otms otms 23672176 Mar 29 2016 mysql-community-client-5.7.12-1.el6.x86_64.rpm
-rw-r--r-- 1 otms otms 334040 Mar 29 2016 mysql-community-common-5.7.12-1.el6.x86_64.rpm
-rw-r--r-- 1 otms otms 3765324 Mar 29 2016 mysql-community-devel-5.7.12-1.el6.x86_64.rpm
-rw-r--r-- 1 otms otms 38736700 Mar 29 2016 mysql-community-embedded-5.7.12-1.el6.x86_64.rpm
-rw-r--r-- 1 otms otms 133956388 Mar 29 2016 mysql-community-embedded-devel-5.7.12-1.el6.x86_64.rpm
-rw-r--r-- 1 otms otms 2174152 Mar 29 2016 mysql-community-libs-5.7.12-1.el6.x86_64.rpm
-rw-r--r-- 1 otms otms 1720844 Mar 29 2016 mysql-community-libs-compat-5.7.12-1.el6.x86_64.rpm
-rw-r--r-- 1 otms otms 149101172 Mar 29 2016 mysql-community-server-5.7.12-1.el6.x86_64.rpm
-rw-r--r-- 1 otms otms 104017276 Mar 29 2016 mysql-community-test-5.7.12-1.el6.x86_64.rpm

按照順序依次安裝:

  1. rpm -ivh mysql-community-common-5.7.12-1.el6.x86_64.rpm
  2. rpm -ivh mysql-community-libs-5.7.12-1.el6.x86_64.rpm
  3. rpm -ivh mysql-community-devel-5.7.12-1.el6.x86_64.rpm
  4. rpm -ivh mysql-community-client-5.7.12-1.el6.x86_64.rpm
  5. rpm -ivh mysql-community-server-5.7.12-1.el6.x86_64.rpm

不出意外,MySQL應(yīng)該已經(jīng)安裝成功。
3.環(huán)境變量配置
1)啟動(dòng)MySQL:service mysqld start
MySQL5.7+SonarQube7.4+SonarScanner4.2安裝與使用
(圖片源自網(wǎng)絡(luò),侵刪)
2)登錄:mysql -u root -p,初次登錄密碼為空,直接回車(chē):
MySQL5.7+SonarQube7.4+SonarScanner4.2安裝與使用

為什么會(huì)出現(xiàn)這個(gè)錯(cuò)誤,原因是因?yàn)镸ySQL5.7中的mysql.user 表中沒(méi)有Password字段,所以要以安全方式登錄,然后修改密碼。
解決方法如下:
修改MySQL配置文件:vim /etc/my.cnf,在文件末尾加上:skip-grant-tables,保存后重啟MySQL服務(wù):service mysqld restart,然后重新登錄。

MySQL5.7+SonarQube7.4+SonarScanner4.2安裝與使用

3)修改密碼,用戶密碼是在名為mysql的database下面:
依次執(zhí)行以下指令:

mysql> use mysql
mysql> update user set password_expired='N' where user='root’;
mysql> update user set authentication_string=password('root') where user=‘root’;
mysql> flush privileges;

4)注意:一定要將my.cnf配置文件之前加的跳過(guò)密碼檢測(cè)內(nèi)容去掉,重啟服務(wù);

5)創(chuàng)建數(shù)據(jù)庫(kù)并授權(quán)(為下面的SonarQube做準(zhǔn)備)
MySQL5.7+SonarQube7.4+SonarScanner4.2安裝與使用

MySQL配置完成。

三、安裝并配置SonarQube
1.下載
https://www.sonarqube.org/downloads/

2.修改環(huán)境變量

[root@otms_mq04 ~]# vim /etc/profile
export SONAR_HOME=/home/sonarqube-7.4
[root@otms_mq04 ~]# source /etc/profile

3.修改配置文件

../sonarqube-7.4/conf/sonar.properties

添加以下配置:

sonar.jdbc.username=Sonar
sonar.jdbc.password=Sonar
sonar.jdbc.url=jdbc:mysql://ip:3306/Sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
sonar.web.host=0.0.0.0
sonar.web.port=9000

配置完成后啟動(dòng)即可,啟動(dòng)文件:

../sonarqube-7.4/bin/linux-x86-64/sonar.sh

啟動(dòng)完成后顯示如下信息證明啟動(dòng)成功。
MySQL5.7+SonarQube7.4+SonarScanner4.2安裝與使用

訪問(wèn)鏈接:http://localhost:9000/ ,默認(rèn)用戶名密碼:admin/admin

4.中文插件地址(注意安裝版本要和sonar對(duì)應(yīng)):
https://github.com/SonarQubeCommunity/sonar-l10n-zh/releases/tag/sonar-l10n-zh-plugin-1.24

四、安裝并配置SonarScanner

1.下載:
https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/

2.修改環(huán)境變量
環(huán)境變量→系統(tǒng)變量→Path→新建→scanner路徑(C:\Software\sonar-scanner-cli-4.2.0.1873-windows\sonar-scanner-4.2.0.1873-windows\bin)→保存退出

3.修改配置文件

C:\Software\sonar-scanner-cli-4.2.0.1873-windows\sonar-scanner-4.2.0.1873-windows\conf\sonar-scanner.properties

#Configure here general information about the environment, such as SonarQube server connection details for example
#No information about specific project should appear here

#----- Default SonarQube server
#sonar.host.url=http://localhost:9000

#----- Default source code encoding
#sonar.sourceEncoding=UTF-8

4.在要分析的項(xiàng)目根目錄下添加sonar-project.properties文件
MySQL5.7+SonarQube7.4+SonarScanner4.2安裝與使用
文件內(nèi)容:

sonar.projectKey=OTMS_UDA_AUTOMATION_TEST

sonar.jdbc.url=jdbc:mysql://ip:3306/Sonar?useUnicode=true&characterEncoding=utf8

sonar.jdbc.username=Sonar
sonar.jdbc.password=Sonar

sonar.login=admin
sonar.password=admin

#sonar.projectName=My project

#sonar.projectVersion=1.0

#sonar.sources=.

sonar.sourceEncoding=UTF-8

5.啟動(dòng)SonarScanner分析代碼(此處命令以分析Python代碼為例)

sonar-scanner.bat -Dsonar.projectKey=OTMS_UDA_AUTOMATION_TEST -Dsonar.sources=C:\workspace\OTMS_UDA_AUTOMATION_TEST -Dsonar.host.url=http://ip:9000 -Dsonar.login=admin -Dsonar.password=admin

完成。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI