Skip to content

Commit 248685e

Browse files
unknownunknown
unknown
authored and
unknown
committed
added Sonarqube
1 parent cfc7290 commit 248685e

File tree

3 files changed

+239
-0
lines changed

3 files changed

+239
-0
lines changed

sonarqube/Setup_SonarQube.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Sonarqube Setup
2+
3+
SonarQube is an open-source static testing analysis software, it is used by developers to manage source code quality and consistency.
4+
## 🧰 Prerequisites
5+
6+
Source: https://docs.sonarqube.org/latest/requirements/requirements/
7+
1. An EC2 instance with a minimum of 2 GB Ram (t2.small)
8+
1. Java 11 installation
9+
1. SonarQube cannot be run as root on Unix-based systems, so create a dedicated user account for SonarQube if necessary.
10+
11+
## Installation steps
12+
13+
1. Download SonarQube [latest verions](https://www.sonarqube.org/downloads/) on to EC2 instace
14+
```sh
15+
cd /opt
16+
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-x.x.zip
17+
```
18+
1. extract packages
19+
```sh
20+
unzip /opt/sonarqube-x.x.zip
21+
```
22+
23+
2. Change ownershipt to the user and Switch to Linux binaries directory to start service
24+
```bash
25+
chown -R <sonar_user>:<sonar_user_group> /opt/sonarqube-x.x
26+
cd /opt/sonarqube-x.x/bin/linux-x86-64
27+
./sonar.sh start
28+
```
29+
3. Connect to the SonarQube server through the browser. It uses port 9000.
30+
`Note`: Port should be opened in the Security group
31+
```bash
32+
http://<Public-IP>:9000
33+
```
34+
35+
## 🧹 CleanUp
36+
1. Stop SonarQube server
37+
```sh
38+
cd /opt/sonarqube-x.x/bin/linux-x86-64
39+
./sonar.sh stop
40+
```
41+
1. Terminate EC2 instance incase if you setup only for this lab.
42+
43+
## 📌 Who is using this
44+
People who want to setup SonarQube and would like to integrate with Jenkins
45+
46+
47+
48+
## Additional Resources
49+
50+
- [How to integrate SonarQube wih Jenkins](https://www.youtube.com/c/ValaxyTechnologies/videos)
51+
52+
53+
## 🔗 My Profile
54+
[![portfolio](https://img.shields.io/badge/my_portfolio-000?style=for-the-badge&logo=ko-fi&logoColor=white)](https://www.udemy.com/user/ar-shankar/)
55+
[![linkedin](https://img.shields.io/badge/linkedin-0A66C2?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/ravdsun/)
56+
57+
58+
### 💡 Help/Suggestions or 🐛 Bugs
59+
60+
Thank you for your interest in contributing to our project. Whether it is a bug report, new feature, correction, or additional documentation or solutions, we greatly value feedback and contributions from our community. [Start here](/issues)

sonarqube/Sonarqube_with_database.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
2+
# Sonarqube Setup
3+
4+
SonarQube is an open-source static testing analysis software, it is used by developers to manage source code quality and consistency.
5+
## 🧰 Prerequisites
6+
1. Need an EC2 instance (min t2.small)
7+
2. Install Java-11
8+
```sh
9+
apt-get update
10+
apt-get list | grep openjdk-11
11+
apt-get install openjdk-11-jdk -y
12+
```
13+
14+
## Install & Setup Postgres Database for SonarQube
15+
`Source: https://www.postgresql.org/download/linux/ubuntu/`
16+
1. Install Postgres database
17+
``sh
18+
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
19+
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
20+
sudo apt-get update
21+
sudo apt-get -y install postgresql
22+
```
23+
24+
1. Set a password and connect to database (setting password as "admin" password)
25+
```sh
26+
sudo passwd postgres
27+
su - postgres
28+
```
29+
30+
1. Create a database user and database for sonarque
31+
```sh
32+
createuser sonar
33+
psql
34+
ALTER USER sonar WITH ENCRYPTED PASSWORD 'admin';
35+
CREATE DATABASE sonarqube OWNER sonar;
36+
GRANT ALL PRIVILEGES ON DATABASE sonarqube to sonar;
37+
```
38+
39+
1. Restart postgres database to take latest changes effect
40+
```sh
41+
system restart postgresql
42+
system status postgresql
43+
```
44+
`check point`: You should see postgres is running on 5432
45+
46+
47+
48+
apt install net-tools
49+
50+
`Source: https://docs.sonarqube.org/latest/requirements/requirements/`
51+
52+
1. Added below entries in `/etc/sysctl.conf`
53+
```sh
54+
vm.max_map_count=524288
55+
fs.file-max=131072
56+
ulimit -n 131072
57+
ulimit -u 8192
58+
```
59+
1. Add below entries in `/etc/security/limits.conf`
60+
```sh
61+
sonarqube - nofile 131072
62+
sonarqube - nproc 8192
63+
```
64+
65+
1. reboot the server
66+
```sh
67+
init 6
68+
```
69+
==========================================
70+
71+
## SonarQube Setup
72+
73+
1. Download [soarnqube](https://www.sonarqube.org/downloads/) and extract it.
74+
```sh
75+
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-8.9.2.46101.zip
76+
unzip sonarqube-8.9.2.46101.zip
77+
```
78+
79+
1. Update sonar.properties with below information
80+
```sh
81+
sonar.jdbc.username=<sonar_database_username>
82+
sonar.jdbc.password=<sonar_database_password>
83+
84+
#sonar.jdbc.username=sonar
85+
#sonar.jdbc.password=admin
86+
#sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube
87+
#sonar.search.javaOpts=-Xmx512m -Xms512m -XX:MaxDirectMemorySize=256m -XX:+HeapDumpOnOutOfMemoryError
88+
``
89+
90+
1. Create a `/etc/systemd/system/sonarqube.service` file start sonarqube service at the boot time
91+
```sh
92+
cat >> /etc/systemd/system/sonarqube.service <<EOL
93+
[Unit]
94+
Description=SonarQube service
95+
After=syslog.target network.target
96+
97+
[Service]
98+
Type=forking
99+
User=sonar
100+
Group=sonar
101+
PermissionsStartOnly=true
102+
ExecStart=/opt/sonarqube/bin/linux-x86-64/sonar.sh start
103+
ExecStop=/opt/sonarqube/bin/linux-x86-64/sonar.sh stop
104+
StandardOutput=syslog
105+
LimitNOFILE=65536
106+
LimitNPROC=4096
107+
TimeoutStartSec=5
108+
Restart=always
109+
110+
[Install]
111+
WantedBy=multi-user.target
112+
EOL
113+
```
114+
115+
1. Add sonar user and grant ownership to /opt/sonarqube directory
116+
```sh
117+
useradd -d /opt/sonarqube sonar
118+
chown -R sonar:sonar
119+
```
120+
121+
1. Reload the demon and start sonarqube service
122+
```sh
123+
systemctl daemon-reload
124+
systemctl start sonarqube.service
125+
```
126+
127+
128+
## 🧹 CleanUp
129+
130+
Stop sonarqube services and delete the instance
131+
132+
## Unable to access Sonarqube from browser?
133+
134+
1. Make sure port 9000 is opened at security group leave
135+
2. start sonar service as a sonar user
136+
3. user correct database credentials in the sonar.properties
137+
4. user instance which has atleast 2 GB of RAM
138+
139+
140+
141+
## 🔗 My Profile
142+
[![portfolio](https://img.shields.io/badge/my_portfolio-000?style=for-the-badge&logo=ko-fi&logoColor=white)](https://www.udemy.com/user/ar-shankar/)
143+
[![linkedin](https://img.shields.io/badge/linkedin-0A66C2?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/ravdsun/)
144+
145+
146+
### 💡 Help/Suggestions or 🐛 Bugs
147+
148+
Thank you for your interest in contributing to our project. Whether it is a bug report, new feature, correction, or additional documentation or solutions, we greatly value feedback and contributions from our community. [Start here](/issues)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Integrate Sonarqube wit Jenkins
2+
3+
## 🧰 Prerequisites
4+
1. a Sonarqube Server [Click here to Setup Sonarqube server]()
5+
2. A Jenkins server [Click here to set up a Jenkins server]()
6+
7+
8+
Integration Steps
9+
10+
### On Sonarqube server
11+
12+
1. Generate a sonarqube token to authenticate from Jenkins
13+
14+
### On Jenkins server
15+
16+
1. Install Sonarqube plugin
17+
2. Configure Sonarqube credentials
18+
3. Install SonarScanner (needed only for the pipeline)
19+
4. Run Maven Job
20+
5. Run Pipeline job
21+
22+
23+
## 🧹 CleanUp
24+
25+
Stop sonarqube services and delete the instance
26+
Stop Jenkins service and delete the instance
27+
28+
29+
## 🔗 My Profile
30+
[![portfolio](https://img.shields.io/badge/my_portfolio-000?style=for-the-badge&logo=ko-fi&logoColor=white)](https://www.udemy.com/user/ar-shankar/)
31+
[![linkedin](https://img.shields.io/badge/linkedin-0A66C2?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/ravdsun/)

0 commit comments

Comments
 (0)