1.环境说明
| 角色 | 主机名 | IP | 系统版本 |
|---|---|---|---|
| 监控服务端 | sy-gmh-monitor-vm6.shaoyan.pro | 192.168.168.6 | CentOS Linux release 7.6.1810 (Core) |
计划prometheus,zabbix,saltstack服务端都跑在这台虚拟机。
2.下载安装prometheus
到官网链接下载对应系统版本:https://prometheus.io/download/
因为prometheus是Go写的,提供的是编译好的二进制包,所以下载解压,添加环境变量就可以用啦。
[root@sy-gmh-monitor-vm6:/data/app]# wget https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.linux-amd64.tar.gz[root@sy-gmh-monitor-vm6:/data/app]# mv prometheus-2.10.0.linux-amd64 prometheus-2.10.0[root@sy-gmh-monitor-vm6:/data/app]# ln -s /data/app/prometheus-2.10.0 /usr/local/prometheus[root@sy-gmh-monitor-vm6:/data/app]# tail -2 /etc/profile.d/myenv.sh# prometheusexport PATH=/usr/local/prometheus:$PATH[root@sy-gmh-monitor-vm6:/data/app]# source /etc/profile.d/myenv.sh
3.启动prometheus
# 使用默认配置先跑起来[root@sy-gmh-monitor-vm6:~]# prometheus --config.file "/usr/local/prometheus/prometheus.yml"# 再开一个ssh连接。查看端口,添加iptables防火墙规则[root@sy-gmh-monitor-vm6:~]# netstat -nltpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program nametcp 0 0 0.0.0.0:12080 0.0.0.0:* LISTEN 9244/sshdtcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 9446/mastertcp6 0 0 :::12080 :::* LISTEN 9244/sshdtcp6 0 0 ::1:25 :::* LISTEN 9446/mastertcp6 0 0 :::9090 :::* LISTEN 10196/prometheus[root@sy-gmh-monitor-vm6:~]# iptables -nLChain INPUT (policy ACCEPT)target prot opt source destinationACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:12080ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:12080ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:443ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHEDACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibitedChain FORWARD (policy ACCEPT)target prot opt source destinationREJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibitedChain OUTPUT (policy ACCEPT)target prot opt source destination[root@sy-gmh-monitor-vm6:~]# iptables -I INPUT -s 192.168.168.0/24 -p tcp -m tcp -j ACCEPT[root@sy-gmh-monitor-vm6:~]# service iptables saveiptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ][root@sy-gmh-monitor-vm6:~]#

