部署prometheus监控服务器
- 安装监控服务器
- 修改配置文件
- 编写service文件,管理服务
- 查看监控数据
所有主机系统均为CentOS7,提前配置IP、主机名、系统YUM源
安装监控软件(192.168.4.10主机操作)
安装软件
- [root@prometheus ~]# tar -xf prometheus_soft.tar.gz
- [root@prometheus ~]# cd prometheus_soft
- [root@prometheus prometheus_soft]# tar -xf prometheus-2.17.2.linux-386.tar.gz
- [root@prometheus prometheus_soft]# ls
- [root@prometheus prometheus_soft]# mv prometheus-2.17.2.linux-386 /usr/local/prometheus
- [root@prometheus prometheus_soft]# ls /usr/local/prometheus/
修改prometheus配置文件
- [root@prometheus ~]# vim /usr/local/prometheus/prometheus.yml
- static_configs:
- - targets: ['192.168.4.10:9090'] #修改最后一行,将IP地址改为本机IP
- [root@prometheus ~]# /usr/local/prometheus/promtool check config \
- /usr/local/prometheus/prometheus.yml #检查配置配置文件是否有语法错误
编写服务service文件,使用systemd管理服务
- [root@prometheus ~]# vim /usr/lib/systemd/system/prometheus.service
- [Unit]
- Description=Prometheus Monitoring System
- After=network.target
- [Service]
- ExecStart=/usr/local/prometheus/prometheus \
- --config.file=/usr/local/prometheus/prometheus.yml \
- --storage.tsdb.path=/usr/local/prometheus/data/
- [Install]
- WantedBy=multi-user.target
- #--config.file和--storage.tsdb.path都是prometheus这个程序的参数
- #可以通过prometheus -h查看这个程序支持哪些参数
- #--config.file参数后面指定该程序使用哪个配置文件启动服务
- #--storage.tsdb.path参数后面指定该程序将数据存储在哪个目录下
- [root@prometheus ~]# systemctl enable prometheus.service --now #设置服务器开机自启动服务,并立刻启动该服务
设置防火墙、SELinux
- [root@prometheus ~]#firewall-cmd --set-default-zone=trusted
- [root@prometheus ~]#setenforce 0
- [root@prometheus ~]#sed -i '/SELINUX/s/enforcing/permissive/' /etc/selinux/con