CentOS安装SonarQube

System Version:CentOS release 6.7(Final)

1、下载SonarQube 和 Sonar-scanner

http://www.sonarqube.org/downloads/

当前下载版本Sonar-3.7.4.zip、Sonar-scanner-2.5.1.zip

2、新建安装目录mkdir /opt/sonar,上传zip至sonar目录

3、环境变量配置,在/etc/profile.d目录下新建sonar.sh文件

-----------------------------------------------------------------------

#!/bin/bash

SONAR_HOME=/opt/sonar/sonar-3.7.4

SONAR_RUNNER_HOME=/opt/sonar/sonar-scanner-2.5.1

PATH=$SONAR_RUNNER_HOME/bin:$PATH

export SONAR_HOME

export SONAR_RUNNER_HOME

export PATH

赋予执行权限

chmod +x /etc/profile.d/sonar.sh

source /etc/profile.d/sonar.sh

4、配置命令,在/etc/init.d/目录下新建sonar文件

-----------------------------------------------------------------------

#!/bin/sh

# chkconfig: -80 20

# Description: SONAR

/opt/sonar/sonar-3.7.4/bin/linux-x86-64/sonar.sh $*

exit $?

-----------------------------------------------------------------------

赋予执行权限

sudo ln -s $SONAR_HOME/bin/linux-x86-64/sonar.sh /usr/bin/sonar

sudo chmod 755 /etc/init.d/sonar

sudo chkconfig --add sonar

chmod +x /etc/init.d/sonar

-----------------------------------------------------------------------

设置开机启动

chkconfig sonar on

-----------------------------------------------------------------------

5、更改配置文件/opt/sonar/sonar-3.7.4/conf/sonar.properties

-----------------------------------------------------------------------

sonar.web.host:                           x.x.x.x

sonar.web.port:                           9000

sonar.jdbc.username:                  sonar

sonar.jdbc.password:                   sonar

sonar.jdbc.url:                              jdbc:h2:tcp://x.x.x.x:9092/sonar(Default)

sonar.embeddedDatabase.port:               9092

当前使用:192.168.2.42:10080

-----------------------------------------------------------------------

6、更改配置/opt/sonar/sonar-2.5.1/conf/sonar.properties

-----------------------------------------------------------------------

#----- Default SonarQube server

sonar.host.url=http://localhost:9000

#----- Default source code encoding

sonar.sourceEncoding=UTF-8

#----- Global database settings (not used for SonarQube 5.2+)

sonar.jdbc.username=sonar

sonar.jdbc.password=sonar

sonar.jdbc.url=jdbc:h2:tcp://localhost:9092/sonar(默认数据库)

sonar.login=admin

sonar.password=admin

-----------------------------------------------------------------------

7、启动SonarQube

# cd /opt/sonar/sonar-3.7.4/bin/linux-x86-64/

# ./sonar.sh start / restart / stop

8、SonarQube数据库配置

-----------------------------------------------------------------------

创建Sonar用户

#mysql -uroot -p$password

mysql>create user 'sonar'@'%'identified by 'sonar';

mysql>grant all on *.* to 'sonar'@'%' with grant option;

-----------------------------------------------------------------------

SonarQube配置

#vim /opt/sonar/sonar-3.7.4/conf/sonar.properties

#-----MySQL 5.x

soanr.jdbc.url : jdbc:mysql://192.168.2.42:3306/sonar?useUnicode=true&characterEndoding=utf&rewriteBatchedStatements=true

-----------------------------------------------------------------------

Sonar-Runner配置

# vim /opt/sonar/sonar-scanner-2.5.1/conf/sonar-runner.properties

#-----MySQL

sonar.jdbc.url = jdbc:mysql://192.168.2.42:3306/sonar?useUnicode=true&characterEndoding=utf8

-----------------------------------------------------------------------

重启SonarQube

-----------------------------------------------------------------------

备注:

1、使用sonar用户登录mysql,手工创建sonar数据库,否则SonarQube启动不了

2、由于更改了SonarQube的数据库配置(由默认的H2转至MySQL),进入SonarQube时需要使用以下地址:

http://192.168.2.42:11080/setup

此时会提示你手工设置,亲测没必要手工点击,静静等待1分钟即可自动完成数据库设置

-----------------------------------------------------------------------

猜你喜欢

转载自liusq.iteye.com/blog/2341885
今日推荐