Sonarqube 代码审核工具
环境要求
| 软件 | 版本 |
|---|---|
| Centos | 7 |
| PGSQL | 12 |
| Sonar | 8.5 |
| OpenJDK | 11 |
Sonarqube组件
| 名称 | 描述 |
|---|---|
| SonarQube Server | 主服务 |
| SonarQube Database | 数据库 |
| SonarQube Scanners | 代码扫描器 |
| SonarQube Plugins | 插件管理 |
安装PGSQL
yum安装
xxxxxxxxxxyum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpmyum install -y postgresql12 postgresql12-server二进制安装
下载地址: https://www.enterprisedb.com/download-postgresql-binaries
初始化数据库
xxxxxxxxxx/usr/pgsql-12/bin/postgresql-12-setup initdb 启动PGSQL
xxxxxxxxxx#启动PostgreSQL服务sudo systemctl start postgresql-12
#设置PostgreSQL服务为开机启动sudo systemctl enable postgresql-12
修改超级用户密码(postgresql数据库中会初始化一名超级用户
postgres)
xxxxxxxxxx# 修改postgres用户密码su postgrespsqlALTER USER postgres WITH PASSWORD 'your password';
创建sonar数据库,配置用户权限
xxxxxxxxxxsu postgrespsql#创建数据库CREATE DATABASE sonar;
#查看所有数据库\l
#切换当前数据库\c sonar
#查看当前数据库下所有表\d
#新建用户CREATE USER test WITH PASSWORD 'sonar';
#赋予指定账户指定数据库所有权限GRANT ALL PRIVILEGES ON DATABASE sonar TO sonar;
#更改sonar数据库拥有者alter database sonar owner to sonar;
#移除指定账户指定数据库所有权限REVOKE ALL PRIVILEGES ON DATABASE sonar TO sonar;PGSQL其他配置
xxxxxxxxxx#修改IP绑定vi /var/lib/pgsql/12/data/postgresql.conf
#将监听地址修改为*#默认listen_addresses配置是注释掉的,所以可以直接在配置文件开头加入该行listen_addresses='*'
#允许所有IP访问vi /var/lib/pgsql/12/data/pg_hba.conf
#在问价尾部加入host all all 0.0.0.0/0 md5
安装sonar
下载地址(社区版免费): https://www.sonarqube.org/downloads/
安装JDK11 (openJDK 下载地址:https://openjdk.java.net/)
xxxxxxxxxxyum install java-11-openjdk.x86_64 -y
解压部署
xxxxxxxxxxcd /opt/applicationunzip sonarqube-8.5.0.37579.zipmv sonarqube-8.5.0.37579 sonarqube
#创建sonar用户(sonar自带es不能使用root用户启动)useradd sonarchown sonar. sonarqube -R
系统配置
xxxxxxxxxxvim /etc/sysctl.confvm.max_map_count = 262144
#重新载入sysctl -p
vim /etc/security/limits.conf
* soft nofile 65536* hard nofile 65536
vim /etc/security/limits.d/20-nproc.conf
* soft nproc 65536root soft nproc unlimited配置sonar
xxxxxxxxxxvim /opt/application/sonarqube/conf/sonar.properties
sonar.jdbc.username=sonarsonar.jdbc.password=dingtone.sonarsonar.jdbc.url=jdbc:postgresql://localhost/sonar
# 使用LDAP账户
sonar.security.realm=LDAPldap.url=ldap://ldapserverldap.bindDn=my_bind_dnldap.bindPassword=my_bind_password # User Configurationldap.user.baseDn=ou=Users,dc=mycompany,dc=comldap.user.request=(&(objectClass=inetOrgPerson)(uid={login}))ldap.user.realNameAttribute=cnldap.user.emailAttribute=mail # Group Configurationldap.group.baseDn=ou=Groups,dc=mycompany,dc=comldap.group.request=(&(objectClass=posixGroup)(memberUid={uid}))启动sonar
xxxxxxxxxxcd /opt/application/sonarqube/bin/linux-x86-64./sonar.sh start配置服务
xxxxxxxxxx# 添加服务vim /etc/systemd/system/sonar.service[Unit]Description=SonarQube ServerAfter=syslog.target network.target
[Service]Type=forkingExecStart=/opt/sonarqube/bin/linux-x86-64/sonar.sh startExecStop=/opt/sonarqube/bin/linux-x86-64/sonar.sh stopUser=sonarGroup=sonarRestart=on-failure
[Install]WantedBy=multi-user.target
# 加载服务sudo systemctl daemon-reloadsudo systemctl restart sonar.servicesudo systemctl enable sonar.service
访问sonar:http://serverip:9000,默认用户密码:admin admin
安装SonarQube Scanners
下载地址:https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/
xxxxxxxxxxcd /opt/application/unzip sonar-scanner-cli-4.5.0.2216-linux.zipmv sonar-scanner-4.5.0.2216-linux sonar-scannerchown sonar. sonar-scanner -Rvim sonar-scanner/conf/sonar-scanner.properties
sonar.host.url=http://localhost:9000sonar.sourceEncoding=UTF-8
评论
发表评论