sonar搭建

sonar是一个代码评测工具

基础环境:

  centos 7.4//MySQL 5.6/Oracle JDK 1.8

下载:

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

官方手册:

  https://docs.sonarqube.org/display/SONAR/Documentation/

linux上安装,需要确保:

  • vm.max_map_count 大于等于 262144
  • fs.file-max 大于等于 65536
  • 该进程文件描述符 最少 65536
  • 该进程能运行的线程数 最少 2048

查看办法:

  • sysctl vm.max_map_count
  • sysctl fs.file-max
  • ulimit -n
  • ulimit -u

设置办法(临时):

  • sysctl -w vm.max_map_count=262144
  • sysctl -w fs.file-max=65536
  • ulimit -n 65536
  • ulimit -u 2048

设置办法(永久):

  • 编辑/etc/security/limits.conf写入
  • *  soft  nproc   102400
    *  hard  nproc   102400
    *  soft  nofile  102400
    *  hard  nofile  102400
  • 编辑服务启动脚本$SONAR_HOME/bin/linux-x86-64/sonar.sh
  • [Service]
    LimitNOFILE=65536
    LimitNPROC=2048

步骤

  • 添加环境变量

export SONAR_HOME=/wdcloud/app/sonarqube-7.3

  • 添加数据库
CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL ON sonar. TO 'sonar'@'%' IDENTIFIED BY 'sonar';
FLUSH PRIVILEGES;
  • 使用数据库

编辑文件vi $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&useSSL=false

  • 添加用户,因为sonar自带的elasticsearch需要非root用户启动
useradd sonar.sonar

chown -R sonar.sonar /data/app/sonaqube-7.3
  • 添加服务
ln -s /cloud/app/sonarqube-7.3/bin/linux-x86-64/sonar.sh /etc/init.d/sonar
编辑/etc/init.d/sonar,加入下列几行
RUN_AS_USER=sonar
LimitNOFILE=65536
LimitNPROC=2048
  • 启动
service sonar start

runuser -l sonar -c "/cloud/app/sonarqube-7.3/bin/linux-x86-64/sonar.sh start"
  •  查看日志
$SONAR_HOME/logs/es.log      #elasticsearch日志
$SONAR_HOME/logs/sonar.log    #sonar启动日志
$SONAR_HOME/logs/access.log      #访问日志
原文地址:https://www.cnblogs.com/hinimix/p/9830424.html