搭建 SonarQube 进行代码审查
编写docker-compose.yml
version: '3'
services:
sonarqube:
image: sonarqube:latest
container_name: sonarqube
privileged: true
ports:
- "9000:9000"
volumes:
- '/root/sonarqube/data:/opt/sonarqube/data'
- '/root/sonarqube/logs:/opt/sonarqube/logs'
- '/root/sonarqube/extensions:/opt/sonarqube/extensions'
执行docker-compose up -d 启动之后。/root/sonarqube/目录结构如下,log文件夹是sonar运行过程的所有日志。ce.log是插件加载日志,es.log是是elasticsearch的启动日志,sonar.log是整个sonar的启动日志。
[root@iZ2ze4yxz5mahmlf0hmgi6Z sonarqube]# ls
data docker-compose.yml extensions logs
[root@iZ2ze4yxz5mahmlf0hmgi6Z sonarqube]#
问题排查
docker TimeOut
ERROR: error pulling image configuration: Get https://production.cloudflare.docker.com/registry-v2/docker/registry/v2/blobs/sha256/ce/ce76b6b9372a3f9fba5326432778d0a4c81ba18f50a1be3315107a7dab4fd6ec/data?verify=1595504332-J3%2BINTJEwkUCr%2F%2FOr2Gw1WKFHaw%3D: read tcp 172.21.0.5:42114->104.18.124.25:443: read: connection reset by peer
Error response from daemon: Get https://index.docker.io/v1/search?q=centos: read tcp 52.200.132.201:443: i/o timeout
-
进入/etc/docker
-
查看有没有 daemon.json。这是docker默认的配置文件。
-
如果没有新建,如果有,则修改。
$ vi daemon.json 保存退出。
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}
- 重启docker服务
service docker restart
gitlib-runner 执行sonar分析报错
$ sonar-scanner -Dsonar.qualitygate.wait=true
INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /builds/mall/test/sonar-project.properties
INFO: SonarScanner 4.4.0.2170
INFO: Java 11.0.6 AdoptOpenJDK (64-bit)
INFO: Linux 3.10.0-1062.18.1.el7.x86_64 amd64
INFO: User cache: /opt/sonar-scanner/.sonar/cache
INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /builds/mall/test/sonar-project.properties
INFO: Analyzing on SonarQube server 8.4.1
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Load global settings
INFO: Load global settings (done) | time=1958ms
INFO: Server id: BF41A1F2-AXN7XsOhpOFdbp4kSnfN
INFO: User cache: /opt/sonar-scanner/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=205ms
INFO: Plugin [l10nzh] defines 'l10nen' as base plugin. This metadata can be removed from manifest of l10n plugins since version 5.2.
INFO: Load/download plugins (done) | time=281ms
INFO: Process project properties
INFO: Process project properties (done) | time=19ms
INFO: Project key: spring-boot-ci
INFO: Base dir: /builds/mall/test
INFO: Working dir: /builds/mall/test/.scannerwork
INFO: Load project settings for component key: 'spring-boot-ci'
INFO: Load quality profiles
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 3:06.324s
ERROR: Error during SonarScanner execution
ERROR: No quality profiles have been found, you probably don't have any language plugin installed.
ERROR:
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
INFO: Final Memory: 7M/58M
INFO: ------------------------------------------------------------------------
没有安装 java语言的插件,难受啊,开始了苦命的下载,在页面访问应用市场,下载简直龟速,只好自己想法走手动安装。从github下载,从maven仓库下载贼慢,好不容易下载了一个sonar-aemrules-plugin-1.1.jar
,放在extensions/plugins目录下,发现sonar起不来了,查询es。也没起来查看es.log发现max_map_count数不够用
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
然后修改VM参数,设置为262144。
[root@centos7 sonarqube-7.2.1]# vi /etc/sysctl.conf
vm.max_map_count=262144
[root@centos7 sonarqube-7.2.1]# sysctl -p
修改完毕重启,还是特么访问不到,docker-compose up -d 之后。没一会儿容器就挂了。然后又去查询sonar.log文件,发现有用的日志少的可怜。然后再去观察ce.log. 发现了无法加载sonar-aemrules-plugin-1.1.jar
。初步怀疑插件版本不匹配。然后去Sonar插件版本参考。来对比插件和sonar的兼容问题。插件也需要与主版本兼容,血与泪的教训啊。难受啊 老老实实的下载一个 sonar-java-plugin-5.10.1.16922.jar
的了。起初怀疑是内存不够导致容器挂掉。毕竟我的宿主机就是个1C2G
,乞丐版,第一点就考虑了机器,却忘了是不是插件的版本问题。我丢。