安装代码审查工具

Posted by Xi Yang on September 6, 2017
安装Java
安装MySQL
安装Nginx
安装Sonar
  1. 下载

    a. 获取Sonar:wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-6.5.zip

    b. 获取Sonar Runner: wget https://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip

    c. 解压下载包,unzip sonarqube-6.5.zip unzip sonar-runner-dist-2.4.zip

  2. 配置

    a. 修改配置文件

     [root@localhost conf]# vim sonar.properties
     sonar.jdbc.username=root
     sonar.jdbc.password=123456
     sonar.sorceEncoding=UTF-8
     sonar.login=admin
     sonar.password=admin
     sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
     sonar.web.javaOpts=-Xmx768m -XX:MaxPermSize=160m -XX:+HeapDumpOnOutOfMemoryError
     sonar.web.host=0.0.0.0
     sonar.web.port=9000
    

    b. 创建sonar数据库依赖

     create database sonar default character set utf8;
    

    c. 配置nginx

         worker_processes  1;
         events {
             worker_connections  1024;
         }
         http {
             include       mime.types;
             default_type  application/octet-stream;
             #access_log  logs/access.log  main;
    
             sendfile        on;
    
             keepalive_timeout  65;
    
             server {
                 listen       8003;
                 server_name  localhost;
                 location / {
                     root   /usr/local/sonarqube-6.5/web;
                     index  index.html index.htm;
                     proxy_pass http://127.0.0.1:9000;
                 }
    
                 error_page   500 502 503 504  /50x.html;
                 location = /50x.html {
                     root   html;
                 }
             }
         }
    

    d. 添加环境变量

         export SONAR_HOME=/usr/local/sonarqube-6.5
         export SONAR_RUNNER_HOME=/usr/local/sonar-runner-2.4
    

    e. 修改防火墙开放端口: iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 9000 -j ACCEPT 或者关闭防火墙 service iptables stop(永久关闭防火墙步骤 chkconfig iptables off)

    f. 启动sonar

         [root@localhost linux-x86-64]# pwd
         /usr/local/sonarqube-4.5.4/bin/linux-x86-64
         [root@localhost linux-x86-64]# ls
         lib  sonar.sh  wrapper
         [root@localhost linux-x86-64]# ./sonar.sh start
         Starting SonarQube...
         Started SonarQube...
    

    ps 停止sonar使用命令 ./sonar.sh stop

    g. 可选择安装汉化包 方法1:按照下图的点击顺序,进入插件安装页面

    搜索chinese pack,安装中文语言包
    重启之后,会显示中文页面