天天看点

prometheus

实验环境

master 192.168.1.15:9090

node    192.168.1.16:9100

实验软件

go1.8.3.linux-amd64.tar.gz

prometheus-2.16.0.linux-amd64.tar.gz

node_exporter-0.18.1.linux-amd64.tar.gz

软件安装

cat /etc/redhat-release && uname -a

centos linux release 7.8.2003 (core)

linux centos7-1 3.10.0-1127.el7.x86_64 

systemctl stop firewalld && systemctl disable firewalld

echo selinux=disabled > /etc/sysconfig/selinux 

hostnamectl set-hostname master    master操作

hostnamectl set-hostname node      node操作

cp -pv /etc/sysctl.conf /etc/sysctl.conf.bak

echo net.ipv4.tcp_syncookies = 1 >> /etc/sysctl.conf

echo net.ipv4.tcp_tw_reuse = 1 >> /etc/sysctl.conf

echo net.ipv4.tcp_tw_recycle = 1 >> /etc/sysctl.conf

echo net.ipv4.tcp_fin_timeout = 30 >> /etc/sysctl.conf

sysctl -p  

ntpdate ntp.aliyun.com && hwclock -w   master/node操作

cp -pv /etc/hosts /etc/hosts.bak’

echo 192.168.1.15 master >> /etc/hosts

echo 192.168.1.16 node >> /etc/hosts         master/node操作

tar zxvf go1.8.3.linux-amd64.tar.gz

mv /root/go  /usr/local/  &&  ln -s /usr/local/go/bin/go /usr/bin/

cp -pv /etc/profile /etc/profile.bak

echo "export goroot=/usr/local/go" >> /etc/profile

echo "export path=$path:$goroot/bin" >> /etc/profile

source  /etc/profile && go version

go version go1.8.3 linux/amd64            master/node操作

tar zxvf prometheus-2.16.0.linux-amd64.tar.gz    

mv prometheus-2.16.0.linux-amd64 /usr/local/prometheus   master操作

tar zxvf node_exporter-0.18.1.linux-amd64.tar.gz

mv node_exporter-0.18.1.linux-amd64 /usr/local/node      node操作

cp -pv prometheus.yml prometheus.yml.bak

global:

   scrape_interval:    15s    收集数据间隔,默认15秒。

   evaluation_interval: 15s   告警规则监测频率

#prometheus告警设置

alerting:                  alertmanager报警组件地址

   alertmanagers:

     - static_configs

     - targets:

         # - alertmanager:9093

rule_files:               报警规则文件

    # - "first_rules.yml"

#被监控端配

scrape_configs:              监控组,可定义多个实例

    - job_name: 'prometheus'

       scrape_interval: 5s

       static_configs:

- targets: ['192.168.1.15:9090','192.168.1.17:9090']  定义监控主机

       labels:                     自定义标签,通过标签对查询数据进行分组管理

          appname: 'prometheus'

  - job_name: 'node_exporter'  node监控组

     scrape_interval: 5s

     static_configs:

- targets: ['192.168.1.16:9100','192.168.1.19:9100']

      labels:

        appname: 'node_exporter'

touch  /etc/systemd/system/prometheus.service

cat /etc/systemd/system/prometheus.service 

[unit]

description=prometheus

wants=network-online.target

after=network-online.target

[service]

type=simple

execstart=/usr/local/prometheus/prometheus \

--config.file /usr/local/prometheus/prometheus.yml \

--web.console.templates=/usr/local/prometheus/consoles \

[install]

wantedby=multi-user.target

touch /etc/systemd/system/node_exporter.service

cat /etc/systemd/system/node_exporter.service

description=node exporter

after=network.target

execstart=/usr/local/node/node_exporter

execrestart=/usr/local/node/node_exporter

systemctl daemon-reload

systemctl enable prometheus &&  systemctl restart prometheus

systemctl enable  node_exporter && systemctl start  node_exporter

netstat -tuplna | grep 9090

tcp        0      0 127.0.0.1:34270         127.0.0.1:9090          established 1544/prometheus   

tcp6       0      0 :::9090                 :::*                    listen      1544/prometheus 

netstat -tuplna | grep 9100

tcp6       0      0 :::9100                 :::*                    listen      1449/node_exporter   

继续阅读