Installing SonarQube in ubuntu
- Perform a system update and install unzip
sudo apt update
sudo apt install unzip -y
sudo apt install openjdk-11-jdk -y
- Install and Configure Postgres
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -
sudo apt-get -y install postgresql postgresql-contrib
- Enable and Start Postgresql
sudo systemctl enable postgresql
sudo systemctl start postgresql
- Change the passwd for postgres user
sudo passwd postgres
- Switch to postgres user and create a user called sonar
su - postgres
createuser sonar
psql
- Set a password for the newly created user for SonarQube database and create a database for Postgresql database
ALTER USER sonar WITH ENCRYPTED password 'P@ssword';
CREATE DATABASE sonar OWNER sonar;
- Exit the psql shell and switch back to the user by running exit comand
\q
exit
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-8.9.1.44547.zip
- Unzip the sonarqube using following command
sudo unzip sonarqube-8.9.1.44547.zip -d /opt
sudo mv /opt/sonarqube-8.9.1.44547 /opt/sonarqube
- Create a non sudo linux user
sudo adduser sonarq
- Assign permissions to sonarqube directory
sudo chown -R sonarq:sonarq /opt/sonarqube/
- Sonarqube uses the elastic search service so increase vm max map
sudo sysctl -w vm.max_map_count=262144
- Open the Sonarqube properties file
sudo nano /opt/sonarqube/conf/sonar.properties and change the following properties
sonar.jdbc.username=sonar
sonar.jdbc.password=P@ssword
sonar.jdbc.url=jdbc:postgresql://localhost/sonar
sonar.web.javaAdditionalOpts=-server
- Configure Sonarqube as service
sudo nano /etc/systemd/system/sonar.service
- Add the following content to sonar.service
[Unit]
Description=SonarQube service
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/opt/sonarqube/bin/linux-x86-64/sonar.sh start
ExecStop=/opt/sonarqube/bin/linux-x86-64/sonar.sh stop
User=sonarq
Group=sonarq
Restart=always
[Install]
WantedBy=multi-user.target
- Now enable and start sonarqube
sudo systemctl enable sonar
sudo systemctl start sonar
sudo systemctl status sonar
- Now access the sonarqube with the ip address of the server
http://<ipaddress>:9000. Login into sonarqube with default credentails username: admin and password: admin
Like this:
Like Loading...