美文网首页
Sonarqube 6.7代码质量管理平台安装

Sonarqube 6.7代码质量管理平台安装

作者: CoderMichael | 来源:发表于2022-03-24 08:47 被阅读0次

    Sonarqube官网
    [ http://www.sonarqube.org/ ]
    获取安装包,当前为sonarqube-6.7.zip

    请先看支持安装环境:

    • 软件依赖:Oracle JRE 8 or OpenJDK 8
    • 硬件要求:
    1. SonarQube 服务器需要至少 2GB 的 RAM 才能有效运行,并且需要 1GB 的可用 RAM 用于操作系统。

    2. 您需要的磁盘空间量取决于您使用 SonarQube 分析的代码量。例如,SonarCloud是 SonarQube的公共实例,有超过 3000 万行代码正在分析中,有 4 年的历史。SonarCloud 目前在Amazon EC2 m4.large实例上运行,使用大约 10 Gb 的驱动器空间。它处理 800 多个项目,大约有 300 万个未解决的问题。SonarCloud 在 PostgreSQL 9.5 上运行,它使用了大约 15Gb 的驱动器空间。

    3. SonarQube 必须安装在具有出色读写性能的硬盘上。最重要的是,“数据”文件夹包含 Elasticsearch 索引,当服务器启动并运行时,将在这些索引上完成大量 I/O。因此,出色的硬盘读写性能将对 SonarQube 服务器的整体性能产生很大影响。

    [ https://docs.sonarqube.org/6.7/Requirements.html ]

    Sonar介绍

    Sonar (SonarQube)是一个开源平台,用于管理源代码的质量。Sonar 不只是一个质量数据报告工具,更是代码质量管理平台。支持的语言包括:Java、PHP、C#、C、Cobol、PL/SQL、Flex 等。

    Sonar数据库创建

    CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
    CREATE USER 'sonar' IDENTIFIED BY 'sonar';
    GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';
    GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
    FLUSH PRIVILEGES;
    

    Sonar数据库配置

    设置SONAR_HOME 指向zip包的解压目录.
    修改文件 $SONAR_HOME/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
    sonar.jdbc.driverClassName=com.mysql.jdbc.Driver
    

    Sonar端口配置

    修改文件 $SONAR_HOME/conf/sonar.properties

    sonar.web.port=9000
    

    Sonar JDK配置

    修改文件 $SONAR_HOME/conf/wrapper.conf

    wrapper.java.command=/opt/test/lixr/jdk1.8.0_45/bin/java
    

    修改 ES 配置

    如果是CentOS 6 修改配置文件 $SONAR_HOME/elasticsearch/config/elasticsearch.yml

    # 在 Memory 配置下添加:
    bootstrap.system_call_filter: false
    

    否则回抛异常: unable to install syscall filter 具体可以查看issues
    https://github.com/elastic/elasticsearch/issues/22899

    修改系统配置

    修改/etc/sysctl.conf 文件,添加 “vm.max_map_count”设置,并执行:sysctl -p

    # 修改/etc/sysctl.conf 文件添加配置
    vm.max_map_count = 262144
    # 执行:
    sysctl -p
    

    修改vi /etc/security/limits.conf,添加:

    *        -       nofile         65536
    @apps    -       nproc          2048
    
    

    设置端口转发(80->9000),使用root用户执行

    iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 9000
    service iptables save
    chkconfig iptables on
    

    Sonar 启动

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

    Sonar自启动配置

    vi /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 $*
    

    执行:

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

    查看启动情况

    $SONAR_HOME/logs/sonar.log
    

    会自动创建数据库所需数据

    Sonar 访问

    http://localhost/
    默认密码:admin/admin

    可能的问题

    暂无

    相关文章

      网友评论

          本文标题:Sonarqube 6.7代码质量管理平台安装

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