Install SonarQube with MySQL database on CentOS - saviovettoor/DevOps-wiki GitHub Wiki

unzip <downloaded_sonar_zip> -d /opt/

Setup MySQL database for Sonar

]# mysql -u root -p

mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;

mysql> CREATE USER 'sonarqube' IDENTIFIED BY 'password';
mysql> GRANT ALL ON sonarqube.* to sonarqube@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> EXIT;

Update Sonar Configuration

Edit **sonar.properties** files at <base_dir>/sonarqube/conf
* Update sonar database **sonar.jdbc.username** and **sonar.jdbc.password** properties. Uncomment below lines and update the credentials if required.
		sonar.jdbc.username=sonarqube
		sonar.jdbc.password=password
* Update Database connection - Uncomment **sonar.jdbc.url** property and update the hostname and port if required
		sonar.jdbc.url=jdbc:mysql://localhost:3306/sonarqube?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false

NOTE: If starting sonarqube with root user

* Navigate to sonarqube bin directory
	]#cd <base_path>/sonarqube/bin/linux-x86-64
update configure SonarQube to run as a sonarqube user
	make the change in sonar.sh
	change RUN_AS_USER=sonarqube

Make sure that "sonarqube" user you have created 
	]#adduser sonarqube
Otherwise when you start sonar you will see following error.
	groups: sonarqube: no such user
	chown: invalid user: ‘sonarqube:sonarqube’
	su: user sonarqube does not exist

Start and Stop

  • Navigate to sonarqube bin directory
# cd <base_path>/sonarqube/bin/linux-x86-64
  • Start Sonarqune
# ./sonar.sh start

Note: The initial startup takes some time. Please check the log <base_path>/sonarqube/logs/sonar.log for the startup status

  • Stop sonarqube
# ./sonar.sh stop

Setup/Update the database

Open the url http://HOSTMACHINE_IP>:9000/setup on your browser and wait for the process to complete. The page will be automatically redirected to http://HOSTMACHINE_IP:9000/ once the database setup is complete.

The Sonarqube WebUI

Browse http://localhost:9000/ for the sonar WebUI
Note: the default admin credentials for sonarqube is admin/admin

Install plugins on sonarqube

* Get the plugins from http://docs.sonarqube.org/display/SONAR/Plugin+Library
* Copy the plugins jar files to <base_path>/sonarqube/extensions/plugins/ directory
* Restart the sonarqube
* Once the webui is up, login as admin and open the settings page. You'll be able to see all plugins there.
Note: If the plugin is not compatible with the sonarquve version that you are running, you'll be seeing that in the error logs.

That's it!! Your sonarqube is ready!

⚠️ **GitHub.com Fallback** ⚠️