20190807184730.jpg

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/
因为prometheusGo写的,提供的是编译好的二进制包,所以下载解压,添加环境变量就可以用啦。

  1. [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
  2. [root@sy-gmh-monitor-vm6:/data/app]# mv prometheus-2.10.0.linux-amd64 prometheus-2.10.0
  3. [root@sy-gmh-monitor-vm6:/data/app]# ln -s /data/app/prometheus-2.10.0 /usr/local/prometheus
  4. [root@sy-gmh-monitor-vm6:/data/app]# tail -2 /etc/profile.d/myenv.sh
  5. # prometheus
  6. export PATH=/usr/local/prometheus:$PATH
  7. [root@sy-gmh-monitor-vm6:/data/app]# source /etc/profile.d/myenv.sh

3.启动prometheus

  1. # 使用默认配置先跑起来
  2. [root@sy-gmh-monitor-vm6:~]# prometheus --config.file "/usr/local/prometheus/prometheus.yml"
  3. # 再开一个ssh连接。查看端口,添加iptables防火墙规则
  4. [root@sy-gmh-monitor-vm6:~]# netstat -nltp
  5. Active Internet connections (only servers)
  6. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  7. tcp 0 0 0.0.0.0:12080 0.0.0.0:* LISTEN 9244/sshd
  8. tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 9446/master
  9. tcp6 0 0 :::12080 :::* LISTEN 9244/sshd
  10. tcp6 0 0 ::1:25 :::* LISTEN 9446/master
  11. tcp6 0 0 :::9090 :::* LISTEN 10196/prometheus
  12. [root@sy-gmh-monitor-vm6:~]# iptables -nL
  13. Chain INPUT (policy ACCEPT)
  14. target prot opt source destination
  15. ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:12080
  16. ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:12080
  17. ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
  18. ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:443
  19. ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
  20. ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
  21. ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
  22. ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
  23. REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
  24. Chain FORWARD (policy ACCEPT)
  25. target prot opt source destination
  26. REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
  27. Chain OUTPUT (policy ACCEPT)
  28. target prot opt source destination
  29. [root@sy-gmh-monitor-vm6:~]# iptables -I INPUT -s 192.168.168.0/24 -p tcp -m tcp -j ACCEPT
  30. [root@sy-gmh-monitor-vm6:~]# service iptables save
  31. iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
  32. [root@sy-gmh-monitor-vm6:~]#

4.访问prometheus

http://192.168.168.6:9090
57f.png