Installation et utilisation de SonarQube

ps:

      SonarQube est une plateforme ouverte de gestion de la qualité du code, qui peut rapidement localiser les erreurs potentielles ou évidentes dans le code.

1. Préparez l'environnement

Centos7.5, jdk8 , mysql 5.6-5.7, sonarqube-7.8

Veuillez vous assurer que linux a installé jdk8 et a configuré les variables d'environnement;

Voici mon environnement de machine virtuelle: (ps: jdk, mysql a été installé)

[root@localhost ~]# mysql -V
mysql  Ver 14.14 Distrib 5.7.28, for Linux (x86_64) using  EditLine wrapper
[root@localhost ~]# java -version
java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)
[root@localhost ~]#  cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)

Une fois la base de données installée, vous devez créer une base de données, sonarQube, sonarQube utilise cette base de données dans le processus d'utilisation:

[root@localhost ~]# mysql -uroot -p
Enter password:
mysql> create database sonar charset=utf8;
Query OK, 1 row affected (0.00 sec)

2. Installez sonarQube

  2.1 Décompressez

  2.2 Configuration:

[root@localhost local]# cd sonarqube-7.8/
[root@localhost sonarqube-7.8]# ll
total 12
drwxr-xr-x. 6 root root   94 Jun 17  2019 bin
drwxr-xr-x. 2 root root   50 Jun 17  2019 conf
-rw-r--r--. 1 root root 7651 Jun 17  2019 COPYING
drwxr-xr-x. 2 root root   24 Jun 17  2019 data
drwxr-xr-x. 7 root root  131 Jun 17  2019 elasticsearch
drwxr-xr-x. 4 root root   40 Jun 17  2019 extensions
drwxr-xr-x. 6 root root  123 Jun 17  2019 lib
drwxr-xr-x. 2 root root   24 Jun 17  2019 logs
drwxr-xr-x. 2 root root   24 Jun 17  2019 temp
drwxr-xr-x. 7 root root 4096 Jun 17  2019 web
[root@localhost sonarqube-7.8]# cd conf/
[root@localhost conf]# ll
total 24
-rw-r--r--. 1 root root 20422 Jun 17  2019 sonar.properties
-rw-r--r--. 1 root root  3217 Jun 17  2019 wrapper.conf
[root@localhost conf]# vim sonar.properties
[root@localhost conf]# cd ..

Configurez sonar.properties:

# Mysql数据用户名
sonar.jdbc.username=root
sonar.jdbc.password=123456
# 配置mysql数据库
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?
useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=
maxPerformance&useSSL=false
# 设置sonar服务
sonar.web.host=0.0.0.0
sonar.web.context=/sonarqube
sonar.web.port=9000

 Remarque: Vous ne pouvez pas commencer avec l'utilisateur root en raison du problème de sécurité d'ElasticSearch, vous devez donc créer un nouvel utilisateur, donner à l'utilisateur des autorisations d'accès au fichier sonarQube, puis vous connecter avec l'utilisateur.

[root@localhost sonarqube-7.8]# su esuser
[esuser@localhost sonarqube-7.8]$ su root
Password:
[root@localhost sonarqube-7.8]# chown -R esuser.esuser /usr/local/sonarqube-7.8/
[root@localhost sonarqube-7.8]# ll
total 12
drwxr-xr-x. 6 esuser esuser   94 Jun 17  2019 bin
drwxr-xr-x. 2 esuser esuser   50 Mar 11 22:48 conf
-rw-r--r--. 1 esuser esuser 7651 Jun 17  2019 COPYING
drwxr-xr-x. 2 esuser esuser   24 Jun 17  2019 data
drwxr-xr-x. 7 esuser esuser  131 Jun 17  2019 elasticsearch
drwxr-xr-x. 4 esuser esuser   40 Jun 17  2019 extensions
drwxr-xr-x. 6 esuser esuser  123 Jun 17  2019 lib
drwxr-xr-x. 2 esuser esuser   24 Jun 17  2019 logs
drwxr-xr-x. 2 esuser esuser   24 Jun 17  2019 temp
drwxr-xr-x. 7 esuser esuser 4096 Jun 17  2019 web
[root@localhost sonarqube-7.8]# chmod 777 -R /usr/local/sonarqube-7.8/
[root@localhost sonarqube-7.8]# vim elasticsearch/config/elasticsearch.yml
[root@localhost sonarqube-7.8]# su esuser
[esuser@localhost sonarqube-7.8]$ cd bin
[esuser@localhost bin]$ ls
jsw-license  linux-x86-64  macosx-universal-64  windows-x86-64
[esuser@localhost bin]$ cd linux-x86-64/
[esuser@localhost linux-x86-64]$ ls
lib  sonar.sh  wrapper
[esuser@localhost linux-x86-64]$ ./sonar.sh start
Starting SonarQube...
Started SonarQube.

base de données mysql sonar cette bibliothèque, il y aura un grand nombre de tables.

Visitez le navigateur http://192.168.160.130:9000/sonarqube, comme indiqué dans la figure:

ps:

1. Sonar.web.context = / sonarqube dans le fichier de configuration sonar.properties est configuré après http://192.168.160.130:9000/sonarqube

sonarqube。

2. Connectez-vous avec admin / admin, la page aura ce menu d'administration. Si vous vous connectez sans compte ni mot de passe, vous ne le ferez pas.

Pièce jointe: sonar-l10n-zh

Par conséquent, téléchargez sonar-l10n-zh-plugin-1.28 .

[esuser@localhost plugins]$ pwd
/usr/local/sonarqube-7.8/extensions/plugins
[esuser@localhost plugins]$ wget https://github.com/SonarQubeCommunity/sonar-l10n-zh/releases/download/sonar-l10n-zh-plugin-1.28/sonar-l10n-zh-plugin-1.28.jar

 Téléchargez-le et redémarrez le sondeur.

[esuser@localhost linux-x86-64]$ ./sonar.sh restart
Gracefully stopping SonarQube...
Stopped SonarQube.
Starting SonarQube...
Started SonarQube.

 Revisitez: http://192.168.160.130:9000/sonarqube , la page est déjà en chinois.

 

3. Utilisez le plugin SonarQube Maven pour analyser le code

Dans le répertoire d'installation de maven: tel que: settings: xml dans D: \ Program Files (x86) \ apache-maven-3.3.9 \ conf, ajoutez le contenu suivant:

ps: ajouter à la balise <profiles> </ profiles>.

  <profile>
      <id>sonar</id>

      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>

      <properties>
        <sonar.host.url>http://192.168.160.130:9000/sonarqube</sonar.host.url>
      </properties>
    </profile>

Sous le chemin du projet, utilisez cmd et exécutez sonar mvn: sonar

 Attendez la fin de l'exécution. . . .

Rouvrez votre navigateur et visitez: http://192.168.160.130:9000/sonarqube/projects :

 

Publié 187 articles originaux · J'aime 146 · Visitez 490 000+

Je suppose que tu aimes

Origine blog.csdn.net/qq_37495786/article/details/104820420
conseillé
Classement