sudo apt install openjdk-17-jdk
sudo apt install postgresql postgresql-contrib
sudo -u postgres psql
CREATE DATABASE sonarqube;
CREATE USER sonaruser WITH ENCRYPTED PASSWORD '123456';
GRANT ALL PRIVILEGES ON DATABASE sonarqube TO sonaruser;
\q
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-10.5.1.90531.zip
unzip sonarqube-10.5.1.90531.zip
sudo mv sonarqube-10.5.1.90531 /opt/sonar
sudo vi /opt/sonar/conf/sonar.properties
Thêm cấu hình
# DATABASE
sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonarqube
sonar.jdbc.username=sonaruser
sonar.jdbc.password=123456
sudo adduser --system --no-create-home --group --disabled-login sonarqube
sudo chown sonarqube:sonarqube /opt/sonar -R
#sudo chown sonarqube:sonarqube sonar.sh
sudo vi /etc/sysctl.conf
Thêm cấu hình
vm.max_map_count=524288
fs.file-max=131072
Tạo file 99-sonarqube.conf
sudo vi /etc/security/limits.d/99-sonarqube.conf
Thêm cấu hình vào file 99-sonarqube.conf
sonarqube - nofile 131072
sonarqube - nproc 8192
sudo -u sonarqube ./sonar.sh start
sudo nano /etc/systemd/system/sonarqube.service
Thêm cấu hình
[Unit]
Description=SonarQube service
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/opt/sonar/bin/linux-x86-64/sonar.sh start
ExecStop=/opt/sonar/bin/linux-x86-64/sonar.sh stop
User=sonarqube
Group=sonarqube
PermissionsStartOnly=true
Restart=always
StandardOutput=syslog
LimitNOFILE=131072
LimitNPROC=8192
TimeoutStartSec=5
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
sudo systemctl start sonarqube
#sudo systemctl status sonarqube
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-6.0.0.4432-linux.zip
unzip sonar-scanner-cli-6.0.0.4432.zip
sudo mv sonar-scanner-cli-6.0.0.4432 /opt/sonarscanner
cd /opt/sonarscanner
sudo nano conf/sonar-scanner.properties
Thêm cấu hình
sonar.host.url=http://localhost:9000
Đăng nhập sonarqube (admin:admin) thực hiện tạo project mới để lấy token. Thực hiện chạy lệnh tùy cấu hình project. VD:
~/opt/sonarscanner/bin/sonar-scanner -Dsonar.projectKey=monti -Dsonar.sources=. -Dsonar.host.url=http://localhost:9000 -Dsonar.token=sqp_a48123dda49081fce58cfd5f44d277cbf7a3df7f