هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
Know it before you install
The server (web UI, compute engine and an embedded Elasticsearch) stores results in PostgreSQL. A scanner runs in your CI job, analyses the code and sends the report to the server. A quality profile is the rule set; a quality gate is the pass/fail condition (for example "no new critical issues, coverage on new code ≥ 80 %").
| Item | Value |
|---|---|
| Editions | Community Build (free), Developer/Enterprise (branches, PR decoration, more languages) |
| Image | sonarqube:community (+ postgres:16) |
| Data | Docker volumes for data, extensions, logs + the PostgreSQL volume |
| Port | 9000/tcp (web UI and API) |
| Scanners | sonar-scanner (CLI), Maven/Gradle plugins, .NET scanner, CI actions |
| Kernel needs | vm.max_map_count ≥ 524288, fs.file-max ≥ 131072 |
What you need: Docker Engine (see the Docker guide), 4 GB RAM or more, 2 CPU.
Prepare the host (RHEL and Ubuntu)
The embedded Elasticsearch needs these kernel settings, or SonarQube stops at start:
Install with Docker Compose
services:
db:
image: postgres:16
restart: unless-stopped
environment:
POSTGRES_USER: sonar
POSTGRES_DB: sonarqube
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
volumes:
- pgdata:/var/lib/postgresql/data
sonarqube:
image: sonarqube:community
restart: unless-stopped
depends_on: [db]
ports:
- "127.0.0.1:9000:9000"
environment:
SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonarqube
SONAR_JDBC_USERNAME: sonar
SONAR_JDBC_PASSWORD: ${POSTGRES_PASSWORD}
ulimits:
nofile: { soft: 131072, hard: 131072 }
nproc: 8192
volumes:
- sonar_data:/opt/sonarqube/data
- sonar_extensions:/opt/sonarqube/extensions
- sonar_logs:/opt/sonarqube/logs
volumes:
pgdata:
sonar_data:
sonar_extensions:
sonar_logs:Pin a version tag (for example sonarqube:25.10.0.114319-community) in production and update on purpose.
First configuration: login and safe settings
Open http://localhost:9000 through an SSH tunnel (or Nginx — below). Log in as admin / admin; SonarQube makes you change the password at once.
| Where | Setting | Why |
|---|---|---|
| Administration → Security | Force user authentication = on (default) | No code or results visible without login. |
| Administration → Security → Users | Personal accounts or SSO (SAML/GitHub/GitLab) | No shared admin. |
| Administration → General → Server base URL | https://sonar.example.com | Correct links in emails and CI. |
| My Account → Security | Make tokens for CI (project analysis tokens) | Scanners never use passwords. |
| Quality Gates | Use "Sonar way" or your own gate on new code | The merge stops on new problems; old debt is fixed step by step. |
Behind Nginx with HTTPS:
server {
listen 443 ssl;
server_name sonar.example.com;
ssl_certificate /etc/letsencrypt/live/sonar.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/sonar.example.com/privkey.pem;
client_max_body_size 50m;
location / {
proxy_pass http://127.0.0.1:9000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
}
}Analyse a project from CI
Create the project in the UI (Create project → Manually), get its key and a token. Then in the repository:
sonar.projectKey=shop-api
sonar.sources=src
sonar.tests=tests
sonar.python.coverage.reportPaths=coverage.xml
sonar.qualitygate.wait=truedocker run --rm -e SONAR_HOST_URL=https://sonar.example.com -e SONAR_TOKEN="$SONAR_TOKEN" -v "$PWD":/usr/src sonarsource/sonar-scanner-cli
mvn -B verify sonar:sonar -Dsonar.host.url=https://sonar.example.com -Dsonar.token="$SONAR_TOKEN" -Dsonar.projectKey=shop-javaWith sonar.qualitygate.wait=true the scanner waits for the result and fails the CI job when the quality gate fails. Store SONAR_TOKEN as a masked CI secret.
Real uses at work:
- A quality gate on every pull request (with Developer edition: comments in the PR).
- Find security hotspots and secrets in code before release.
- Track coverage and technical debt per team.
Make it safe
Security checklist:
- Change the admin password at once; personal accounts or SSO; Force user authentication on.
- Port 9000 only on
127.0.0.1; HTTPS through Nginx. - Tokens per project for CI, stored as CI secrets; revoke unused tokens.
- Database password in
.env(mode600), never in Git. - Back up PostgreSQL (
pg_dump) — it holds all results and settings. - Update SonarQube regularly (new rules and security fixes); read the upgrade notes.
Update and remove
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
Stops at start: max virtual memory areas vm.max_map_count [65530] is too low | Kernel setting. | vm.max_map_count = 524288 (see above), sysctl --system. |
Can not connect to database | Wrong JDBC URL or password, DB not ready. | Check .env and SONAR_JDBC_*; docker compose logs db. |
Scanner: Not authorized. Please check the user token | Wrong or expired token, or missing rights on the project. | Make a new token; check project permissions. |
Scanner: Project not found | Wrong sonar.projectKey. | Use the key shown in the project. |
| Quality gate wait times out | The background task is slow or failed. | Administration → Projects → Background Tasks; more RAM. |
| Out of memory / very slow | Too little RAM for big projects. | More RAM; SONAR_CE_JAVAOPTS / SONAR_WEB_JAVAOPTS heap settings. |
Links point to localhost:9000 | Server base URL not set. | Set it in Administration → General. |
Next steps
- Quick how-tos: Check code quality in CI.
- Command page: sonar-scanner, Command page: mvn.
- At work: Code quality and the quality gate, All scanners in one pipeline.
- The other scanners: Trivy, semgrep, gitleaks. The CI side: Jenkins, GitLab Runner.
1What makes the CI job fail when the quality gate fails?
sonar.qualitygate.wait=true — the scanner waits for the gate result and exits with an error.
2SonarQube stops right after start with a vm.max_map_count error. Why?
Its embedded Elasticsearch needs vm.max_map_count of at least 524288 on the host.