Centos 7环境安装SonarQube

SonarQube简介
Sonar 是一个用于代码质量管理的开放平台。通过插件机制,Sonar 可以集成不同的测试工具,代码分析工具,以及持续集成工具。比如pmd-cpd、checkstyle、findbugs、Jenkins。通过不同的插件对这些结果进行再加工处理,通过量化的方式度量代码质量的变化,从而可以方便地对不同规模和种类的工程进行代码质量管理。同时 Sonar 还对大量的持续集成工具提供了接口支持,可以很方便地在持续集成中使用 Sonar。
此外,Sonar 的插件还可以对 Java 以外的其他编程语言(支持的语言包括:Java、PHP、C#、C、Cobol、PL/SQL、Flex等)提供支持,对国际化以及报告文档化也有良好的支持。可以说Sonar是目前最强大的代码质量管理工具之一。
下面就来揭开Sonar的神秘面纱,看看如何在Centos环境上安装Sonar。
安装环境
系统环境:centos7.0 -x86_64(最小化安装) 
前置条件:jdk1.8 , mysql-5.6
软件下载目录:/usr/local/
软件安装目录:/usr/local/
软件版本:sonarqube-6.7,sonar-runner-dist-2.4 sonar-scanner-3.0.3.778
sonarqube下载地址:http://www.sonarqube.org/downloads/
sonar-runner下载地址:https://link.jianshu.com/?t=http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip
sonar-scanner下载扫描器地址:https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.0.3.778-linux.zip

预置条件
1, 需要JDK1.6+支持;
Centos 7环境安装SonarQube和SonarQube Runner
添加环境变量
[root@localhost java]# vim /etc/profile
Centos 7环境安装SonarQube和SonarQube Runner
JDK
export JAVA_HOME=/usr/java/jdk1.8.0_101
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
export TIME_STYLE='+%Y/%m/%d %H:%M:%S'
[root@localhost local]# source /etc/profile

2, 需要Mysql数据库支持;虽然SonarQube自带了H2数据库,但是为了方便管理数据推荐使用Mysql数据库
安装Mysql数据库
安装MySQL的yum源
yum -y install http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
安装MySQL
yum -y install mysql mysql-devel mysql-server mysql-utilities
启动MySQL
systemctl start mysqld.service
3,数据库配置
进入数据库命令
mysql -u root -p
mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci; 
mysql> CREATE USER 'sonar' IDENTIFIED BY 'sonar';
mysql> GRANT ALL ON sonar. TO 'sonar'@'%' IDENTIFIED BY 'sonar';
mysql> GRANT ALL ON sonar.
 TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
mysql> FLUSH PRIVILEGES;

4,安装
在安装之前,介绍一下SonarQube和SonarQube Runner之间的关系。 
SonarQube是服务器端,它主要有两个功能:1.分析源代码;2.因为它内嵌了Apache模块,所以提供Web端的界面访问。
SonarQube Runner是一个利用SonarQube服务端分析代码的命令行工具,可以把它简单理解为客户端。
所以,为了安装和调试方便,建议SonarQube和SonarQube Runner都下载。

5, 安装SonarQube
第一步:将下载的sonarqube-6.7.zip解压后移动到/usr/local目录下。具体步骤如下:
Centos 7环境安装SonarQube和SonarQube Runner
将文件解压到/usr/local/
[root@localhost local]# unzip sonarqube-6.7

第二步:配置环境变量
[root@localhost local]# vim /etc/profile
export SONAR_HOME=/usr/local/sonarqube-6.7
export SONAR_RUNNER_HOME=/usr/local/sonar-runner-2.4
PATH=$PATH:$SONAR_HOME/bin:$SONAR_RUNNER_HOME/bin
Centos 7环境安装SonarQube和SonarQube Runner

[root@localhost local]# source /etc/profile
第三步:配置sonar.properties
Centos 7环境安装SonarQube和SonarQube Runner
Centos 7环境安装SonarQube和SonarQube Runner
Centos 7环境安装SonarQube和SonarQube Runner
配置SonarQube Runner
[root@localhost local]# # unzip sonar-runner-dist-2.4.zip
Centos 7环境安装SonarQube和SonarQube Runner
Centos 7环境安装SonarQube和SonarQube Runner
[root@localhost sonar-runner-2.4]# vim sonar-project.properties
#Required metadata
sonar.projectKey=my:project
sonar.projectName=yaok
sonar.projectVersion=1.0
#Paths to source directories.
#Paths are relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
#Do not put the "sonar-project.properties" file in the same directory with the source code.
#(i.e. never set the "sonar.sources" property to ".")
sonar.sources=/root/java
#The value of the property must be the key of the language.
sonar.language=java
#Encoding of the source code
sonar.sourceEncoding=UTF-8
#Additional parameters
sonar.my.property=value

Centos 7环境安装SonarQube和SonarQube Runner
[root@localhost sonar-runner-2.4]# ./bin/sonar-runner -e -X
Centos 7环境安装SonarQube和SonarQube Runner
如果能够看到下面的输出信息,证明你的SonarQube Runner安装并配置正确啦。
6,安装后启动SonarQube
用root无法启动lSonarQube,需要另外新建普通用户来启动
[root@localhost ]# useradd esadmin
[root@localhost local]# chown esadmin.esadmin sonarqube-6.7
[root@localhost sonarqube-6.7]# vim elasticsearch/config/elasticsearch.yml
开启以下两行
Centos 7环境安装SonarQube和SonarQube Runner
[root@localhost sonarqube-6.7]# su esadmin
[esadmin@localhost sonarqube-6.7]$ ./bin/linux-x86-64/sonar.sh start
启动的时候会报错
1,错误:max file descriptors [4096] for elasticsearch process is too low, increase to at least
解决方法:
[root@localhost ]#vim /etc/security/limits.conf
esadmin hard nofile 65536
esadmin soft nofile 65536
在文件最后添加以上两行
查看文件限制命令
[esadmin@localhost sonarqube-6.7]$ ulimit -Hn
Centos 7环境安装SonarQube和SonarQube Runner
2,错误,max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决方法:
切换到root用户修改配置sysctl.conf
[root@localhost]#vim /etc/sysctl.conf 
添加下面配置:
vm.max_map_count=655360
并执行命令:
[root@localhost java]# sysctl -p
Centos 7环境安装SonarQube和SonarQube Runner
解决好以上错误后就可以重启SonarQube
[esadmin@localhost sonarqube-6.7]$ ./bin/linux-x86-64/sonar.sh start
[root@localhost sonarqube-6.7]# ps -aux |grep sonar
Centos 7环境安装SonarQube和SonarQube Runner
使用浏览器就可以直接登陆
http://192.168.0.39:9000/projects
Centos 7环境安装SonarQube和SonarQube Runner
7,安装中文语言包
Centos 7环境安装SonarQube和SonarQube Runner
选择语言包,点击安装,安装好后重启,重新进入就是汉化版了

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值