Prometheus容器化部署,配合Grafan画图工具监控节点信息

Prometheus容器化部署,配合Grafan画图工具监控节点信息

Prometheus 容器化部署,配合Grafan画图工具监控节点

部署 Prometheus

准备工作

//关闭防火墙和selinux
[root@prometheus ~]# systemctl disable --now firewalld
[root@prometheus ~]# sed -i s/SELINUX=enforing/SELINUX=disabled/g /etc/selinux/config
[root@prometheus ~]# setenforce 0

//配置docker源与安装docker
[root@prometheus ~]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
[root@prometheus ~]# yum -y install docker-ce
[root@prometheus ~]# systemctl enable --now docker

//配置阿里云镜像加速
[root@prometheus ~]# cat > /etc/docker/daemon.json << EOF
 {
   "registry-mirrors": ["https://wjscumc2.mirror.aliyuncs.com"]
 }
 EOF
[root@prometheus ~]# systemctl restart docker

prometueus

//创建共享存储卷位置,提前准备好promrtheus的配置文件,放入此目录下
[root@prometheus ~]# mkdir -p /prometheus/config
[root@prometheus config]# ls 
prometheus.yml
[root@prometheus config]# cat prometheus.yml 
# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]

//运行prometheus容器
[root@prometheus ~]# docker run --name prometheus -d --restart always  -p 9090:9090 -v /prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml:ro   prom/prometheus:latest
[root@prometheus ~]# docker ps 
CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS          PORTS                                       NAMES
a1ebf9e29cb8   prom/prometheus:latest   "/bin/prometheus --c…"   12 seconds ago   Up 10 seconds   0.0.0.0:9090->9090/tcp, :::9090->9090/tcp   prometheus

[root@prometheus ~]# ss -antl 
State  Recv-Q Send-Q Local Address:Port Peer Address:PortProcess 
LISTEN 0      128          0.0.0.0:22        0.0.0.0:*           
LISTEN 0      128          0.0.0.0:9090      0.0.0.0:*           
LISTEN 0      128             [::]:22           [::]:*           
LISTEN 0      128             [::]:9090         [::]:* 

网页访问prometueus
访问方式:主机IP:9090 主机名:9090/targets

部署 node_exporter

节点主机安装node_exporter

//关闭节点主机防火墙和selinux
[root@node1 ~]# systemctl disable --now firewalld
[root@node1 ~]# sed -i s/SELINUX=enforing/SELINUX=disabled/g /etc/selinux/config
[root@node1 ~]# setenforce 0

//下载安装包
[root@node1 src]# wget https://github.com/prometheus/node_exporter/releases/download/v1.3.0/node_exporter-1.3.0.linux-amd64.tar.gz
[root@node1 src]# ls 
debug  kernels  node_exporter-1.3.0.linux-amd64.tar.gz

//解压
[root@node1 src]# tar -xf node_exporter-1.3.0.linux-amd64.tar.gz  -C /usr/local/
[root@node1 src]# mv /usr/local/node_exporter-1.3.0.linux-amd64/ /usr/local/node_exporter
[root@node1 src]# ls ../local/
bin  games    lib    libexec        sbin   src
etc  include  lib64  node_exporter  share

//service启动文件
[root@node1 ~]# cat > /usr/lib/systemd/system/node_exporter.service   <<EOF
[unit]
Description=The node_exporter Server
After=network.target

[Service]
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
RestartSec=15s
SyslogIdentifier=node_exporter

[Install]
WantedBy=multi-user.target
EOF

[root@node1 ~]# cat /usr/lib/systemd/system/node_exporter.service 
[unit]
Description=The node_exporter Server
After=network.target

[Service]
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
RestartSec=15s
SyslogIdentifier=node_exporter

[Install]
WantedBy=multi-user.target

//启动
[root@node1 ~]# systemctl enable --now node_exporter
Created symlink /etc/systemd/system/multi-user.target.wants/node_exporter.service → /usr/lib/systemd/system/node_exporter.service.
[root@node1 ~]# ss -antl 
State  Recv-Q Send-Q Local Address:Port   Peer Address:Port 
LISTEN 0      128        127.0.0.1:36451       0.0.0.0:*    
LISTEN 0      128        127.0.0.1:10248       0.0.0.0:*    
LISTEN 0      128          0.0.0.0:22          0.0.0.0:*    
LISTEN 0      128                *:10250             *:*    
LISTEN 0      128                *:9100              *:*    
LISTEN 0      128             [::]:22             [::]:* 

添加节点主机到prometheus

//添加节点主机
[root@prometheus config]# pwd
/prometheus/config
[root@prometheus config]# vi prometheus.yml 

# my global config
global:
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]

  - job_name: "linux servers"    #节点主机任务名称
    static_configs:
      - targets: ["192.168.218.130:9100"]   #节点主机IP

//重启prometheus容器
[root@prometheus config]# docker restart prometheus
prometheus
[root@prometheus config]# docker ps 
CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS         PORTS                                       NAMES
a1ebf9e29cb8   prom/prometheus:latest   "/bin/prometheus --c…"   24 minutes ago   Up 2 seconds   0.0.0.0:9090->9090/tcp, :::9090->9090/tcp   prometheus

网页访问
访问方式: 主机名IP:9090/targets
Prometheus容器化部署,配合Grafan画图工具监控节点信息

查看监控数据
主机名IP:9090/metrics
Prometheus容器化部署,配合Grafan画图工具监控节点信息

部署grafana

//使用grafana镜像运行容器
[root@prometheus ~]# docker run -d --name grafana -p 3000:3000 --restart always grafana/grafana

[root@prometheus ~]# docker ps 
CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS          PORTS                                       NAMES
133606fe4b00   grafana/grafana          "/run.sh"                20 seconds ago   Up 19 seconds   0.0.0.0:3000->3000/tcp, :::3000->3000/tcp   grafana
a1ebf9e29cb8   prom/prometheus:latest   "/bin/prometheus --c…"   31 minutes ago   Up 6 minutes    0.0.0.0:9090->9090/tcp, :::9090->9090/tcp   prometheus

[root@prometheus ~]# ss -antl 
State  Recv-Q Send-Q Local Address:Port Peer Address:PortProcess 
LISTEN 0      128          0.0.0.0:22        0.0.0.0:*           
LISTEN 0      128          0.0.0.0:3000      0.0.0.0:*           
LISTEN 0      128          0.0.0.0:9090      0.0.0.0:*           
LISTEN 0      128             [::]:22           [::]:*           
LISTEN 0      128             [::]:3000         [::]:*           
LISTEN 0      128             [::]:9090         [::]:* 

网页访问grafana
访问方式:主机IP:3000 默认账号密码均为admin
第一次登陆需要修改密码
Prometheus容器化部署,配合Grafan画图工具监控节点信息
Prometheus容器化部署,配合Grafan画图工具监控节点信息
Prometheus容器化部署,配合Grafan画图工具监控节点信息
Prometheus容器化部署,配合Grafan画图工具监控节点信息
Prometheus容器化部署,配合Grafan画图工具监控节点信息

上一篇:Qt获取屏幕DPI


下一篇:内网渗透(Frp代理)