CentOS 7上安装SonarQube8.9
在CentOS 7上安装SonarQube8.9并使用PostgreSQL作为数据库
⚠️ 重要注意事项
不再支持:MySQL 数据库(从 SonarQube 7.9 开始已移除)
数据库驱动:不需要手动安装,SonarQube 已包含
字符集:所有数据库必须使用 UTF-8 编码
权限:需要为 SonarQube 创建专用数据库用户
安装SonarQube
# 创建sonarqube用户
sudo useradd sonarqube
# 安装unzip(如果没有)
sudo yum install -y unzip
# 解压
sudo unzip sonarqube-8.9.10.61524.zip
sudo mv sonarqube-8.9.10.61524 sonarqube
# 设置权限
sudo chown -R sonarqube:sonarqube /opt/sonarqube
sudo chmod -R 775 /opt/sonarqube
配置系统参数
sudo vi /etc/security/limits.conf
sonarqube soft nofile 65536
sonarqube hard nofile 65536
sonarqube soft nproc 4096
sonarqube hard nproc 4096
修改sysctl配置
sudo vi /etc/sysctl.conf
vm.max_map_count=262144
fs.file-max=65536
应用配置:
sudo sysctl -p
创建Systemd服务
创建服务文件
sudo vi /etc/systemd/system/sonarqube.service
添加以下内容:
[Unit]
Description=SonarQube service
After=syslog.target network.target mysqld.service
[Service]
Type=forking
User=sonarqube
Group=sonarqube
PermissionsStartOnly=true
ExecStart=/opt/sonarqube/bin/linux-x86-64/sonar.sh start
ExecStop=/opt/sonarqube/bin/linux-x86-64/sonar.sh stop
ExecReload=/opt/sonarqube/bin/linux-x86-64/sonar.sh restart
StandardOutput=syslog
LimitNOFILE=65536
LimitNPROC=4096
TimeoutStartSec=5
TimeoutStopSec=5
Restart=always
[Install]
WantedBy=multi-user.target
启动SonarQube
# 重新加载systemd
sudo systemctl daemon-reload
# 启动SonarQube服务
sudo systemctl start sonarqube
# 设置开机自启
sudo systemctl enable sonarqube
# 检查状态
sudo systemctl status sonarqube
# 查看日志
sudo tail -f /opt/sonarqube/logs/sonar.log
访问SonarQube
http://your-server-ip:9000