SonarQube

1.安装java(最新版本sonar需要至少JDK 1.8及以上版本)

[root@Centos7-1 ~]# yum -y install java

[root@Centos7-1 ~]# java -version

openjdk version "1.8.0_171"

OpenJDK Runtime Environment (build 1.8.0_171-b10)

OpenJDK 64-Bit Server VM (build 25.171-b10, mixed mode)

2.安装mysql数据库(这里使用mysql 5.7)


[https://dev.mysql.com/downloads/repo/yum/](https://dev.mysql.com/downloads/repo/yum/)

下载yum源,然后安装

[root@Centos7-1 ~]# rpm -ivh mysql80-community-release-el7-1.noarch.rpm

编辑yum库,开启5.7的yum源,关闭8.0

[root@Centos7-1 ~]# vim /etc/yum.repos.d/mysql-community.repo

# Enable to use MySQL 5.7

[mysql57-community]

name=MySQL 5.7 Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql80-community]

name=MySQL 8.0 Community Server

baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/

enabled=0

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[root@Centos7-1 ~]# yum -y install mysql-community-client mysql-community-server

[root@Centos7-1 ~]# mysql --version

mysql Ver 14.14 Distrib 5.7.22, for Linux (x86_64) using EditLine wrapper

3.修改mysql配置,并启动

[root@Centos7-1 ~]# vim /etc/my.cnf

[mysqld]

validate-password=OFF #关闭复杂密码验证

max_allowed_packet=1024M #限制Server接受的数据包大小

#限制过小,会引起扫描结果无法上传到服务器

[root@Centos7-1 ~]# systemctl restart mysqld; systemctl enable mysqld

初始化数据库

初次安装的mysql密码在/var/log/mysql.log里面

[root@Centos7-1 ~]# cat /var/log/mysqld.log | grep password

2018-06-14T06:15:31.925974Z 1 [Note] A temporary password is generated for root@localhost: c;G5_ldQkI1I

[root@Centos7-1 ~]# mysql_secure_installation

4.创建sonar数据库及用户

[root@Centos7-1 ~]# mysql -u root -p123

mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;

mysql> GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';

mysql> FLUSH PRIVILEGES;

5.下载sonarqube(这里使用的sonarqube 7.1版本)

https://www.sonarqube.org/

解压压缩包到/usr/local/sonarqube-7.1

[root@Centos7-1 ~]# unzip sonarqube-7.1.zip -d /usr/local/sonarqube

6.修改sonarqube配置文件

[root@Centos7-1 ~]# vim /usr/local/sonarqube-7.1/conf/sonar.properties

sonar.jdbc.username=sonar

sonar.jdbc.password=sonar #去掉注释添加数据库账号密码

sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false #去掉注释

sonar.web.host=0.0.0.0 #去掉注释

sonar.web.port=9000 #去掉注释

:wq!

7.启动sonarqube

创建一个新用户(由于elasticsearch默认不能以root身份启动)

[root@Centos7-1 ~]# useradd sonar

[root@Centos7-1 ~]# passwd sonar

Changing password for user sonar.

New password:

BAD PASSWORD: The password is shorter than 8 characters

Retype new password:

passwd: all authentication tokens updated successfully.

[root@Centos7-1 ~]# chown -R sonar.sonar /usr/local/sonarqube-7.1/

[root@Centos7-1 ~]# su - sonar

[sonar@Centos7-1 ~]$ /usr/local/sonarqube-7.1/bin/linux-x86-64/sonar.sh start

Starting SonarQube...

Started SonarQube.

查看服务是否启动

[sonar@Centos7-1 ~]$ netstat -lntp

(Not all processes could be identified, non-owned process info

will not be shown, you would have to be root to see it all.)

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp 0 0 127.0.0.1:32000 0.0.0.0:* LISTEN 2685/java

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN -

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -

tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN -

tcp6 0 0 :::9000 :::* LISTEN 2813/java

tcp6 0 0 127.0.0.1:9001 :::* LISTEN 2710/java

tcp6 0 0 :::3306 :::* LISTEN -

tcp6 0 0 :::80 :::* LISTEN -

tcp6 0 0 127.0.0.1:44757 :::* LISTEN 2875/java

tcp6 0 0 :::22 :::* LISTEN -

tcp6 0 0 ::1:25 :::* LISTEN -

8.访问页面http://192.168.1.196:9000 默认账号密码为admin admin

SonarQube_第1张图片

SonarQube_第2张图片

你可能感兴趣的:(SonarQube)