📝 SonarQube安装配置

← 返回笔记列表

SonarQube安装配置

2026年03月24日 18:26

下载压缩包并解压

cd /usr/local
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.2.zip
unzip sonarqube-7.2.zip

添加用户sonar

更改 该目录 的owner(原因:sonarqube中的es不许以root启动,故以sonar用户来启动)

useradd sonar
chown -R sonar /usr/local/sonarqube-7.2

数据库创建和用户设置

set global validate_password_policy=0;
CREATE USER sonar@'%' IDENTIFIED BY 'sonar123';
CREATE DATABASE `sonar` CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_general_ci';
GRANT ALL ON sonar.* TO sonar@'%';
flush privileges;

配置数据库连接

vi /usr/local/sonarqube-7.2/conf/sonar.properties

相应的修改处如下

sonar.jdbc.username=sonar
sonar.jdbc.password=sonar123
sonar.jdbc.url=jdbc:mysql://172.19.197.139:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
sonar.web.host=172.19.197.138

文件数处理

vim /etc/security/limits.conf

添加如下配置:

sonar hard nofile 65536
sonar soft nofile 65536

内存配置

vim /etc/sysctl.conf 

添加下面配置

vm.max_map_count=655360

加载配置

sysctl -p

启动sonar

cd /usr/local/sonarqube-7.2/

以普通用户sonar启动服务,不然es启动会报错,用法:console、start、status、stop...

su sonar bin/linux-x86-64/sonar.sh start

查看状态

这个状态只是暂时的,并不可信

su sonar bin/linux-x86-64/sonar.sh status

跟踪日志确保启动成功

先跟着sonar.log日志,如果报es错误,可以去查看es.log;如果报了web错误,那么就是查看web.log

tail -f logs/sonar.log

重启

su sonar bin/linux-x86-64/sonar.sh restart

安装插件

下载响应插件(jar)保存到以下目录,重启

/usr/local/sonarqube-7.2/extensions/plugins/
mvn -e clean install sonar:sonar -Dsonar.host.url=http://172.19.197.138:9000 -Dsonar.login=2ba0fe0287d35200bfe90ea58800c19b70b53d16
返回顶部 ← 返回笔记列表