背景
我是在ubuntu服务器安装docker服务,我已经安装好了docker和docker-compose服务,这里我就不写这些服务的安装过程,直接开始安装sonarqube服务
安装 sonarqube服务器
1.执行脚本文件 config.sh
1#!/bin/bash
2sysctl -w vm.max_map_count=262144
3sysctl -w fs.file-max=65536
4ulimit -n 65536
5ulimit -u 4096
6# # 永久改变
7# echo "vm.max_map_count=262144" >> /etc/sysctl.conf
8# sysctl -p
1sh config.sh
2.执行docker-compose文件
1version: '3'
2services:
3 postgres:
4 image: postgres:15
5 container_name: postgres
6 ports:
7 - 5432:5432
8 volumes:
9 - ./sonar/postgres/postgresql:/var/lib/postgresql
10 - ./sonar/postgres/data:/var/lib/postgresql/data
11 environment:
12 TZ: Asia/Shanghai
13 POSTGRES_USER: user #数据库用户
14 POSTGRES_PASSWORD: password #数据库密码
15 POSTGRES_DB: sonar
16
17 sonarqube:
18 depends_on:
19 - postgres
20 image: sonarqube:9.9.0-community
21 container_name: sonarqube
22 ports:
23 - 9000:9000
24 volumes:
25 - ./sonar/sonarqube/extensions:/opt/sonarqube/extensions
26 - ./sonar/sonarqube/logs:/opt/sonarqube/logs
27 - ./sonar/sonarqube/data:/opt/sonarqube/data
28 - ./sonar/sonarqube/conf:/opt/sonarqube/conf
29 environment:
30 SONARQUBE_JDBC_USERNAME: user #数据库用户
31 SONARQUBE_JDBC_PASSWORD: password #数据库密码
32 SONARQUBE_JDBC_URL: jdbc:postgresql://postgres:5432/sonar
1docker-compose up -d
3. 生成用户令牌
安装 sonar scanner扫描器
1wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip
2unzip sonar-scanner-cli-5.0.1.3006-linux.zip
3mv sonar-scanner-cli-5.0.1.3006-linux.zip /opt/
连接sonarqube服务器
1cd /opt/sonar-scanner-5.0.1.3006-linux/conf/
2vim sonar-scanner.properties
修改配置文件
1#No information about specific project should appear here
2
3#----- 修改服务器地址
4sonar.host.url=http://sonar-server:9000
5
6#----- Default source code encoding
7sonar.sourceEncoding=UTF-8
安装scanner
1cd sonar-scanner-5.0.1.3006-linux/
2sudo ln -s /opt/sonar-scanner-5.0.1.3006-linux/bin/sonar-scanner /usr/local/bin/sonar-scanner
3sonar-scanner -v
执行扫描
1cd /code/github/project/path
2sonar-scanner -D sonar.login=<sonar-key> -Dsonar.projectKey=<my-project> -Dsonar.projectName=<my-project-name> -Dsonar.projectVersion=1.0 -Dsonar.sourceEncoding=UTF-8 -Dsonar.java.binaries=target/classes -Dsonar.java.libraries=target/*.jar