Setup SonarQube with PostgreSQL Database | How to setup Sonarqube with Database

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back in previous lectures we have seen how to what is sonar cube and how to install sonar cube next understanding the sonar cube gui in this lecture again i am trying to show you how to install sonar cube but it is little bit different why because whenever you install sonar cube by default it is going to use default database but in this case i am going to create a database as a separate one why because in production ready environments that is how we need to set it up i have already done similar kind of video for the around sonar cube version 6.x but now they have done some changes and they withdraw the support for the mysql databases that is the reason i am trying to create this document once again at this moment sonar cube is supporting only for mysql server rcl and postgresql databases so in this case we are going to see how to setup sonarqube with the postgres sql and these are the instructions which we need to follow but before that i have already explained this diagram in our previous lecture but let me quickly explain so there is a sonar scanner where you are have there is a sonar scanner is kind of agent for your sonar cube server and it resets on the system where you have a source code so it runs the source code it's it's runs the it runs the analysis on source code and generate a report this report it is going to share with the sonar cube and it stores in the database whenever whenever you want to retrieve the database you are going to use the search server like elasticsearch to retrieve the data in the web server that is how it works so the major components on this one is a web server and elastic search and the database so these are the three major components we are having on the center cube now we are going to use these two as one server now we can set up now we can set up these two in one server and this one in setup and this one in the separate system but for this demo i'm setting up all this in the same system however i will treat however i am going to install database separately and install sonar keep separately and will integrate these two that is what we that is what i am going to do and the next thing there are some system requirements which we need to follow and also some steps we need to follow some steps we need to follow which are not mentioned in this document so with all those steps i have created a separate document in my github repository called devops and if you go here in the integration with this if you go here you if you see here sonarcube with database in this document i kept all the syst all all the steps and there is one more there is one more there is one more document that is setups on our cube it is inbuilt database okay anyway we have covered this in the previous lectures now it's time to cover this one let's go inside and i have set up all the steps which we need to follow first thing is prerequisites we need an ec2 instance this time we are going to use the ubuntu system with the t2 smart why because we need 2 gb ram minimum next to install java 11 so to install java 11 we can use this one and to list out and to install so first we need to update to install java first we need to update then we can check for the then we can check for the open jdk and install open jdk next these steps i have copied from the postgresql official website so these are the steps to install postgrade database okay this is to add the repository and key once that is done we can install the postgre database after that we should create password for the user whenever we install database it will create a user called postgres and we are setting up the password for that after that we need to create a database and a database user where we are going to grant access to the database in this case we are creating a sonar cube as a database and its owner as a database user after that we need to restart our postgresql services so that it will take effect next postgresql postgre postgre postgresql is going to run on 543 to port you can just check it out by using the net start minus tulpn if it is not working try to if you if it is not working use this command to install netstart use this command to install netstat after that remaining steps i have copied from the sonar cube official documentation so we need to do some system configuration changes that is slash edcctl.conf so these are the number of files you limits all this stuff and also we need to add the limits once this is done we need to reboot our system to take it effective it is it is not going to take effect immediately after that the this after that this procedure is to download sonarcube and setup so these are the steps to download and i was discussing about the sonar properties file in our previous lecture where we need to update the username and password and some of the other information we should update and this is actually talks about the database if you have your database in your local system you can use the localhost and if it is in another system you need to specify the another system with the port number so that it can able to connect with your database all right after that to run sonar cube as a service this is the file we just need to create it is a extra step i can say otherwise you need to go to this location and you can execute it and one more thing is this is what we need to concentrate if we are going to download it under opt and we are not renaming it to sonar cube it doesn't work as expected maybe i will explain while doing it okay for now let it be and at last what we need to do is we need to give ownership to the our sonar cube directory to the sonar user why because we should not run sonarcube service as a root user that is what we told and we have encountered an issue with the elasticsearch as well when we were doing the sonar cube setup in our previous lectures okay at last we are going to at last we are going to reload and we will start the sonar keep service so for this we need an easy to instance that to ubuntu system why because the steps which we are following over here are belongs to the ubuntu operating system so let's go here and start setting up a ubuntu system and i am choosing the ubuntu system and this time this is t2y because we are going to use it for the sonar cube as well it requires the 2gb ram and the name so not so normal cube i'm giving okay there could be another server with the sonar cube name and select the security group not this one yep sonarqube server and launch it all right so it may take a while meantime what i will show you is okay in case if you are encountering any issue while following these steps you just need to cross check these steps that is you should open the port number 9000 in the security group which i have already done and start the sonar cube service as a sonar user in this case sonar is the user and use the correct database credentials in the sonar properties and this is use not user use instance which has at least 2 gb of ram all right so i hope this system could be ready by this time let's connect to the system copy the public ip and ssh let me load the key pair and ubuntu okay username is ubuntu for the ubuntu system alright i have connected to this system and clear the screen let me become a root because we are doing administrative activities and go back to our documentation so we need to install java so this is before installing java this is to update all right updation is completed now i am going to install java apt list which will show you the i think all the files out of this we are going to grip java open jdk 11 right okay open jdk -11 yep so open jdk -11 among this we are going to use the open jdk 11 jdk jdk nothing but java development kit usually it is necessary if you are doing the development but for us jre is sufficient but however if you install jdk it automatically brings the jre as well so let's install jdk apt install just to install is okay java installation all right java all right java installation is completed next thing is we need to install post gray postgresql so let's go back and these are the steps to install postgresql first thing is we are adding the repository then adding the key next we are updating our next we are updating our system with the latest files then install the postgresql okay that's it let's copy it and go to the system and install it all right database installation is successful you can cross check your database by using systemctl status postgresql okay it is active now now next thing is we need to do some modifications next thing we need to create the database before that if you see the next thing is we need to create a database for sonar cube before that we just need to see the user which is created by the postgres database that is postgres and i am going to set up the password for this and postgres i have given devops at one two three anyway so pass now password has been obtained and let's switch to postgresql user now we are going to create a database user the database username is user now we are going to create a database user database user can be anything we can use the sonar admin or zone or anything so in this case i'm using sonar okay create user so as a database user i am creating a user that is sonar once you have created you can switch to the psql to jump into the database and here we need to create tables and grant ownership to the sonar user so what does it mean that first thing we are adding the sonar as your admin user in the database level we are adding we are giving the password for the sonarqube user as a admin that is encrypted then we are creating a dot next we are creating a database with sonar cube next we are creating a database as a sonar cube and owner is owner and we are granting all previous privileges on the database to the sonar keyboard to date next we are going to grant all privileges of your sonar cube database to sonar scan sorry sonar user okay that is the meaning let's copy this and create this database okay i think double time it got copied anyway so we have granted access that's it next thing we just need to restart our sonar postgres sorry we just need to restart our postgres database so we need to just to restart our postgresql so let's oops okay restarted and if we want to see the oops not here i need to come out from the database and let's restart oops even not as a user we need to run it as a root user okay we just restarted it now if i check the status okay it is running so now it is so now it is running so now it is running let's go back and next thing is we need to do some operating system level modifications for that yeah one last thing is we need to check that whether it is running on port number 5432 or not only thing is net start minus ulpn okay if it is not working it is clearly giving the instruction okay by using this one you can install the net start command next if i run the same command now you can see your database 543t sorry 5432 it is running up so postgresql is running on 5432 5432 all right next so next we are going to do some operating system changes operating system level changes so we just need to copy it and if you want to know more about it just copy this url and you can see the all the requirements over here hardware requirements is 2gb and java 11 is required and if you scroll down okay you can see here you can set this dynamically this is dynamically however we need to keep it as a permanent that's the reason i have it that's the reason i'm updating in the slash utc slash slash utc ctl.com file similar way these are also these also so i'm updating in this file all right let's go and do that one va so sorry here right this is the file and shift g i'm just going to end of this one and insert mode now copy the values and save this file similar way we are going to update the limits files va slash ctc security limits shift g o copy the values which we need to update and save this file that's it and to make it effect we need to reboot it so you need 6 i'm giving unit 6 is a command to reboot your system even reboot also could work depends upon the linux operating systems once our system is up we are going to set up the sonar cube so meantime you can download the sonar cube from here so if you click over here i think i have already explained in our previous lectures that okay we have different editions we are going with the community edition why because it is free and open source and remaining you can still use it by enabling the free trial so this is the lta version long term support so we are going to use the long term support one sorry cancel so i will just copy it into my sys clipboard so let's go back i think our system might be up by this time so it's still coming up all right so it's up now let me become a root again clear the screen and cd opt so for under opt nothing is there so w get under the link [Music] okay all right we have downloaded it let's extract it sorry gun zip not even unzip sorry unzip sonar cube okay unzip is not installed apt install unzip now let's run it again and i'm going to rename it this is what we are going to talk okay let it be for now and let's go here okay now we need to update the sonar cube jdbc user okay you know right username and password let's go and connect with this system that we need to update under conf directory so we have a sonar dot properties just editing and by default all the parameters are commented out so i'm uncommenting this so username is we have created it as a sonar right and password is admin okay if you do remember those information we have specified over here okay create user this is database user and password okay once that is done we need to update this parameter as well jdbc url this is where we need to specify our database and if you come down little bit okay you can see here post gray sql okay postgresql 9.3 or later postgresql 9.3 or greater we should use it okay anyway we are using around 12 i think i missed it to show you that but anyway you just need to uncomment it and another thing is our database is located in our local system that is the reason we need to specify it localhost if it is in another system we need to specify the ip address of another system that is the only change and this current schema is not required just till sonar cube is sufficient and one last thing is this is mysql and let me search one last parameter that is sonar search okay so slash yep this is where we need to do uncomment it that's it okay that's it now let's save this file now what do i mean what i have done is in our sonarqube properties instead of using the default database you just go and connect with the database which we just created that's it once that is done okay we want to add our sonar cube service as a sonar cube as a service so for that one we need to execute it i have already done the cat so it is going to create this file and add this content to that file so that's what i'm going to do before that let me check this file okay so this file doesn't exist and i'm creating it in one chart enter okay now this file is has been created and content has been added and if you see the uh stuff we are starting it as a sonar user and group also sonar and execution start so where is your sonar.sh but in this case our directory name is sonar cube minus dot 8.9.2 slash so and so dots also so this we need to change it as a just to sonar cube then only it will be possible to start otherwise you need to give this name in in this location okay either way does work and if you go come out i mean to say if you come out from the conf directory and if you do ll and go to bin here we have here linux and ll so this is where we have a sonar cube dot sh is that if you do the pwd so this is the path you need to mention here okay but uh here just a sonar cube is there so to make it aligned what i will do i will go to opt and i will move this one to just to sonar cube so that it will be aligned with the what information we have provided in the exec start and stop location okay that's it and one last thing we need to do is owning the sorry giving the ownership of this slash opt sonar cube to sonar user what i am doing is user ad i am creating a user called sonar while creating just to make the slash opt sonar cube as his home directory minus d nothing but a directory that is one thing i'm doing so i have done that and we need to give ownership still it is owned by the root only if you check ls minus l sorry okay you can see still it is owned by the root c h 1 minus r our sonar colon sonar on opt okay now if i check it should be owned by the sonar user that's it now let's start the sonar cube so before that we just need to reload the daemon and system seat here start sonar cube dot service okay so there is a typo let me copy it here system ctl start sonar cube.service okay so let's enter and if i check now maybe you might be think that okay i'm starting it as a route no because we have updated in the configuration that whoever starting it it has to start with the sonar user only so now ps minus ef grip so now if i search yes it started and if you see the user it is sonar user and also net start minus tulpn it should be running on port number 9000 yes it's running and let's connect to our database sorry sonarcube server okay what is our ec2 instance ip this is the public ap colon 9000 all right it is getting ready once it is ready we are going to set up the password and we will see nice now give the username as a admin password also admin and no need to save let's uh change the admin password okay that's it we have set up the sonar cube and this one i have already explained to understand the sonar cube console in our last video if you haven't checked it please go and check it out and in next video i am going to integrate this sonar cube server with the jenkins so that you can understand how we can run the projects from the jenkins and also in our previous lecture we have seen how to integrate sonarqube with the maven as well right all right so that's all for this lecture i hope all right that's all for this lecture i hope you found this video available okay that's all for this lecture okay that's all for this lecture i hope you found this available that's all right that's all for this lecture i hope you found this video valuable please show your support by subscribing to our channel or give a thumbs up if you like this video and we like to hear you please comment out in the chat window if you have any questions thank you see you in the next video
Info
Channel: Valaxy Technologies
Views: 16,487
Rating: undefined out of 5
Keywords: aws, devops, valaxy technologies, security, automation, serverless, lambda, linux, linux for beginners, linux basics, linux for cloud and devops engineers, linux for cloud engineers, linux for aws engineers, learn linux for basics
Id: gH1EQTRbeIw
Channel Id: undefined
Length: 28min 33sec (1713 seconds)
Published: Mon Sep 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.