Sonar代码质量管理平台搭建步骤与注意点

it2026-06-06  6

文章目录

一:基本信息(注意事项)1.各种地址2.sonar特点 二:安装Sonar1.安装信息2.安装JDK113.安装postgreSQL数据库4.安装SonarQube5.登录Sonar6.安装Sonar汉化插件如有疑问,可评论区或私信交流!

一:基本信息(注意事项)

1.各种地址

官网地址:https://www.sonarqube.org/

下载地址:https://www.sonarqube.org/downloads/

资料地址:https://docs.sonarqube.org/latest/

2.sonar特点

**支持的编程语言:**27种,包括:Java,python,go,php,C,C++,C#,JS等等

**版本区分:**免费开源社区版,开发者版,企业版,数据中心版

**硬件要求:**SonarQube在服务器端不支持32位系统

**数据库注意点:**SonarQube的7.9版本开始放弃支持MySQL数据库,8.4版本支持PostgreSQL、Microsoft SQL Server和Oracle三种数据库

二:安装Sonar

1.安装信息

安装版本:sonarqube-8.4.2

安装平台:Linux

需要JDK版本:JDK-11

2.安装JDK11

1.上传JDK包

2.解压并修改环境变量

[root@localhost ~]# tar zxf jdk-11.0.8_linux-x64_bin.tar.gz -C /opt/ [root@localhost ~]# mv /opt/jdk-11.0.8/ /opt/jdk11 [root@localhost ~]# vim /etc/profile tar zxf jdk-11.0.8_linux-x64_bin.tar.gz -C /opt/ vim /etc/profile export JAVA_HOME=/opt/jdk11 export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$JAVA_HOME/bin:$PATH [root@localhost ~]# source /etc/profile

3.验证

[root@localhost ~]# java -version java version "11.0.8" 2020-07-14 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.8+10-LTS) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.8+10-LTS, mixed mode)

3.安装postgreSQL数据库

1.安装

[root@localhost ~]# yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm [root@localhost ~]# yum install -y postgresql12 [root@localhost ~]# yum install -y postgresql12-server [root@localhost ~]# /usr/pgsql-12/bin/postgresql-12-setup initdb [root@localhost ~]# systemctl enable postgresql-12 Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-12.service to /usr/lib/systemd/system/postgresql-12.service. [root@localhost ~]# [root@localhost ~]# systemctl start postgresql-12

2.修改/var/lib/pgsql/12/data/pg_hba.conf配置,开放所有Host的访问

3.重启postgresql数据库并且添加一个新的数据库用户sonar和新的数据库sonar备用

[root@localhost ~]# systemctl restart postgresql-12 [root@localhost ~]# su - postgres -bash-4.2$ psql -U postgres psql (12.4) 输入 "help" 来获取帮助信息. postgres=# CREATE USER sonar WITH PASSWORD 'sonar'; CREATE ROLE postgres=# CREATE DATABASE sonar WITH OWNER sonar ENCODING 'UTF8'; CREATE DATABASE postgres=# exit -bash-4.2$ exit 登出

4.安装SonarQube

1.调整系统参数

[root@localhost ~]# vim /etc/security/limits.conf * soft nofile 65536 '//文件尾部添加' * hard nofile 65536 * soft nproc 4096 * hard nproc 4096 [root@localhost ~]# vim /etc/sysctl.conf vm.max_map_count=262144 '//文件尾部添加' fs.file-max=65536 [root@localhost ~]# sysctl -p

2.Sonar下载后直接在服务器上解压

[root@localhost ~]# unzip sonarqube-8.4.2.36762.zip -d /opt/

3.添加用户,并设置sonarqube文件夹的权限,修改sonar配置文件

[root@localhost ~]# useradd sonar [root@localhost ~]# chown -R sonar.sonar /opt/sonarqube-8.4.2.36762 [root@localhost ~]# vim /opt/sonarqube-8.4.2.36762/conf/sonar.properties sonar.jdbc.username=sonar '//修改这三项' sonar.jdbc.password=sonar sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonar

4.启动sonar

[root@localhost ~]# su sonar '//需要切换用户,不可以使用root用户启动sonar' [sonar@localhost root]$ /opt/sonarqube-8.4.2.36762/bin/linux-x86-64/sonar.sh console '//先使用控制台启动sonar'

Ctrl + C取消后重新启动

[sonar@localhost root]$ /opt/sonarqube-8.4.2.36762/bin/linux-x86-64/sonar.sh start Starting SonarQube... Started SonarQube.

5.登录Sonar

HTTP://本地主机:9000使用系统管理员凭据(登录名= admin,密码=管理员

6.安装Sonar汉化插件

管理员身份进去安装插件,安装时会提示需要重启sonar服务

等待重启完成即可,下图是汉化效果

如有疑问,可评论区或私信交流!

最新回复(0)