温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

MySQL5.7+SonarQube7.4+SonarScanner4.2安装与使用

发布时间:2020-06-09 19:10:17 来源:网络 阅读:611 作者:清风与你 栏目:软件技术

一、系统环境:
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.安装
安装前检查服务器是否已安装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应该已经安装成功。
3.环境变量配置
1)启动MySQL:service mysqld start
MySQL5.7+SonarQube7.4+SonarScanner4.2安装与使用
(图片源自网络,侵删)
2)登录:mysql -u root -p,初次登录密码为空,直接回车:
MySQL5.7+SonarQube7.4+SonarScanner4.2安装与使用

为什么会出现这个错误,原因是因为MySQL5.7中的mysql.user 表中没有Password字段,所以要以安全方式登录,然后修改密码。
解决方法如下:
修改MySQL配置文件:vim /etc/my.cnf,在文件末尾加上:skip-grant-tables,保存后重启MySQL服务:service mysqld restart,然后重新登录。

MySQL5.7+SonarQube7.4+SonarScanner4.2安装与使用

3)修改密码,用户密码是在名为mysql的database下面:
依次执行以下指令:

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配置文件之前加的跳过密码检测内容去掉,重启服务;

5)创建数据库并授权(为下面的SonarQube做准备)
MySQL5.7+SonarQube7.4+SonarScanner4.2安装与使用

MySQL配置完成。

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

2.修改环境变量

[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

配置完成后启动即可,启动文件:

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

启动完成后显示如下信息证明启动成功。
MySQL5.7+SonarQube7.4+SonarScanner4.2安装与使用

访问链接:http://localhost:9000/ ,默认用户名密码:admin/admin

4.中文插件地址(注意安装版本要和sonar对应):
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.修改环境变量
环境变量→系统变量→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.在要分析的项目根目录下添加sonar-project.properties文件
MySQL5.7+SonarQube7.4+SonarScanner4.2安装与使用
文件内容:

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.启动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问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI