批量添加zabbix监控
1.使用ansible配置zabbix客户端

①修改服务器的IP(域名),为了方便使用ansible来批量操作

等同于如下sed语句
sed -i 's#Server=1.1.1.11#Server=2.2.2.2#g' /usr/local/zabbix_agents_3.2.0/conf/zabbix_agentd.conf
sed -i 's#ServerActive=1.1.1.11#ServerActive=2.2.2.2#g' /usr/local/zabbix_agents_3.2.0/conf/zabbix_agentd.conf

先使用一台服务器测试,通过以后再批量操作即可

②使用ansible将zabbix_agentd.conf的服务器IP有1.1.1.11更换为2.2.2.2
ansible web01 -m replace -a 'path=/usr/local/zabbix_agents_3.2.0/conf/zabbix_agentd.conf regexp="1.1.1.11" replace="2.2.2.2"'

③重启客户端生效
ansible web01 -m shell -a "executable=/bin/bash /etc/init.d/zabbix_agentd restart"

# 全部执行

ansible all -m replace -a 'path=/usr/local/zabbix_agents_3.2.0/conf/zabbix_agentd.conf regexp="1.1.1.11" replace="2.2.2.2"'
ansible all -m shell -a "executable=/bin/bash /etc/init.d/zabbix_agentd restart"

因为是内网所以不需要开启防火墙放行这些IP

其他修改操作类似,就不继续举例说明了

2.服务端操作
①整理agent端需要添加的模板、主机组等信息到excel中


②不存在的模板需要添加到服务端templates中

③执行zabbix_api批量操作excel添加监控


# 修改/etc/ansible/hosts加入如下主机(可以先通过excel整理后直接拷贝)

frontend_web01 ansible_host
=172.30.0.241 ansible_port=2018 ansible_user=root ansible_ssh_pass=pass frontend_web02 ansible_host=172.30.0.240 ansible_port=2018 ansible_user=root ansible_ssh_pass=pass backend_web1 ansible_host=172.30.0.245 ansible_port=2018 ansible_user=root ansible_ssh_pass=pass backend_web2 ansible_host=172.30.0.243 ansible_port=2018 ansible_user=root ansible_ssh_pass=pass backend_web3 ansible_host=172.30.0.242 ansible_port=2018 ansible_user=root ansible_ssh_pass=pass backend_web4 ansible_host=172.30.0.244 ansible_port=2018 ansible_user=root ansible_ssh_pass=pass # 测试ping命令报错 [root@zabbix:~]# ansible eus_redis01 -m ping eus_redis01 | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: command-line: line 0: Bad configuration option: stricthostkeychecking\\357\\274\\235no\r\n", "unreachable": true } 解决办法: 修改ansible配置文件,关闭首次ssh检查 # vim /etc/ansible/ansible.cfg # uncomment this to disable SSH key host checking host_key_checking = False