自动化工具ansible官网地址:Ansible is Simple IT Automationhttps://www.ansible.com/
关于自动化工具ansible这里仅写关于批量部署zabbix-agent部分,其它玩法请继续关注见后文哈
模拟内网环境通过自动化工具ansible批量部署zabbix-agent端;这里使用离线方式部署ansible服务,有外网环境直接yum安装
#yum -y install epel-release && yum -y install ansible && ansible --version
一、环境及准备(接第一节)
#共5台主机(其中zabbix-server和zabbix-agent01已经在上节初步部署,这里体现用ansbile主机部署zabbix-agent02、zabbix-agent03,并在web界面手动添加到监控中)
192.168.200.82 zabbix-server
192.168.200.27 ansible
192.168.200.127 zabbix-agent01
192.168.200.128 zabbix-agent02
192.168.200.129 zabbix-agent03
#系统类型
[root@zabbix-agent02 ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
#模拟内网环境(zabbix-agent03及ansible主机同理)
[root@zabbix-agent02 ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp2s0 #设静态ip,不设网关及NS
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
NAME=enp2s0
DEVICE=enp2s0
ONBOOT=yes
IPADDR=192.168.200.128
NETMASK=255.255.255.0
[root@zabbix-agent02 ~]# systemctl restart network #重启生效
[root@zabbix-agent02 ~]# cd /etc/yum.repos.d/
[root@zabbix-agent02 yum.repos.d]# find . -type f | sed -r 's#(.*).repo#mv \0 \1.repo.bak#' | bash #批量注释yum源
[root@zabbix-agent02 yum.repos.d]# yum clean all #清理yum缓存
[root@zabbix-agent02 ~]# cat /etc/hosts #改主机名后需要在/etc/hosts文件映射
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 zabbix-agent02
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 zabbix-agent02
192.168.200.128 zabbix-agent02
[root@zabbix-agent02 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 enp2s0
192.168.200.0 0.0.0.0 255.255.255.0 U 0 0 0 enp2s0
二、离线安装ansible
1)ansible离线安装及配置 (ansible的server端和client端的连接走的是ssh的数据传输通道)
[root@ansible ansible]# python --version #python环境
Python 2.7.5
#新建目录,把安装包及脚本拷贝进来哈
[root@ansible ~]# test -d /app/an