安装需要
JDK 11
postgresql 9.1.0
SonaQube简介
SonarQube是一个用于管理代码质量的开放平台,可以快速的定位代码中潜在的或者明显的错误。目前支持java,C#,C/C++,Python,PL/SQL,Cobol,JavaScrip,Groovy
等二十几种编程语言的代码质量管理与检测。
官网:https://www.sonarqube.org/
安装SonarQube
下载sonar压缩包:https://www.sonarqube.org/downloads/
解压sonar,并设置权限
# 创建目录
mkdir /opt/sonar
# 下载unzip
yum install unzip
# 解压
unzip sonarqube-9.1.0.47736.zip
# 创建sonar用户,必须sonar用于启动,否则报错
useradd sonar
# 更改sonar目录及文件权限
chown -R sonar. /opt/sonar
编辑配置文件,将如下配置添加至文件中,然后保存退出
vi /etc/profile
#sonar 内容
export SONAR_HOME=/opt/sonar/sonarqube-9.1.0.47736
export PATH=$PATH:$SNOAR_HOME/bin/linux-x86-64
# 重启命令
source /etc/profile
修改sonar配置文件
vi /opt/sonar/sonarqube-9.1.0.47736/conf/sonar.properties
# 内容如下:
sonar.jdbc.username=postgres
sonar.jdbc.password=postgres
# jdbc:postgresql
sonar.jdbc.url=jdbc:postgresql://127.0.0.1:5432/sonarqube
注意:sonar默认监听9000端口,如果9000端口被占用,需要更改。
启动sonar
cd /opt/sonar/sonarqube-9.1.0.47736
# 启动
su sonar ./bin/linux-x86-64/sonar.sh start
# 查看状态
su sonar ./bin/linux-x86-64/sonar.sh status
# 停止
su sonar ./bin/linux-x86-64/sonar.sh stop
# 查看日志
tail -f logs/sonar.logs
访问sonar
http://172.16.150.145:9000
可能遇到问题
- 启动失败,提示ERROR: [1] bootstrap checks failed [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
issue fix: sudo sysctl -w vm.max_map_count=262144
- 提示Failed to create table schema_migrations,类似下面的内容
ERROR web[][o.s.s.p.PlatformImpl] Web server startup failed
java.lang.IllegalStateException: `Failed to create table schema_migrations`
数据库连接指定了?currentSchema=my_schema
,删除即可,使用默认的public schema
。
创建Token
6e146485a155bb6b18fd8ef9356f77d355a53c75