linuxea:sonarqube-6.5_2代码质量管理系统配置和汉化


I. SonarQube简介

SonarQube是一个用于代码质量管理的开源平台,用于管理Java源代码的质量。通过插件机制,SonarQube可以集成不同的测试工具,代码分析工具,以及持续集成工具,比如pmd-cpd、checkstyle、findbugs、Jenkins。通过不同的插件对这些结果进行再加工处理,通过量化的方式度量代码质量的变化,从而可以方便地对不同规模和种类的工程进行代码质量管理。同时 SonarQube还对大量的持续集成工具提供了接口支持,可以很方便地在持续集成中使用 SonarQube。此外,SonarQube的插件还可以对 Java 以外的其他编程语言提供支持,对国际化以及报告文档化也有良好的支持
参考:https://docs.sonarqube.org/display/SONAR/Documentation/

II. 为什么要使用6.5

在pipeline的集成中需要6版本的支持
Pause pipeline until quality gate is computed
The waitForQualityGate step will pause the pipeline until SonarQube analysis is completed and returns quality gate status.
Pre-requisites:
SonarQube server 6.2+ (need webhook feature)
Configure a webhook in your SonarQube server pointing to <your Jenkins instance>/sonarqube-webhook/ (info) The trailing slash is mandatory with SonarQube 6.2 and 6.3!
Use withSonarQubeEnv step in your pipeline (so that SonarQube taskId is correctly attached to the pipeline context).
参考:https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Jenkins
恰巧有人已经发布过,借鉴:https://testerhome.com/topics/10064

安装数据库,这里需要5.6的数据库,之前没有,这里需要安装最新的

III. install mariadb

[root@linuxea.com-Node114 ~]# axel -n 50 http://mirror.poliwangi.ac.id/mariadb//mariadb-10.2.8/bintar-linux-x86_64/mariadb-10.2.8-linux-x86_64.tar.gz
[root@linuxea.com-Node114 ~]# tar xf mariadb-10.2.8-linux-x86_64.tar.gz -C /usr/local
[root@linuxea.com-Node114 ~]# useradd mysql -s /sbin/nologin -M
[root@linuxea.com-Node114 ~]# cd /usr/local
[root@linuxea.com-Node114 /usr/local]# ln -s mariadb-10.2.8-linux-x86_64 mysql && cd mysql
[root@linuxea.com-Node114 /usr/local/mysql ]# mkdir /data/mysql -p 
[root@linuxea.com-Node114 /usr/local/mysql ]# chown mysql.mysql /data/mysql
[root@linuxea.com-Node114 /usr/local]# ./mysql/scripts/mysql_install_db --datadir=/data/mysql --basedir=/usr/local/mysql --user=mysql
Installing MariaDB/MySQL system tables in '/data/mysql' ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

'/usr/local/mysql/bin/mysqladmin' -u root password 'new-password'
'/usr/local/mysql/bin/mysqladmin' -u root -h linuxea.com-Node114.cluster.com password 'new-password'

Alternatively you can run:
'/usr/local/mysql/bin/mysql_secure_installation'

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '/usr/local/mysql' ; /usr/local/mysql/bin/mysqld_safe --datadir='/data/mysql'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/local/mysql/mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/

配置:

[root@linuxea.com-Node114 /usr/local]# cp mysql/support-files/mysql.server /etc/init.d/mysqld
[root@linuxea.com-Node114 /usr/local]# chmod +x /etc/init.d/mysqld
[root@linuxea.com-Node114 /usr/local]# cp mysql/support-files/my-large.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
[root@linuxea.com-Node114 /usr/local]# vim /etc/my.cnf

添加:

[mysqld]
datadir=/data/mysql
basedir=/usr/local/mysql  
query_cache_siz=16M

启动和授权

[root@linuxea.com-Node114 /usr/local]# /etc/init.d/mysqld start
Reloading systemd:                                         [  确定  ]
Starting mysqld (via systemctl):                           [  确定  ]
[root@linuxea.com-Node114 /usr/local]# ln -s /usr/local/mariadb-10.2.8-linux-x86_64/bin/mysql /usr/bin/mysql
[root@linuxea.com-Node114 /usr/local]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.2.8-MariaDB-log MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.05 sec)

MariaDB [(none)]> CREATE USER 'sonar' IDENTIFIED BY 'sonar';
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> GRANT ALL ON sonar.* TO 'sonar'@'10.10.0.98' IDENTIFIED BY 'sonar';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> 

IV. install sonarqube-6.5_2

下载地址https://www.sonarqube.org/downloads/

[root@linuxea.com-Node113 ~]# unzip sonarqube-6.5_2.zip 
[root@linuxea.com-Node113 ~]# mv sonarqube-6.5 /usr/local/sonarqube
[root@linuxea.com-Node113 ~]# cd /usr/local/sonarqube

修改配置文件

sed -i 's/#sonar.jdbc.username=/sonar.jdbc.username=sonar/g' /usr/local/sonarqube/conf/sonar.properties
sed -i 's/#sonar.jdbc.password=/sonar.jdbc.password=sonar/g' /usr/local/sonarqube/conf/sonar.properties
echo 'sonar.jdbc.url=jdbc:mysql://127.0.0.1:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance' >> /usr/local/sonarqube/conf/sonar.properties
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

最终如下:

[root@linuxea.com-Node114 /usr/local/sonarqube]# egrep -v "^#|^$" conf/sonar.properties 
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.web.host=0.0.0.0
sonar.web.port=888
sonar.web.context=/sonar
sonar.embeddedDatabase.port=9092
sonar.jdbc.url=jdbc:mysql://127.0.0.1:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false

启动测试

[root@linuxea.com-Node113 /usr/local/sonarqube]# ./bin/linux-x86-64/sonar.sh start
Starting SonarQube...
Started SonarQube.
[root@linuxea.com-Node113 /usr/local/sonarqube]# 


启动脚本

[root@linuxea.com-Node114 /usr/local/sonarqube]# ln -s /usr/local/sonarqube/bin/linux-x86-64/sonar.sh /etc/init.d/sonar
[root@linuxea.com-Node114 /usr/local/sonarqube]# chmod +x /etc/init.d/sonar
[root@linuxea.com-Node114 /usr/local/sonarqube]# /etc/init.d/sonar start
Starting SonarQube...
SonarQube is already running.
[root@linuxea.com-Node114 /usr/local/sonarqube]# /etc/init.d/sonar restart
Stopping SonarQube...
Stopped SonarQube.
Starting SonarQube...
Started SonarQube.
[root@linuxea.com-Node114 /usr/local/sonarqube]# 

V. 汉化

下载jar包到/usr/local/sonarqube/extensions/plugins下重启即可

[root@linuxea.com-Node114 /usr/local/sonarqube/extensions/plugins]# wget https://github.com/SonarQubeCommunity/sonar-l10n-zh/releases/download/sonar-l10n-zh-plugin-1.17/sonar-l10n-zh-plugin-1.17.jar
[root@linuxea.com-Node114 /usr/local/sonarqube/extensions/plugins]# /etc/init.d/sonar restart
Stopping SonarQube...
Stopped SonarQube.
Starting SonarQube...
Started SonarQube.

再看已经汉化成功

2 分享

您可以选择一种方式赞助本站

支付宝扫码赞助

支付宝扫码赞助

日期: 2017-09-23分类: 持续集成

标签: sonarqube, devops

发表评论