1.安装sonarqube
下载sonarqube所需版本:
2.修改配置(解压后):
vim sonarqube/conf/wrapper.conf
# 指定命令执行路径
wrapper.java.command=/opt/java/jdk1.8.0_241/bin/java
vim sonarqube/conf/sonar.properties
# 添加如下配置
sonar.jdbc.username=chao
sonar.jdbc.password=密码
sonar.jdbc.url=jdbc:postgresql://IP:5432/sonarqube
#sonar.login=admin
#sonar.password=admin
#sonar.web.port=9002
其他系统配置
# 以下命令查看目前值
sysctl vm.max_map_count
sysctl fs.file-max
ulimit -n
ulimit -u
# 以下命令修改为sonarqube建议的值
sysctl -w vm.max_map_count=262144
sysctl -w fs.file-max=65536
ulimit -n 65536
ulimit -u 2048
sonarqube不能用root用户启动,所以新建用户,并改权限
adduser chao
passwd chao (可省略这一步)
chown -R chao:chao sonarqube
chown -R chao:chao java
# 此时还未安装数据库,所以先不运行
/sonarqube/bin/linux-x86-64/sonar.sh console
3.安装postgresql数据库
dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
dnf -qy module disable postgresql
dnf install postgresql96
dnf install postgresql96-server
/usr/pgsql-9.6/bin/postgresql96-setup initdb
systemctl enable postgresql-9.6
systemctl start postgresql-9.6
数据库相关设置
su - postgres
psql
create user chao with password '密码';
create database sonar encoding='UTF8' owner chao;
grant all privileges on database sonar to chao;
\q
开启远程访问
vim /var/lib/pgsql/9.6/data/postgresql.conf
# 取消listen_addresses的注释
listen_addresses = '*'
vim /var/lib/pgsql/9.6/data/pg_hba.conf
# 增加如下最后一行
# IPv4 local connections:
host all all 127.0.0.1/32 ident
host all all 0.0.0.0/0 md5
# 用root账户执行命令重启postgresql
systemctl restart postgresql-9.6.service
低版本汉化jar包下载
4.集成到jenkins
安装SonarQube Scanner for Jenkins插件
Configure System-->SonarQube servers
Name:sonarqube
Server URL:http://192.168.1.199:9000
Server authentication token:这里需要先创建Secret text凭据
Global Tool Configuration-->SonarQube Scanner
Name:scanner
# 勾选Install automatically
# 构建新增Execute SonarQube Scanner
Analysis properties-->
sonar.projectKey=logistics-dev
sonar.projectName=logistics-dev
sonar.sources=.
sonar.language=ts
sonar.sourceEncoding=UTF-8