This is a setup guide for SonarQube in production using MySQL as DB.
Operating System: Ubuntu
Software/Tools:
- Docker (official installation guide)
- install by running command:
wget -qO- https://get.docker.com/ | sh
- install by running command:
- MySQL client
- install by running command:
sudo apt-get install mysql-client
- install by running command:
-
On hosting server
- Start MySQL container:
docker run --name sonardb -p 3306:3306 -v /opt/sonarqube/data/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=sonar -e MYSQL_DATABASE=sonar -e MYSQL_USER=sonar -e MYSQL_PASSWORD=sonar -d mysql:5.6
- Check status:
docker logs -f sonardb
Wait until you see "MySQL init process done. Ready for start up." in the log.
- Start SonarQube container linked to MySQL:
docker run --name sonarqube --link sonardb:mysql -p 9000:9000 -e SONARQUBE_JDBC_USERNAME=sonar -e SONARQUBE_JDBC_PASSWORD=sonar -e SONARQUBE_JDBC_URL="jdbc:mysql://mysql:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance" -v /opt/sonarqube/extensions/plugins:/opt/sonarqube/extensions/plugins -d sonarqube:5.1.1
- Check status:
docker logs -f sonarqube
Wait until you see "Process[web] is up" in the log.
-
Go to http://hostname:9000/ to access SonarQube dashboard (default Admin user name: admin, password: admin)
docker restart sonardb
docker logs -f sonardb
Wait unitl see "mysqld: ready for connections." in the log.docker restart sonarqube
docker logs -f sonarqube
Wait unitl see "app[o.s.p.m.Monitor] Process[web] is up" in the log.
On host server, first run below command
mysqldump --host=localhost --port=3306 --protocol TCP -u sonar -p sonar --single-transaction --databases sonar > sonardb_backup-<date>.sql
(password: sonar)
Then, store the backup sql file to a secure place.
Back up folder/directory:
- /opt/sonarqube/extensions/plugins
On host server, navigate to folder/directory where DB backup file is stored. Then, run below command
mysql --host=localhost --port=3306 --protocol TCP -u sonar -p sonar < backup_file.sql
(password: sonar)
Put back backup folders/directories.
Refer: http://docs.sonarqube.org/display/PLUG/Jenkins+Plugin
Refer: https://wiki.jenkins-ci.org/display/JENKINS/Plugins#Plugins-Howtoinstallplugins
Refer: http://docs.sonarqube.org/display/PLUG/Configuring+Jenkins+SonarQube+Plugin
Only need to config below parameters, the rest can leave as default
- Server URL
http://<hostname or ip>:9000
- Database URL
jdbc:mysql://<jenkins>:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance