目录
一、Prometheus部署
1、前期准备,主机分配、防火墙、基础环境等
地址 |
安装包 |
|
192.168.110.130 |
prometheus-2.27.1.linux-amd64.tar.gz |
|
server1 |
192.168.110.131 |
node_exporter-1.1.2.linux-amd64.tar.gz |
server2 |
192.168.110.132 |
|
server3 |
192.168.110.133 |
hostnamectl set-hostname prometheus #其他主机分别设置server1.2.3
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
vim /etc/reslove.conf
nameserver 114.114.114.114
ntpdate ntp1.aliyun.com #时间同步;时间同步必须要做,不然会报错
2、准备安装包
#同步源的方式下载
cat > /etc/yum.repos.d/prometheus.repo <<EOF
[prometheus]
name=prometheus
baseurl=https://packagecloud.io/prometheus-rpm/release/el/basearch
repo gpgcheck=1
enabled-1
gpgkey=https://packagecloud.io/prometheus-rpm/release/gpgkeyhttps://raw.githubusercontent.com/lest/prometheus-rpm/master/RPM-GPG-KEY-prometheus-rpmgpgcheck=1 metadata_expire=300
EOF
3、prometheus主机服务部署
#上传包,并解压
tar -zxvf prometheus-2.27.1.linux-amd64.tar.gz -C /usr/local
#启动服务
[root@prometheus ~]# cd /usr/local/prometheus-2.27.1.linux-amd64/
[root@prometheus prometheus-2.27.1.linux-amd64]# ./prometheus
#重新开会话终端,查看9090端口,检测服务是否启动
[root@prometheus prometheus-2.27.1.linux-amd64]# ss -natp | grep 9090
LISTEN 0 128 :::9090 :::* users:(("prometheus",pid=85118,fd=7))
[root@prometheus prometheus-2.27.1.linux-amd64]#
#浏览器访问http://192.168.110.130:9090/
#访问http://192.168.110.130:9090/metrics:查看prometheus自带的内键指标。
#查看采集数据。Prometheus会进行周期性的采集数据(完整的),多次周期性(在一个时间区间内)
采集的数据集合,形成时间序列数据。
4、部署监控其他节点
server1、server2、server3,prometheus想要监控其他节点,则需要借助node_exporter组件,下
载地:https://prometheus.io/docs/concepts/data_model/,腾讯云盘prometheus安装包。
[root@server1 ~]# rz -E #上传安装包
rz waiting to receive.
[root@server1 ~]# ls
anaconda-ks.cfg original-ks.cfg 模板 图片 下载 桌面
node_exporter-1.1.2.linux-amd64.tar.gz 公共 视频 文档 音乐
[root@server1 ~]# tar -zxvf node_exporter-1.1.2.linux-amd64.tar.gz -C /opt/
node_exporter-1.1.2.linux-amd64/
node_exporter-1.1.2.linux-amd64/LICENSE
node_exporter-1.1.2.linux-amd64/NOTICE
node_exporter-1.1.2.linux-amd64/node_exporter
[root@server1 ~]# cd /opt/node_exporter-1.1.2.linux-amd64/
[root@server1 node_exporter-1.1.2.linux-amd64]# ls
LICENSE node_exporter NOTICE
[root@server1 node_exporter-1.1.2.linux-amd64]# cp node_exporter /usr/local/bin/
[root@server1 node_exporter-1.1.2.linux-amd64]# ./node_exporter #启动node_exporter,在/usr/local/bin/目录下
###添加系统管理,使用systemctl管理工具管理此服务
服务管理方式utilfile(文件读取工具)
[Unit]
Description=node_exporter
Documentation=https:/prometheus.io/
After=network.targets
[serveice]
Type=simple
User=prometheus
ExecStart=/usr/local/bin/node_exporter \
--collector.ntp \
--collector.mountstats \
--collector.systemd \
--collertor.tcpstat
ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20s
Restart=always
[Install]
WantedBy=multi-user.target
#启动服务这边的会话窗口查看动态变化
#在开一个会话终端,查看服务是否启动
[root@server1 ~]# netstat -antp | grep 9100
tcp6 0 0 :::9100 :::* LISTEN 86943/./node_export
[root@server1 ~]#
#我们访问http://192.168.110.130:9090/targets,访问http://192.168.110.130:9090/ 点击—>status
—>targets
5、修改配置,加入其他节点监控
需要在192.168.110.130 prometheus服务端停止prometheus,并修改配置文件添加静态targets才
能使得server节点可以被发现。
[root@prometheus ~]# cd /usr/local/prometheus/
[root@prometheus prometheus]# vim prometheus.yml
…… #在文件末尾添加target静态配置如下
- job_name: 'nodes'
static_configs:
- targets:
- 192.168.110.130:9100
- 192.168.110.131:9100
- 192.168.110.132:9100
- 192.168.110.133:9100
[root@prometheus prometheus]# ./prometheus