Friday, 18 February 2022

SonarQube installation on Ubuntu 20.04

1)  Update System

sudo apt-get update && sudo apt-get upgrade -y

2) Install open-jdk

sudo apt-get install openjdk-11-jdk -y


3) Download the SonarQube software.

cd /opt
sudo wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.6.zip


4) Extract SonarQube software

sudo unzip sonarqube-7.6.zip
sudo mv sonarqube-7.6 sonarqube


5) Please change permissions  ( Update user as per requirement )

cd /opt/
sudo chown -R vagrant:vagrant sonarqube

6) Start Sonar

cd /opt/sonarqube/bin/linux-x86-64
./sonar.sh start


You should able to access SonarQube over 9000 port now. By default admin/admin will be credentials for SonarQube.

If you are using VM or Vagrant please enable port forwarding.





7) Enable Sonar as service on Ubuntu
Create sonar service file
sudo vi /etc/systemd/system/sonarqube.service

Add  below content to above file. If you want to change user to run sonarqube process please update User and Group.

[Unit]
Description=SonarQube service
After=syslog.target network.target

[Service]
Type=simple
User=vagrant
Group=vagrant
PermissionsStartOnly=true
ExecStart=/bin/nohup java -Xms32m -Xmx32m -Djava.net.preferIPv4Stack=true -jar /opt/sonarqube/lib/sonar-application-7.6.jar
StandardOutput=syslog
LimitNOFILE=65536
LimitNPROC=8192
TimeoutStartSec=5
Restart=always

[Install]
WantedBy=multi-user.target



8) Start and Enable Sonar Service
sudo systemctl start sonarqube
sudo systemctl enable sonarqube


9) Check SonarQube status to ensure it is working as expected.
sudo systemctl status  sonarqube


Jenkins installation on Ubuntu 20.04

1)  Update System

sudo apt-get update && sudo apt-get upgrade -y

2) Install open-jdk

sudo apt-get install openjdk-11-jdk -y


3) Add Jenkins key.
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
4) Configure Jenkins repo.
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'

5) Update system
sudo apt-get update

6) Install Jenkins.
sudo apt-get install jenkins -y

6) Once Installation of Jenkins is completed start jenkins service.
sudo systemctl start jenkins

7) Enable Jenkins service to be restart on system reboot
sudo systemctl enable jenkins

8) By Default Jenkins will run and accessible over 8080 port. We need to open port to access in our browser if we are using Jenkins on Virtual Environment.

i) If you are using Vagrant please add below line to Vagrantfile and restart vm.
config.vm.network "forwarded_port", guest: 8080, host: 8080

ii)  If you are using Oracle VirtualBox please follow below steps to open 8080 port
Right Click on VM and go to settings.



Click On Network and expand advanced button.


Click on Port Forwarding button and add a new port mapping as mentioned in below screen.


9) Once you finished above step you should able to access Jenkins on your favorite browser.


10) You need to copy the password from  /var/lib/jenkins/secrets/initialAdminPassword to text box and click on continue.

sudo cat /var/lib/jenkins/secrets/initialAdminPassword


11) Click on Suggested Plugin Installation. This will install all required plugins to start with CI & CD pipeline.






Apache Tomcat 9 Installation on Ubuntu 20.04


1)  Update System

sudo apt-get update && sudo apt-get upgrade -y


2) Install open-jdk

sudo apt-get install openjdk-11-jdk -y


3)  Download Apache Tomcat and extract tomcat to your Linux Machine

cd /opt/

sudo wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.50/bin/apache-tomcat-9.0.50.tar.gz

sudo tar -zxvf apache-tomcat-9.0.50.tar.gz

sudo mv apache-tomcat-9.0.50 tomcat

sudo chmod -R 777 tomcat

# Update vagrant user as per your requirement

sudo chown -R vagrant:vagrant tomcat


4) Configure Apache Tomcat 9 as system service. 

Open tomcat service file sudo vi /etc/systemd/system/tomcat.service

Add below content.

[Unit]

Description=Tomcat 9

After=network.target

[Service]

Type=forking

# Update users as per target machine

User=vagrant

Group=vagrant

Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"

Environment="CATALINA_BASE=/opt/tomcat"

Environment="CATALINA_HOME=/opt/tomcat"

Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"

ExecStart=/opt/tomcat/bin/startup.sh

ExecStop=/opt/tomcat/bin/shutdown.sh

[Install]

WantedBy=multi-user.target

  

5) Start tomcat service

sudo systemctl start tomcat


5) Check tomcat service

sudo systemctl status tomcat


6) Enable tomcat service

sudo systemctl enable tomcat