實驗環境
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