Article Directory
SonarQube installation
- Official website download address:
http://www.sonarqube.org/downloads/
9.9.1.69595
download link:https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-9.9.1.69595.zip
10.0.0.68432
Download address:https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-10.0.0.
68432.zip
run
bin
Run the startup script in the directory after decompressioncd sonarqube-10.0.0.68432/bin/linux-x86-64 ./sonar.sh start
- If you use the root user to start SonarQube, an error will be reported, please refer to the startup problem solution
- Start with user again
sonar
:sudo su - sonar -c '/opt/sonarqube-10.0.0.68432/bin/linux-x86-64/sonar.sh start'
- Start with user again
- If
ulimit -Hn
the displayed number is4096
, please refer to modify the limit of the number of files- Start again:
sudo su - sonar -c '/opt/sonarqube-10.0.0.68432/bin/linux-x86-64/sonar.sh start'
- Start again:
- If you use
JDK 20
startup, you need to replace it withJDK 17
- Browser input address:
http://localhost:9000/
- Default account password:
admin/admin
- When logging in for the first time, you will be prompted to change the password
Use root to start problem solving
- View logs/sonar.log log
2023.05.29 10:07:25 INFO app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running 2023.05.29 10:07:34 WARN app[][o.s.a.p.AbstractManagedProcess] Process exited with exit value [ElasticSearch]: 1 2023.05.29 10:07:34 INFO app[][o.s.a.SchedulerImpl] Process[ElasticSearch] is stopped 2023.05.29 10:07:34 INFO app[][o.s.a.SchedulerImpl] SonarQube is stopped
Prompt processing ElasticSearch error
- Continue to view logs/es.log
2023.05.29 10:07:34 ERROR es[][o.e.b.Elasticsearch] fatal exception while booting Elasticsearch java.lang.RuntimeException: can not run elasticsearch as root at org.elasticsearch.bootstrap.Elasticsearch.initializeNatives(Elasticsearch.java:260) ~[elasticsearch-8.6.1.jar:?] at org.elasticsearch.bootstrap.Elasticsearch.initPhase2(Elasticsearch.java:166) ~[elasticsearch-8.6.1.jar:?] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:66) ~[elasticsearch-8.6.1.jar:?]
- Elasticsearch does not allow root user to start
- It also means that SonarQube does not allow the root user to start
- create new user
adduser sonar passwd sonar chown -R sonar:sonar sonarqube*
Modify file limit
Checklogs/es.log
2023.05.29 10:36:05 WARN es[][o.e.b.BootstrapChecks] max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
2023.05.29 10:36:05 WARN es[][o.e.b.BootstrapChecks] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
solution
vi /etc/security/limits.conf
- One additional line:
* - nofile 1000000
- View hard limits:
ulimit -Hn
- Exit the current session and reopen the new session to take effect
JDK version problem
Checklogs/nohup.log
Exception in thread "main" java.lang.UnsupportedOperationException: The Security Manager is deprecated and will be removed in a future release
at java.base/java.lang.System.setSecurityManager(System.java:429)
at org.sonar.process.PluginSecurityManager.restrictPlugins(PluginSecurityManager.java:42)
at org.sonar.server.app.WebSecurityManager.apply(WebSecurityManager.java:47)
at org.sonar.server.app.WebServer.main(WebServer.java:101)
solution
- If you use it locally
JDK 20
,JDK 17
you can replace it with
create a project
create token
scan code
mvn sonar:sonar -Dsonar.projectKey=cops -Dsonar.host.url=http://localhost:9000 -Dsonar.login=sqp_1998b065cfa02ebccc672a25449fb468040cc32f
mvn sonar:sonar -Dsonar.projectKey=wen3-demo -Dsonar.host.url=http://localhost:9000 -Dsonar.login=sqp_866c4cbc4722590478f7f2d5cf2f9be06bee2985
Combined
maven-surefire-plugin
withjacoco-maven-plugin
plug-ins, run the unit test first, generate a code coverage report, and then run itsonar:sonar
to upload the coverage toSonarQube
data persistence
- By default, the database is used
h2
, and the storage locationdata/sonar.mv.db
- Support database:
Oracle
,PostgreSQL
,Microsoft SQLServer
- For reference
conf/sonar.properties
, viewsonar.jdbc
the configuration items starting with
online documentation
- Official website:
https://docs.sonarqube.org/
- SonarScanner for Maven:
https://docs.sonarqube.org/latest/analyzing-source-code/scanners/sonarscanner-for-maven/