sonarqube+sonar-scanner部署

sonarqube7.3部署

环境

JDK1.8
mysql5.7
sonarqube7.3

配置JDK环境变量

我们使用sonar用户启动sonar,所以在sonar用户下配置

    su sonar
    vim ~/bash_profile
    export PATH
    export JAVA_HOME=/usr/local/jdk
    export PATH=$JAVA_HOME/bin:$PATH
    export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/rt.jar
    source ~/bash_profile

mysql配置

  • 创建用户
    create user 'sonar'@'%' identified by 'sonar'; 
  • 创建sonar数据库并授权
    create database sonar DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
    GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';
    GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
    FLUSH PRIVILEGES;   

部署步骤

  • 下载解压
    wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.3.zip
    unzip sonarqube-7.3.zip
    mv sonarqube-7.3 /usr/local/sonarqube
  • 添加普通用户
    useradd sonar
    passwd sonar
  • 修改文件用户
     chown -R sonar. /usr/local/sonarqube/
  • 修改sonar配置文件
    vim /usr/local/sonarqube/conf/sonar.properties
    # jdbc连接url
    sonar.jdbc.url=jdbc:mysql://192.168.20.28:3306/sonar?useUnicode=true&characterEncoding=utf8&useSSL=false 
    # 连接用户
    sonar.jdbc.username=sonar
    # 连接密码
    sonar.jdbc.password=sonar
    # web访问页面host
    sonar.web.host=0.0.0.0
    # web访问页面端口
    sonar.web.port=24008
  • 启动[由于启动es不能使用root用户,所以使用sonar启动]
    su sonar /usr/local/sonarqube/bin/sonar.sh start

sonar-scanner部署

  • 下载解压
    wget https://github.com/Kitware/CMake/releases/download/v3.16.0-rc2/cmake-3.16.0-rc2-Linux-x86_64.sh
  • 修改配置文件
    vim conf/sonar-scanner.properties
    sonar.host.url=http://192.168.20.31:24008
  • 加入环境变量
    vim /etc/profile
    export SONAR_SCANNER_HOME=/usr/local/sonar-scanner
    export PATH=$PATH:$SONAR_SCANNER_HOME/bin:PATH
    source /etc/profile
  • 验证
    [root@cn2031 bin]# sonar-scanner -h
    INFO: 
    INFO: usage: sonar-scanner [options]
    INFO: 
    INFO: Options:
    INFO:  -D,--define      Define property
    INFO:  -h,--help             Display help information
    INFO:  -v,--version          Display version information
    INFO:  -X,--debug            Produce execution debug output

你可能感兴趣的:(sonarqube+sonar-scanner部署)