1. 簡介
SonarQube
是一個用於管理代碼質量的開放平台,可以快速的定位代碼中潛在的或者明顯的錯誤。目前支持java
,C#
,C/C++
,Python
,PL/SQL
,Cobol
,JavaScrip
,Groovy
等二十幾種編程語言的代碼質量管理與檢測。
2. 環境
Centos
7
JDK
11
PostgreSQL 10
3. 創建用戶
# 創建sonar系統用戶
groupadd sonar
useradd sonar -g sonar
4. 優化參數
sysctl -w vm.max_map_count=262144
sysctl -w fs.file-max=65536
ulimit -u 4096 sonar
ulimit -n 65536 sonar
5. 安裝PostgreSQL10
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install postgresql10
yum install postgresql10-server
/usr/pgsql-10/bin/postgresql-10-setup initdb
systemctl enable postgresql-10
systemctl start postgresql-10
創建數據庫和用戶,並把數據庫分配給該用戶,並授予權限
# 登錄postsql
su - postgres
psql
# 創建數據庫和用戶,並把數據庫分配給該用戶,並授予權限
create database sonar;
create user sonar;
alter user sonar with password 'sonar';
alter role sonar createdb;
alter role sonar superuser;
alter role sonar createrole;
alter database sonar owner to sonar;
# 退出
\q
exit
修改配置文件/var/lib/pgsql/10/data/pg_hba.conf
,將ident
全部改為md5
改完重啟postsql
systemctl restart postgresql-10
6. 安裝SonarQube
版本是
sonarqube-7.9.3
1. 下載SonarQube
解壓sonar
,並設置權限
yum install unzip
unzip sonarqube-7.9.3.zip
mkdir /opt/sonar
mv sonarqube-7.9.3/* /opt/sonar/
groupadd sonar
useradd sonar -g sonar
chown -R sonar.sonar /opt/sonar/
3. 修改配置文件
vim /opt/sonar/conf/sonar.properties
修改數據庫相關的配置
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:postgresql://localhost/sonar
注意:
sonar
默認監聽9000端口,如果9000端口被占用,需要更改。
4. 啟動SonarQube
# 啟動
su sonar /opt/sonar/bin/linux-x86-64/sonar.sh start
# 查看狀態
su sonar /opt/sonar/bin/linux-x86-64/sonar.sh status
# 停止
su sonar /opt/sonar/bin/linux-x86-64/sonar.sh stop
# 查看日志
tail -f /opt/sonar/logs/sonar.log
5. 常見錯誤
app[][o.s.a.p.AbstractManagedProcess] Process exited with exit value [es]: 143
這個報錯一般是數據庫連接問題,請查看sonar/logs/web.log
app[][o.s.a.p.AbstractManagedProcess] Process exited with exit value [es]: 1
這個報錯一般是es
不能使用root
啟動原因導致
Caused by: org.postgresql.util.PSQLException: ERROR: no schema has been selected to create in
是因為沒權限,要注意授權
java.lang.IllegalStateException: Fail to connect to database
無法連接數據庫,注意IP
地址