失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Zabbix监控部署(内网监控外网服务器)

Zabbix监控部署(内网监控外网服务器)

时间:2019-06-27 15:38:42

相关推荐

Zabbix监控部署(内网监控外网服务器)

最近公司新买了一批OVH服务器,这些服务器的硬盘、负载、和实时带宽需要监控。首先想到的就是用Zabbix监控。因为在公司内网中,之前部署过Zabbix监控。只需要在这些OVH服务器上安装zabbix的客户端即可。以下为实现步骤:

1、配置免密登录

1.1、zabbix服务端生成密钥对

[root@localhost ~]# ssh-keygen -f '~/.ssh/id_rsa' -N ''Generating public/private rsa key pair.Your identification has been saved in /root/.ssh/id_rsa.Your public key has been saved in /root/.ssh/id_rsa.pub.The key fingerprint is:SHA256:4vyK0ZZVYULr0DpJyiYOycisvFZzMehugAlKpFvcXgM root@localhost.localdomainThe key's randomart image is:+---[RSA 3072]----+| .o o|| . E . + .||o. ...o o .||Booo.=o= . ||OBo.+.B.S ||B+ *.= = ||..= + *|| ..o + . ||... . ... |+----[SHA256]-----+

1.2、向zabbix客户端传递公钥

可以把需要监控的服务器IP放到一个列表中

[root@localhost ~]# vi /server/scripts/node.sh#!/bin/bashssdzd(){expect << EOFset timeout 5spawn ssh-copy-id centos@$IPexpect {"yes/no" {send "yes\n";exp_continue }"password" {send "密码\n" }}expect eofEOF}for IP in $(cat /root/ip_list)dossdzddone

2、安装配置ansible批量操作被监控主机

[root@localhost ~]# yum install ansible -y[root@localhost ~]# sed -i 's/^#inventory/inventory/' /etc/ansible/ansible.cfg[root@localhost ~]# sed -i 's/^#host_key_checking/host_key_checking/' /etc/ansible/ansible.cfg

把需要监控的服务器IP写入/etc/ansible/hosts文件

[root@localhost ~]# vi /etc/ansible/hosts.....[node]192.168.1.30192.168.1.31192.168.1.32192.168.1.33........

测试

[root@localhost ~]# ansible ndoe -u centos -m ping192.168.1.31 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"....

3、编写playbook配置zabbix客户端

[root@localhost ~]# vi /server/scripts/zabbix_agent_install.yml---- hosts: chia_centosremote_user: centosgather_facts: Nobecome: yesbecome_method: sudobecome_user: roottasks:- name: "stop firewalld"service:name: firewalldstate: stopped - name: "copy zabbix.repo"copy: src=/etc/yum.repos.d/zabbix.repodest=/etc/yum.repos.d/notify: update repolist- name: "install zabbix-agent"yum:name: "zabbix-agent"state: installed- name: "copy zabbix_agentd.conf"copy: src=/root/zabbix_agentd.confdest=/etc/zabbix/notify: restart servicehandlers:- name: update repolistshell: "yum clean all;yum repolist"- name: restart serviceservice:name: zabbix-agentstate: startedenabled: yes

检查playbook是否存在语法错误

[root@localhost ~]# ansible-playbook --syntax-check /server/scripts/zabbix_agent_install.ymlplaybook: zabbix_agent_install.yml

4、执行playbook

[root@localhost ~]# ansible-playbook /server/scripts/zabbix_agent_install.yml

zabbix客户端安装完成后,在server端创建自动发现规则,或者手动添加被监控主机

备注

由于公司出口IP为动态IP,而zabbix客户端的配置文件中需要写入server端的IP,所以需要定期检测公司的出口IP,如果IP变化后,需要修改客户端的配置文件。以下是实现方法:

通过定时脚本实时检测出口IP,如果有变化就写入本地的配置文件,然后通过上面写好的playbook,将本地的配置文件拷贝到远程被监控主机。

[root@localhost ~]# vi /server/scripts/check_wan_ip.sh#!/bin/bashWAN_IP=`curl |awk '/http/{print}'|awk -F "/" '{print $4}'`OLD_IP=`cat /server/scripts/wan_ip`if [ ${WAN_IP} != ${OLD_IP} ];thenecho $WAN_IP > /server/scripts/wan_ipansible-playbook /server/scripts/zabbix_agent_install.yml > /dev/null 2>&1fi

如果觉得《Zabbix监控部署(内网监控外网服务器)》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。