CentOS6 安装sonarsource并检测java、php项目的代码质量

前端之家收集整理的这篇文章主要介绍了CentOS6 安装sonarsource并检测java、php项目的代码质量前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

CentOS6 安装sonarsource

wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-6.5.zip -P /usr/local/src
  • 安装环境准备

CentOS6 + OpenJDK8 + MysqL7
  • 安装jdk

sudo yum install java-1.8.0-openjdk -y

参考安装MysqLhttp://blog.csdn.net/wh211212...

CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci; 
GRANT ALL PRIVILEGES ON sonar.* TO 'sonar'@'127.0.0.1' IDENTIFIED BY '@Aniusonar..0';
FLUSH PRIVILEGES
  • 解压sonar到/opt

sudo yum install unzip -y
cd /usr/local/src
unzip sonarqube-6.5.zip -d /opt/
cd /opt && mv sonarqube-6.5 sonarqube
  • 更改sonar启动的jvm参数,避免启动报错

cd /opt/sonarqube/conf/
# 编辑sonar.properties
sonar.web.javaOpts=-Xmx4G -Xms2G -XX:MaxMetaspaceSize=256M -XX:+HeapDumpOnOutOfMemoryError
# 编辑wrapper.conf
wrapper.java.initmemory=64 
wrapper.java.maxmemory=128
  • 启动sonar

cd /opt/sonarqube/bin/linux-x86-64/
./sonar.sh start
./sonar.sh stop
  • 配置Nginx反向代理sonar

server {
    listen       80;
    server_name  sonar.aniu.so; # 自定义
    access_log  /var/log/Nginx/sonar.aniu.so.access.log  main;
    error_log  /var/log/Nginx/error/sonar.aniu.so.error.log;

    location / {
        root   /opt/sonarqube;
        index  index.html index.htm index.PHP;
    }

    error_page  404              /404.html;

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/Nginx/html;
    }

    location ~ {
        proxy_pass   http://0.0.0.0:9009;
    }
}

默认登录用户名 admin 密码 admin

配置为自启动服务

  • 创建自启动脚本文件/etc/init.d/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 $*
# ln -s /opt/sonaruube/bin/linux-x86-64/sonar.sh /usr/bin/sonar
# chmod 755 /etc/init.d/sonar
# chkconfig --add sonar

测试java项目代码质量

# 启动到项目目录下
cd /var/lib/jenkins/workspace/gameoflife
# 执行下面命令
mvn clean verify sonar:sonar

检测PHP项目的代码质量

sonar.host.url=http://sonar.aniu.so
sonar.projectKey=org.codehaus.sonar:pc-dzcj
sonar.projectName=pc-dzcj test
sonar.projectVersion=1.0 
# 这里是PHP文件放的地方 
sonar.sources=/var/lib/jenkins/workspace/pc-dzcj/myweb
# Language 
sonar.language=PHP 
sonar.dynamicAnalysis=false 
# Encoding of the source files 
sonar.sourceEncoding=UTF-8

原文链接:https://www.f2er.com/centos/375930.html

猜你在找的CentOS相关文章