掌柜
prometheus安装和配置
09/27
本文最后更新于2023年07月07日,已超过461天没有更新。如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!
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
# prometheus
export 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 -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:12080 0.0.0.0:* LISTEN 9244/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 9446/master
tcp6 0 0 :::12080 :::* LISTEN 9244/sshd
tcp6 0 0 ::1:25 :::* LISTEN 9446/master
tcp6 0 0 :::9090 :::* LISTEN 10196/prometheus
[root@sy-gmh-monitor-vm6:~]# iptables -nL
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:12080
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:12080
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:443
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain 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 save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[root@sy-gmh-monitor-vm6:~]#
4.访问prometheus
访问:http://192.168.168.6:9090