Thứ Năm, Tháng Năm 19, 2022
ITFORVN.COM
  • Cloud Computing
    • Azure
    • AWS
    • GCP
    • Cloud Other
  • System
    • Virtualization
    • Microsoft
    • Linux/Unix
    • Databases
    • Monitoring
    • Logging
  • Networking
    • Routing
    • Switch
    • Firewall
  • Security
    • SIEM
    • CIS
    • Audit
  • DevOps
    • CI/CD
    • Docker
    • K8s
    • IaC
  • Resource
    • Tools
    • Documents
    • Download
ITFORVN.COM
  • Cloud Computing
    • Azure
    • AWS
    • GCP
    • Cloud Other
  • System
    • Virtualization
    • Microsoft
    • Linux/Unix
    • Databases
    • Monitoring
    • Logging
  • Networking
    • Routing
    • Switch
    • Firewall
  • Security
    • SIEM
    • CIS
    • Audit
  • DevOps
    • CI/CD
    • Docker
    • K8s
    • IaC
  • Resource
    • Tools
    • Documents
    • Download
ITFORVN.COM

[Prometheus từ A đến Z] Phần 01. Cài đặt Prometheus và Grafana trên CentOS 7

hieuit1506 bởi hieuit1506
27/06/2019
trong Monitoring
Reading Time: 10 mins read
A A
0
Trang chủ System Monitoring
0
Chia sẻ
11.3k
xem
Share on FacebookShare on Twitter

Bài viết chỉ mang tính chất tham khảo và chia sẻ, các trong quá trình làm chắc chắn sẽ có bạn gặp bug. Nếu gặp bug thì vào telegram group ITFORVN để nhờ support từ cộng đồng. Hoặc các bạn thể có truy cập vào nguồn tham khảo để làm theo hướng dẫn chính thống. Ngoài ra bạn có thể tham gia Forum Google [prometheus-users] của nước ngoài để hỏi đáp. 

Lời đầu tiên mình xin lỗi tất cả vì không thể lên bài như đúng hẹn được, do thời gian này mình khá bận với công việc. Mình mong mọi người thông cảm và tiếp tục đồng hành cùng gia đình ITFORVN.

Tiếp nối thành công của khóa học Docker từ Mr Tấn, mình sẽ ứng dụng thực tế docker và hệ thống monitoring này, để mọi người có thể được trải nghiệm cách làm việc với container, images, …

Trong bài này mình sẽ hướng dẫn các bạn cài đặt Prometheus và Grafana bằng 2 cách.

Cách 01: Cài đặt Prometheus bằng Docker.

Cách 02: Cài đặt Prometheus bằng Package.

 

I. Cấu hình chung cho hệ thống trước khi bạn cài đặt Prometheus: 

  • Update linux,  sync NTP linux, disables selinux

Chạy lệnh : 

yum update -y
ntpdate 1.ro.pool.ntp.org
vim /etc/sysconfig/selinux

Change “SELINUX=enforng” to “SELINUX=disabled”.

Save và exit file. Sau đó reboot lại server.

  • Cài iptables thay thế cho firewalld trên Centos 7

=> Do mình thích sử dụng iptables hơn là firewalld.

Bước 1: remove firewalld 

systemctl stop firewalld
systemctl disable firewalld
systemctl mask --now firewalld

Bước 2: Cài đặt Iptables

yum install iptables-services -y
systemctl start iptables
systemctl enable iptables

Mở các port sau: 

-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3000 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 9090 -j ACCEPT

II. Cài đặt prometheus bằng Docker

  • Cài đặt Docker

Link tham khảo: https://docs.docker.com/install/linux/docker-ce/centos/ 

Bước 1: Cài các gói cần thiết

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

Bước 2: Cấu hình docker-ce repo

sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

Bước 3: Cài đặt docker-ce

sudo yum install docker-ce docker-ce-cli containerd.io
systemctl enable docker
systemctl restart docker

Check docker version

docker vesion
  • Cài đặt prometheus với docker

Có 2 cách:

Cách 1: Bạn có thể pull trực tiếp image về và dùng

Search Images: 

docker search prometheus

Thông tin Image trực tiếp từ trang chủ: https://hub.docker.com/u/prom 

Bước 1: Tải image về: 

docker search prometheus

Bước 2: Run docker với image mình đã pull về

docker run --restart=always --mount source=prometheus-data,target=/prometheus --mount source=prometheus-config,target=/etc/prometheus --name prometheus -d -p ip-prometheus:9090:9090 prometheus

Cách 2 (khuyến nghị): Git clone code về sau đó build image

=> Cách này có thể kiểm soát dc code

Dùng git clone để download code về local

git  clone https://github.com/prometheus/prometheus
cd prometheus/

Sử dụng Go Lang để build  file config của prometheus (binary)

make build

Edit Dockerfile -> check xem Dockerfile 

Ở đây mình check thấy đường dẫn không đúng và mình chỉnh lại cho phù hợp

1 1 - [Prometheus từ A đến Z] Phần 01. Cài đặt Prometheus và Grafana trên CentOS 7

Hình 01. [Monitor System từ A đến Z] Phần 01. Cài đặt Prometheus và Grafana trên CentOS 7

Build Image:

dcker image build -t prometheus:latest .

Run Image sau mình đã build 

docker run --restart=always --mount source=prometheus-data,target=/prometheus --mount source=prometheus-config,target=/etc/prometheus --name prometheus -d -p 9090:9090 prometheus

Check lại kết quả image đang chạy:

docker ps

2 1 - [Prometheus từ A đến Z] Phần 01. Cài đặt Prometheus và Grafana trên CentOS 7

Hình 02: [Monitor System từ A đến Z] Phần 01. Cài đặt Prometheus và Grafana trên CentOS 7

Truy cập vào Prometheus: http://IP:9090

3 1 - [Prometheus từ A đến Z] Phần 01. Cài đặt Prometheus và Grafana trên CentOS 7

Hình 03: [Monitor System từ A đến Z] Phần 01. Cài đặt Prometheus và Grafana trên CentOS 7

Note :

docker run:  lệnh dùng để chạy docker

–restart=always: khởi động lại image sau khi docker start lại

. tượng trưng cho thư mục hiện tại chứa Dockerfile

–mount source=prometheus-data,target=/prometheus: kỹ thuật dùng mount data tránh mất datda khi mình xóa container

Thường mình sẽ inspect image ra để xem nên mount những thư mực nào.

docker image inspect prometheus

4 1 - [Prometheus từ A đến Z] Phần 01. Cài đặt Prometheus và Grafana trên CentOS 7

Hình 04: [Monitor System từ A đến Z] Phần 01. Cài đặt Prometheus và Grafana trên CentOS 7

=> Nhìn hình mình sẽ cần mount Workingdir và thư mực chức file config chính.

-d -p 9090:9090: Nat port bên ngoài vào port container

  • Cài đặt grafana

Bước 1:  Pull image grafana về local

docker pull grafana/grafana

Bước 2: Run image grafana

docker run --restart=always -d -p 3000:3000 grafana/grafana 

=> Mình không mount thư mực vì mình check image không có gì đễ lưu

Truy cập vào Grfana: http://IP:3000

5 1 - [Prometheus từ A đến Z] Phần 01. Cài đặt Prometheus và Grafana trên CentOS 7

Hình 05: [Monitor System từ A đến Z] Phần 01. Cài đặt Prometheus và Grafana trên CentOS 7

=> Passwork mặt định là admin/admin, và sau đó sẽ đổi password sau lần đầu tiên đăng nhập

Bước 3: Connect Grafana tới prometheus

Chọn Configuration, sau đó chọn data source type là Prometheus

6 1 - [Prometheus từ A đến Z] Phần 01. Cài đặt Prometheus và Grafana trên CentOS 7

Hình 06: [Monitor System từ A đến Z] Phần 01. Cài đặt Prometheus và Grafana trên CentOS 7

Nhập thông tin của prometheus, sau đó save lại.

7 1 - [Prometheus từ A đến Z] Phần 01. Cài đặt Prometheus và Grafana trên CentOS 7

Hình 07: [Monitor System từ A đến Z] Phần 01. Cài đặt Prometheus và Grafana trên CentOS 7

=> Như vậy chúng ta đã hoàn thành việc kết nối giữa Grafana và Prometheus

II. Cài đặt Prometheus bằng Package

  • Cài đặt prometheus

Download here: https://prometheus.io/download/

wget https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.linux-amd64.tar.gz
tar -xvzf prometheus-2.10.0.linux-amd64.tar.gz
mv prometheus-2.10.0.linux-amd64 /usr/local/prometheus/

Tạo service prometheus trong systemd

vim /etc/systemd/system/prometheus.service

Nội dung file là:

[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
ExecStart=/usr/local/prometheus/prometheus \
--config.file /usr/local/prometheus/prometheus.yml \
--storage.tsdb.path /usr/local/prometheus/ \
--web.console.templates=/usr/local/prometheus/consoles \
--web.console.libraries=/usr/local/prometheus/console_libraries

[Install]
WantedBy=multi-user.target

 

Restart và enable services.

systemctl daemon-reload
systemctl start prometheus
systemctl status prometheus
  • Cài đặt Grafana

https://grafana.com/grafana/download

wget https://dl.grafana.com/oss/release/grafana-6.2.1-1.x86_64.rpm
sudo yum localinstall grafana-6.2.1-1.x86_64.rpm
sudo service grafana-server start
sudo /sbin/chkconfig --add grafana-server
systemctl daemon-reload
systemctl start grafana-server
systemctl status grafana-server
sudo systemctl enable grafana-server.service

Truy cập vào Grfana: http://IP:3000

5 1 - [Prometheus từ A đến Z] Phần 01. Cài đặt Prometheus và Grafana trên CentOS 7

Hình 08: [Monitor System từ A đến Z] Phần 01. Cài đặt Prometheus và Grafana trên CentOS 7

Sau bài này mình sẽ tiếp tục hướng dẫn mọi người đưa các thiết bị vào để monitor. Ví dụ như Server Windows, Server Linux và monitor những thiết bị mạng qua snmp.

 

Bài viết chỉ mang tính chất tham khảo và chia sẻ, các trong quá trình làm chắc chắn sẽ có bạn gặp bug. Nếu gặp bug thì vào telegram group ITFORVN để nhờ support từ cộng đồng. Hoặc các bạn thể có truy cập vào nguồn tham khảo để làm theo hướng dẫn chính thống. Ngoài ra bạn có thể tham gia Forum Google [prometheus-users] của nước ngoài để hỏi đáp.

Tác giả:  Nguyễn Hiếu – ITFORVN.COM

To you support to be access :  Nhóm Facebook ITFORVN

 

Tất cả bài viết về prometheus tại đây.

Giới thiệu về giải pháp giám sát hệ thống Prometheus và Grafana

Phần 01 – Cài đặt Prometheus và Grafana trên Centos 07

Phần 02 – Giám sát Windows Server với Prometheus

Phần 03 – Giám sát firewall Fortigate với Prometheus

Phần 04 – Giám sát thiết bị mạng Cisco với Prometheus

Phần 05 – Giám sát firewall Pfsense và Linux Server với Prometheus

Phần 06 – Giám sát VMWARE với Prometheus

Phần 07 –  Cấu hình alert trong Prometheus và gửi tin nhắn qua telegram

The: Prometheus
Bài trước

Thành Phần – Nguyên Lý – Cách Hoạt Động Và Lưu Trữ Dữ Liệu Của Ổ Cứng Cơ (HDD & SAS)

Bài kế tiếp

Mảng mới OneDrive Personal Vault của Microsoft bảo vệ một thư mục với 2FA (Two-factor Authentication)

hieuit1506

hieuit1506

Bài viết liên quan

[Prometheus từ A đến Z] Phần 07. Cấu hình Alert trong Prometheus gửi tin nhắn qua telegram
Monitoring

[Prometheus từ A đến Z] Phần 07. Cấu hình Alert trong Prometheus gửi tin nhắn qua telegram

25/05/2020
[Prometheus từ A đến Z] Phần 06. Giám sát Vmware với Prometheus
Monitoring

[Prometheus từ A đến Z] Phần 06. Giám sát Vmware với Prometheus

25/05/2020
[Prometheus từ A đến Z] Phần 05. Giám sát firewall pFsense và Linux server với Prometheus
Monitoring

[Prometheus từ A đến Z] Phần 05. Giám sát firewall pFsense và Linux server với Prometheus

22/05/2020
Bài kế tiếp
Mảng mới OneDrive Personal Vault của Microsoft bảo vệ một thư mục với 2FA (Two-factor Authentication)

Mảng mới OneDrive Personal Vault của Microsoft bảo vệ một thư mục với 2FA (Two-factor Authentication)

Hướng Dẫn Flash Dell PERC H310Mini Sang Firmware LSI IT Mode Để Chạy SDS

Hướng Dẫn Flash Dell PERC H310Mini Sang Firmware LSI IT Mode Để Chạy SDS

0 0 votes
Article Rating
Subscribe
Connect with
Login
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Notify of
guest
Connect with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
guest
0 Comments
Inline Feedbacks
View all comments

Bài viết hay

Mảng mới OneDrive Personal Vault của Microsoft bảo vệ một thư mục với 2FA (Two-factor Authentication)

Mảng mới OneDrive Personal Vault của Microsoft bảo vệ một thư mục với 2FA (Two-factor Authentication)

28/06/2019
Microsoft Azure Toàn Tập – Lab 1: Tạo máy ảo trong Azure với Azure Resource Manager

Microsoft Azure Toàn Tập – Lab 1: Tạo máy ảo trong Azure với Azure Resource Manager

30/12/2017
Remote work: RDS vs. VDI vs. VPN

Remote work: RDS vs. VDI vs. VPN

18/05/2020
ITFORVN

KIẾN THỨC LÀ 1 NGỌN LỬA, CHIA SẺ CÀNG NHIỀU NÓ CÀNG BÙNG CHÁY MẠNH

Chuyên mục

  • Audit
  • Azure
  • Backup & Restore
  • CEH
  • Cloud Computing
  • Cloud Other
  • Databases
  • Documents
  • Firewall
  • IaC
  • Khác
  • Linux/Unix
  • Logging
  • Mail Server
  • Microsoft
  • Monitoring
  • Networking
  • Office 365
  • Routing
  • Security
  • Security Awareness
  • Server & Storage
  • SIEM
  • Switch
  • System
  • Tools
  • Virtualization
  • Website

Tags

AD ARM Cacti CCNA Centos Cisco Citrix Controller DLP EIRGP EthernetChannel EVE-NG Exchange Fortinet FreePBX HCIBench HP IBM Installation iRedMail LAB McAfee MCSA Meeting Microsoft Teams Monitoring MSSQL P2S Prometheus SAN Splunk STP TCP/IP Ubuntu VDI Virtual Machine VLAN VMware VPN VTP Windows 10 Windows Server Wireless XPENOLOGY Zabbix

Bài Viết Gần Đây

  • Hướng dẫn cài đặt Windows Subsystem for linux version 2 (WSL2) 14/12/2021
  • Hướng dẫn Active code Azurepass 14/12/2021
  • [Tự học MCSA MCSE 2016]Lab 17 Cấu hình DFS trên Windows Server 2016 phần 1 23/08/2021
  • Zabbix monitoring network 10:Upgrade Zabbix from 4.4 to 5.0 LTS 27/06/2021
  • Zabbix monitoring network 9: Convert character Zabbix Database 07/06/2021
  • Zabbix monitoring network 8: Zabbix Grafana 16/05/2021
  • Zabbix monitoring network 7: Telegram Alert 09/05/2021

© 2021 Cộng Đồng IT Việt - ITFORVN

  • Cloud Computing
    • Azure
    • AWS
    • GCP
    • Cloud Other
  • System
    • Virtualization
    • Microsoft
    • Linux/Unix
    • Databases
    • Monitoring
    • Logging
  • Networking
    • Routing
    • Switch
    • Firewall
  • Security
    • SIEM
    • CIS
    • Audit
  • DevOps
    • CI/CD
    • Docker
    • K8s
    • IaC
  • Resource
    • Tools
    • Documents
    • Download

© 2021 Cộng Đồng IT Việt - ITFORVN

wpDiscuz
0
0
Would love your thoughts, please comment.x
()
x
| Reply
This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.