由于新版本sonar不再支持MySQL数据库,这次使用postgresql搭建当前最新版本sonar
版本信息
操作系统:centos 7
java版本:openjdk 11.0.5
postgresql版本:9.6.16
sonar版本:8.0
具体软硬件可参照sonar官网给出的要求
安装
JDK安装
yum -y install java-11-openjdk.x86_64
postgresql安装
- 配置yum源,具体版本可在postgresql官网自行选取
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
- 安装
yum makecache
yum -y install postgresql96.x86_64 postgresql96-server.x86_64
- 自定义存储路径
mkdir /postgrespath
chown -R postgres:postgres /postgrespath
修改/usr/lib/systemd/system/postgresql-9.6.service
中的Environment=PGDATA=/postgrespath
,设置为自己的路径即可。
- 初始化并启动数据库
/usr/pgsql-9.6/bin/postgresql96-setup initdb
systemctl start postgresql-9.6
- 修改初始密码并创建sonar数据库
su - postgres
psql -U postgres
ALTER USER postgres WITH PASSWORD 'yourpasswd';
CREATE USER sonar WITH PASSWORD 'yourpasswd';
create database sonar owner sonar;
grant all on database sonar to sonar;
最后执行\q
退出
安装sonar
在官网下载最新sonar-ce版本,编写文档时版本为8.0
修改配置文件sonar.properties
sonar.web.port=9000
sonar.web.host=0.0.0.0
sonar.jdbc.username=soanr
sonar.jdbc.password=yourpasswd
sonar.jdbc.url=jdbc:postgresql://localhost/sonar
启动服务后在9000端口访问即可
FAQ
启动时报错
修改/etc/security/limits.conf
,在末尾添加
sonar soft nofile 65536
sonar hard nofile 65536
修改/etc/sysctl.conf
,在末尾添加
vm.max_map_count=655360