Time: 2020年10月
Operation System: CentOS7
RAM: 4G
Java Version: 11.0.8
SonarQube Version: 8.0
之前在公众号也写过一篇关于SonarQube的文章,本文将针对这篇文章进行一个完善,包括SonarQube安装、使用、集成三个部分,后期有时间会写一篇关于规则优化的文章。原微信公众号文章地址:SonarQube实现自动化代码扫描 https://mp.weixin.qq.com/s/L5WeEFvu6etVTAigx6jjcQ
官网也有安装文档:https://docs.sonarqube.org/latest/setup/install-server/ 这里安装就贴原文就好了
SonarQube的依赖
运行内存依赖
A small-scale (individual or small team) instance of the SonarQube server requires at least 2GB of RAM to run efficiently and 1GB of free RAM for the OS.
If you’re running on Linux, you must ensure that:
- vm.max_map_count is greater than or equal to 524288
- fs.file-max is greater than or equal to 131072
- the user running SonarQube can open at least 131072 file descriptors
- the user running SonarQube can open at least 8192 threads
You can see the values with the following commands:
sysctl vm.max_map_count
sysctl fs.file-max
ulimit -n
ulimit -u
You can set them dynamically for the current session by running the following commands as root
:
sysctl -w vm.max_map_count=524288
sysctl -w fs.file-max=131072
ulimit -n 131072
ulimit -u 8192
以上是临时解决方案,但是如果需要永久生效需要进行如下配置:
# 在sysctl配置文件中添加 vm.max_map_count=655360
vim /etc/sysctl.conf
vm.max_map_count=655360
# 使sysctl配置立即生效
sysctl -p
# 在limits配置文件中添加
vim /etc/security/limits.conf
* soft nofile 65536
* hard nofile 65536
# 要使limits配置生效不需要重启系统,但是需要重新登录用户
如果按照官方文档的提示进行配置,那么在虚拟机中就可能出现SonarQube服务无法启动,日志记录如下:
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max virtual memory areas vm.max_map_count [65530] is too low,