速云科技

Sonar(Code Review) 部署

1.安装MySQL数据库

[root@sonar ~]# yum install -y mysql-server

[root@sonar ~]# /bin/cp /usr/share/mysql/my-large.cnf /etc/my.cnf

[root@sonar ~]# /etc/init.d/mysqld start

[root@sonar ~]#vim /etc/my.cnf

[mysqld]
default-storage-engine = innodb
Innodb_file_per_table
collation-server = utf8_general_ci
init-connect = ‘SET NAMES utf8’
character-set-server = utf8

mysql> create database sonar;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on sonar.* to sonar@localhost identified by ‘snoar’;
Query OK, 0 rows affected (0.00 sec)

2.安装JDK

[root@sonar src]# tar zxf jdk-7u71-linux-x64.tar.gz

[root@sonar src]# mv jdk1.7.0_71/ /usr/local/jdk

[root@ops-node1 ~]# vim /etc/profile

export JAVA_HOME=/usr/local/jdk
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

[root@ops-node1 ~]# source /etc/profile

[root@sonar ~]# java -version
java version “1.7.0_71”
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

3.安装Sonar

[root@sonar ~]# cd /usr/local/src
[root@sonar src]# wget http://dist.sonar.codehaus.org/sonarqube-4.5.1.zip

[root@sonar src]# unzip sonarqube-4.5.1.zip

[root@sonar src]# mv sonarqube-4.5.1 /usr/local/

[root@sonar ~]# cd /usr/local/sonarqube-4.5.1/

[root@sonar sonarqube-4.5.1]# vim 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.web.host=0.0.0.0

sonar.web.port=80

[root@sonar ~]# vim /usr/local/sonarqube-4.5.1/conf/wrapper.conf

4.启动Sonar

[root@sonar ~]# vim /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 $*
[root@sonar ~]# chmod 755 /etc/init.d/sonar
[root@sonar ~]# chkconfig –add sonar
[root@sonar ~]# chkconfig sonar on
5.安装Sonar-Runner
[root@sonar src]# wget http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip
[root@sonar src]# unzip sonar-runner-dist-2.4.zip
[root@sonar src]# mv sonar-runner-2.4/ /usr/local/
[root@sonar src]# vim /usr/local/sonar-runner-2.4/conf/sonar-runner.properties
sonar.host.url=http://192.168.99.223:80
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.login=admin
sonar.password=admin
[root@sonar ~]# vim /root/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/sonar-runner-2.4/bin/
[root@sonar ~]# source .bash_profile
[root@sonar ~]#  sonar-runner -h
INFO:
INFO: usage: sonar-runner [options]
INFO:
INFO: Options:
INFO:  -D,–define <arg>     Define property
INFO:  -e,–errors           Produce execution error messages
INFO:  -h,–help             Display help information
INFO:  -v,–version          Display version information
INFO:  -X,–debug            Produce execution debug output
6. 安装分析插件
1.访问Sonar。点击右上角Login。
2.点击Seetting-Update Center-

 

 

 

 

 

 

 

欢迎留言