美文网首页
SonarQube 5.6.6安装和配置(云环境)

SonarQube 5.6.6安装和配置(云环境)

作者: darkranger | 来源:发表于2017-07-05 00:04 被阅读0次

安装准备

云环境

CentOS Linux release 7.3.1611 (Core)

JAVA

java version "1.8.0_111"    
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)    
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)

Mysql

Server version:  5.7.17 MySQL Community Server (GPL)

安装前检查Mysql配置

确认是否使用InnoDB引擎
可用下列命令来查看

mysql>show engines;

结果如下图


图1

修改配置文件/etc/my.cnf
加入以下内容

[mysqld]   
innodb_buffer_pool_size = 256M  
query_cache_type=1    
query_cache_size=32M

设置好之后,重启mysql服务

service mysqld restart

安装

下载

下载地址:http://www.sonarqube.org/downloads/
选择最新 LTS 版的 SonarQube 安装包(当前版本为 sonarqube-5.6.6.zip)
下载之后上传到云环境服务器,解压安装
我的云环境解压后路径如下图

图2

指定jdk1.8

解压后,打开conf目录,修改wrapper.conf文件,我的配置如下

# Path to JVM executable. By default it must be available in PATH.
# Can be an absolute path, for example:
#wrapper.java.command=/path/to/my/jdk/bin/java
wrapper.java.command=/home/jdk18111/bin/java

创建 Database

CREATE DATABASE sonar CHARACTER SET utf8 COLLATE  utf8_general_ci;

配置sonar.properties

conf目录下,修改sonar.properties

sonar.jdbc.username=root    
sonar.jdbc.password=自己密码    
#----- MySQL 5.x    
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance    
sonar.web.host=0.0.0.0    
sonar.web.context=/sonarqube    
sonar.web.port=9000    
# 启用 sonar.web.javaOpts 并添加 -server参数   
sonar.web.javaOpts=-server -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError

打开9000端口

vi /etc/sysconfig/iptables

添加

-A INPUT -m state --state NEW -m tcp -p tcp --dport 9000 -j ACCEPT

重启防火墙,使端口配置生效

service iptables restart

启动 SonarQube

第一次启动会自动建表和做相应的初始化

$SONAR_HOME/bin/linux-x86-64/sonar.sh start

浏览器中输入
http://172.104.119.101:9000/sonarqube
见到下图,即安装成功

图3

配置服务

创建文件 /etc/init.d/sonar

内容如下

#!/bin/sh
#
# rc file for SonarQube
#
# chkconfig: 345 96 10
# description: SonarQube system (www.sonarsource.org)
#
### BEGIN INIT INFO
# Provides: sonar
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: SonarQube system (www.sonarsource.org)
# Description: SonarQube system (www.sonarsource.org)
### END INIT INFO
/usr/bin/sonar $*

依次执行如下命令

ln -s $SONAR_HOME/bin/linux-x86-64/sonar.sh /usr/bin/sonar
chmod 755 /etc/init.d/sonar
chkconfig --add sonar

启动和停止服务

启动

service sonar start

停止

service sonar stop

重启

service sonar restart

注:第一次启动服务,可查看日志 /conf/sonar.log 观察进度,因为第一次会初始化数据库和相关配置,需要一段时间

配置Maven

settings.xml 文件

内容如下

<settings>
        <pluginGroups>
            <pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
        </pluginGroups>
        ....
        <profiles>
            <profile>
                <id>sonar</id>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
                <properties>
                    <sonar.host.url>
                    http://172.104.119.101:9000/sonarqube
                    </sonar.host.url>
                </properties>
            </profile>
        </profiles>
    </settings>

pom.xml 文件

每个java+maven项目的pom.xml文件配置内容如下

    <properties>
        .....   
        <sonar.language>java</sonar.language>
        <sonar.host.url>http://172.104.119.101:9000/sonarqube</sonar.host.url>
    </properties>
    ....
     <build>
        <plugins>
           ....
            <plugin>
                <groupId>org.sonarsource.scanner.maven</groupId>
                <artifactId>sonar-maven-plugin</artifactId>
                <version>3.3.0.603</version>
            </plugin>
        </plugins>
    </build>

运行

执行

mvn sonar:sonar -Dmaven.test.skip -U

mvn sonar:sonar -Dmaven.test.skip

运行后,部分结果如下图

图4
此时登录
http://172.104.119.101:9000/sonarqube
显示界面如下
图5

相关文章

网友评论

      本文标题:SonarQube 5.6.6安装和配置(云环境)

      本文链接:https://www.haomeiwen.com/subject/bhrfhxtx.html