sonarqube6.7安装

时间:2024-10-18 18:35:29

1.下载sonar
https://www.sonarqube.org/#downloads

2.配置JDK1.8

3.centOS默认mysql版本为mariaDB
直接安装yum install mysql,据说可以替换mariaDB的版本

sonar自带数据库,但是会被提示

Embedded database should be used for evaluation purpose only
The embedded database will not scale, it will not support upgrading to newer versions of SonarQube, and there is no support for migrating your data out of it into a different database engine.

所以还是使用mysql比较好
这里要注意的是sonar不支持mysql5.5及以下版本

3.1升级mysql,使用rpm方式
删除原有的mariaDB
yum remove mysql mysql-*
查看已安装的软件:rpm -qa¦grep mysql
rpm方式
找到当前最新版本https://dev.mysql.com/downloads/mysql/
下载mysql
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar
解压
tar -xvf mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar 
依次执行(几个包有依赖关系,所以执行有先后)下面命令安装
[root@centos-linux ~]# rpm -ivh mysql-community-common-5.7.18-1.el7.x86_64.rpm 
[root@centos-linux ~]# rpm -ivh mysql-community-libs-5.7.18-1.el7.x86_64.rpm
[root@centos-linux ~]# rpm -ivh mysql-community-client-5.7.18-1.el7.x86_64.rpm 
[root@centos-linux ~]# rpm -ivh mysql-community-server-5.7.18-1.el7.x86_64.rpm

3.2升级mysql,使用yum方式
安装mysql的源
yum install http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
Yum install -y mysql-community-server
systemctl start mysqld.service

4.mysql 修改root账户密码
mysql5.6以后的版本安全机制增强了,临时密码只允许登录,不允许操作数据库,所以必须更改。

4.1先停止mysql服务

service mysqld stop

4.2先修改配置文件

vi /etc/my.cnf

# Disabling symbolic-links is recommended to prevent assorted security risks
skip-grant-tables #添加这句话,这时候登入mysql就不需要密码
symbolic-links=0

4.3.空密码登录mysql:

mysql -u root -p #输入命令回车进入,出现输入密码提示直接回车
4.4.设置mysql密码:

mysql> set password for root@localhost = password('123456');
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> flush privileges; #更新权限
Query OK, 0 rows affected (0.00 sec)
mysql> set password for root@localhost = password('123456'); or update user set authentication_string=PASSWORD("123456") where user="root";
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>flush privileges; #更新权限
mysql>quit; #退出
4.5 停止mysql服务, 恢复mysql配置

service mysqld stop 
4.6 vim /etc/my.cnf #修改配置文件
# Disabling symbolic-links is recommended to prevent assorted security risks
# skip-grant-tables # 注释掉这句话
symbolic-links=0
4.7启动mysql服务

service mysqld start

4.8 输入新密码登录
mysql -uroot -p 
4.9.设置mysql开机自启:

systemctl enable mysqld

5.mysql 添加sonar用户

mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci; 
mysql> CREATE USER 'sonar' IDENTIFIED BY 'sonar';
mysql> GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';
mysql> GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
mysql> FLUSH PRIVILEGES;

这里有个问题,新密码设置的时候如果设置的过于简单会报错:所以sonar这个密码应该是用不了了。根据需要自己修改吧

运行后提示Table ‘performance_schema.session_variables’ doesn’t exist
解决的方法是:mysql_upgrade -u root -p --force

6.解压sonar,这里用6.7版本

7.修改配置文件

vi /usr/local/sonarqube/conf/sonar.properties

取消如下选项的#注释并修改内容

sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

sonar.jdbc.username=sonar

sonar.jdbc.password=sonar

sonar.web.host=0.0.0.0

sonar.web.context=

sonar.web.port=9000

3.运行sonarqube目录下的./bin/linux-x86-64/sonar.sh start

sonar6.7版本已经不允许root用户直接登录了,所以登陆前要切换到其他linux用户

切换的用户要注意是否拥有该目录的权限

8.观察启动日志
tail -200f ./logs/sonar.log

9.打开防火墙的9000端口
firewall-cmd --permanent --add-port=9000/tcp
firewall-cmd --reload

10.访问sonar
http://localhost:9000/
可以看到页面了

11.登录
默认用户名admin,密码admin

12.安装中文补丁包
https://github.com/SonarQubeCommunity/sonar-l10n-zh

12.1下载sonar-l10n-zh-plugin-1.19.jar

12.2.将jar文件复制到Sonarqube主目录extensions/plugins文件夹内
12.3.重启Sonarqube服务

13.安装SonarQube Scanner

13.1.下载SonarQube Scanner

https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner

13.2.解压

unzip sonar-scanner-cli-3.0.3.778-linux.zip

13.3.修改配置文件

修改conf/sonar-scanner.properties

如果没有和sonarqube安装在同一台服务器上,就需要修改,否则默认就可以了

sonar.host.url=http://localhost:9000