Install Prometheus and Grafana in AWS ubuntu ec2 server & node exporter in web server
Step-1
For installing prometheus in aws ec2 instance ,i choose instance type t2 medium and launch a ubuntu instance.
Then connect the instance with localy through pem key in mobaxterm.
sudo su
#for root access
mkdir /tmp/prometheus
then download prometheus from website prometheus.io
wget https://github.com/prometheus/prometheus/releases/download/v2.45.6/prometheus-2.45.6.linux-amd64.tar.gz
then extract the file
tar -xvzf prometheus-2.45.6.linux-amd64.tar.gz
cd prometheus-2.45.6.linux-amd64.tar
mv prometheus promtool /usr/local/bin
cd ..
groupadd prometheus
cat /etc/group
useradd -s /sbin/nologin -g prometheus prometheus
#to add prometheus user to prometheus group
cat /etc/passwd
#for storage location below
/var/lib/prometheus
#for configuration file located in below address
/etc/prometheus
mv (all prometheus configuration file) t0 /etc/prometheus
for giving permission to prometheus to group ,user,and automatic start follow this instruction.
chown -R prometheus:prometheus /etc/prometheus
chown -R prometheus:prometheus /var/lib/prometheus
chown -R prometheus:prometheus /usr/local/bin/prometheus
chown -R prometheus:prometheus /usr/local/bin/promtool
for create systemd to give cli in systemctl follow this instruction
cd /etc/systemd
cd /system
#create a file prometheus.service
vi prometheus.service
[Unit]
Description=Prometheus Service
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/var/lib/prometheus \
--web.console.templates=/usr/local/share/prometheus/consoles \
--web.console.libraries=/usr/local/share/prometheus/console_libraries
[Install]
WantedBy=multi-user.target
Then prometheus service start finally bellow this command
systemctl daemon-reload
systemctl start prometheus
systemctl status prometheus
systemctl enable prometheus
prometheus dashborad open in brouser
(prometheus server ip address:9090 )
step -2
In this step ,i will create aws ec2 instance for target web-server and install node_exporter and instance type t2micro and launch a ubuntu 22.04 instance.
check the disk some command:
top,free -m,df -h
at first to install node_exporter root previliges require.
sudo su
cd /tmp
Download node exporter from Prometheus.io
wget https://github.com/prometheus/node_exporter/releases/download/v1.8.1/node_exporter-1.8.1.linux-amd64.tar.gz
make a directory in /tmp
mkdir node_exporter
cd node_exporter
wget https://github.com/prometheus/node_exporter/releases/download/v1.8.1/node_exporter-1.8.1.linux-amd64.tar.gz
#extract the file
tar –xvzf node_exporter-1.8.1.linux-amd64.tar.gz
cd node_exporter-1.8.1.linux-amd64
echo $PATH
#(node_exporter ke permission dear jonne group a add
mv node_exporter /usr/local/bin
node_exporter –version
#adding group
groupadd node_exporter
useradd -s /sbin/nologin -g node_exporter node_exporter
cat /etc/passwd
#(node_exporter ke permission dite hobe ja /usr/local/bin/ ache ta)
chown node_exporter:node_exporter /usr/local/bin/node_exporter
#nodeexporter service on korte hobe
cd
cd /etc/systemd/system
vi node_exporter.service #(configuration file likhte hobe)
#node_exporter.service
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=multi-user.target
#running the service in web-server
sudo systemctl daemon-reload
sudo systemctl start node_exporter
sudo systemctl enable node_exporter
sudo systemctl status node_exporter
ip:9100 running page
step-3
How to connect Prometheus to node_exporter web
cd /etc/prometheus
ls
cat Prometheus.yaml
vi Prometheus.yaml #( job create korte hobe node_exporter ke connect korar jonne)
#prometheus.yaml
- job_name: "web-app"
static_configs:
- targets: ["3.110.225.132:9100"
Systemctl restart prometheus
ip add:9090
But if prometheus server and target server security group e port must allow to edit endbound rule and allow port 9090;9100 and 3000(grafana)
step-4
For install grafana in prometheus server download gpg key
wget -q -O - https://packages.grafana.com/gpg.key | gpg --dearmor | sudo tee /usr/share/keyrings/grafana.gpg > /dev/null
#Next, add the Grafana repository to your APT sources
echo "deb [signed-by=/usr/share/keyrings/grafana.gpg] https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
#Refresh your APT cache to update your package lists:
sudo apt update
sudo apt install grafana
sudo systemctl start grafana-server
sudo systemctl status grafana-server
sudo systemctl enable grafana-server
grafana login in dashboard:
Enter admin
into both the Email or username and Password fields and then click on the Log in button.
port allow in aws inbound rule 3000.