美文网首页
SonarQube安装说明

SonarQube安装说明

作者: 企业信息化架构 | 来源:发表于2019-12-13 09:56 被阅读0次

    下载安装SonarQube

    a.建议使用sonarqube 6.5版本 ,因为sonarqube自带es ,版本大于6.5 的不支持root启动es,大于6.5可以通过创建其他用户启动es来解决这个问题

    b.如果出现更新中心不能访问的问题,建议自己下载中文插件包(需要对应版本号,否则无法启动),我的是6.5对应1.17版本

    https://www.sonarqube.org/downloads/

    下载后,解压文件

    unzip sonarqube-5.6.5.zip 
    

    将sonarqube移动到opt文件夹

    mv sonarqube-6.5 /root/sonar 
    

    编辑sonarqube的配置文件

    cd /root/sonar/sonarqube-6.5/conf 
    vi sonar.properties 
    

    修改mysql的数据库连接

    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&useSSL=false
    

    修改sonarqube的web配置

    sonar.web.host=0.0.0.0 
    sonar.web.context=/sonar
    sonar.web.port=9000 
    

    编辑防火墙

     vi /etc/sysconfig/iptables
    

    打开端口

    -A INPUT -m state --state NEW -m tcp -p tcp --dport 9000 -j ACCEPT
    
    /etc/init.d/iptables restart
    service iptables status
    

    最后,打开sonarqube服务

    /root/sonar/sonarqube-6.5/bin/linux-x86-64/sonar.sh start 
    

    第一次运行会初始化数据库,速度有些慢 ## 可以监听sonarqube的日志查看具体信息

    tail -f sonar.log 
    

    浏览器中输入:http://10.2.5.99:9000/sonar/

    image.png

    配置SonarQube

    安装补丁

    image.png

    登录后,点击Administrators菜单; 点击System菜单; 点击Update Center菜单; 点击Available选项; 在黄色位置输出Chinese Pack(中文插件); 在最右边有Install的按钮;

    如果无法安装的话,直接下载jar安装

    下载汉化工程:https://github.com/SonarQubeCommunity/sonar-l10n-zh,并编译(maven),生成jar文件,将其放在./extensions/plugins/目录下再启动SonarQube即可 备注:安装插件,按照上面的流程,可以把CheckStyle和PMD插件也都安装了,然后重启sonarqube系统。

    idea使用篇

    image.png

    2.点击图中第二个框起来的选项,在搜索框中输入sonar,出现一下界面


    image.png

    3.选择SonarLint,点击Install安装


    image.png

    4.安装完毕,点击Restart InteliJ IDEA


    image.png

    5.在maven中配置sonar:打开setting.xml配置文件,在其中加入如下代码:

    <profiles> 
        <profile> <!-- maven指令:mvn sonar:sonar -->
            <id>sonar</id> 
            <activation> 
                <activeByDefault>true</activeByDefault> 
            </activation> 
            <properties> 
                <sonar.jdbc.url>jdbc:mysql://10.2.5.99:3306/sonar?characterEncoding=utf8</sonar.jdbc.url>
                <sonar.jdbc.driver>com.mysql.jdbc.Driver</sonar.jdbc.driver> 
                <sonar.jdbc.username>root</sonar.jdbc.username> 
                <sonar.jdbc.password>root</sonar.jdbc.password> 
                <sonar.host.url>http://10.2.5.99:9000//sonar/</sonar.host.url> 
            </properties> 
         </profile> 
     </profiles>
    

    6.然后项目中就如出现如图所示,就能分析文件中的代码质量了


    image.png

    相关文章

      网友评论

          本文标题:SonarQube安装说明

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