使用自动化部署工具Ansible批量部署zabbix_agent.

1. 安装Ansible

yum –y install ansible

内网情况下,现在ansible及其依赖的rpm包,添加到yum源进行安装。

2. 主机配置文件

在/etc/ansible中添加主机,主机配置文件为hosts,也可以在ansible.cfg中修改配置

inventory={主机配置文件路径}

具体hosts格式

[zabbix-agent]  #分组名称,最好是一个文件一个分组。

IP ansible_ssh_user=’{账户名}’ ansible_ssh_pass=’{密码}’ hostname={主机名字,可以自定义}

3. 编写安装脚本

脚本文件结构如下:

.

├── ansible.cfg

├── hosts

└── roles

├── install_zabbix_agent

│   ├── file

│   │   ├── zabbix-agent-4.2.4-1.el7.x86_64.rpm

│   │   └── zabbix_agentd.conf

│   ├── handler

│   │   └── main.yml

│   └── tasks

│       ├── install.yml

│       ├── main.yml

│       └── setport.yml

└── install_zabbix_agent.yml

具体代码:

install_zabbix_agent.yml

- hosts: zabbix-agent
remote_user: root
sudo: yes
sudo_user: root
gather_facts: true
roles:
- install_zabbix_agent

file : zabbix-agent-4.2.4-1.el7.x86_64.rpm  zabbix-agent安装包

zabbix_agentd.conf    统一修改好的zabbix-agent配置文件

handler main.yml

- name: restart zabbix-agent
service: name=zabbix_agentd state=restarted

tasks main.yml

- import_tasks: install.yml
- import_tasks: setport.yml

tasks install.yml

- block:
- name: "copy zabbix_agent to clients"
cpoy:
src=zabbix-agent-4.2.4-1.el7.x86_64.rpm
dest=/tmp
- name: "yum install zabbix_agent"
yum:
name: /tmp/zabbix-agent-4.2.4-1.el7.x86_64.rpm
state: present
- name: "copy zabbix_agentd.conf"
copy:
src=zabbix_agentd.conf
dest=/etc/zabbix/zabbix_agentd.conf
- name: disabled selinux
shell: /usr/sbin/setenforce 0 && sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
- name: "start zabbix, enable zabbix"
service:
name=zabbix-agent
state=started
enabled=yes
notify:
- restart zabbix-agent

tasks setport.yml

- block:
- name: mkdir log file
shell: mkdir -p /var/log/zabbix
- name: chmod for log
shell: chmod -R 755 /var/log/zabbix
- name: chown for log
shell: chown -R zabbix. /var/log/zabbix
- name: chmod for zabbix
shell: chmod -R 755 /etc/zabbix
- name: chown for zabbix
shell: chown -R zabbix. /etc/zabbix
- name: change log filepath
shell: sed -i 's/LogFile=\/var\/log\/zabbix\/zabbix_agent.log/LogFile=\/var\/log\/zabbix\/{{hostname}}.log/g' /etc/zabbix/zabbix_agentd.conf
- name: change server ip
shell: sed -i 's/Server=127.0.0.1/Server=10.10.40.70/g' /etc/zabbix/zabbix_agentd.conf
- name: change server active ip
shell: sed -i 's/ServerActive=127.0.0.1/ServerActive=10.10.40.70/g' /etc/zabbix/zabbix_agentd.conf
- name: change hostname
shell: sed -i 's/Hostname=Zabbix Server/Hostname={{hostname}}/g' /etc/zabbix/zabbix_agentd.conf
notify:
- restart zabbix-agent

最新文章

  1. Jmeter插件监控服务器性能
  2. Eclipse Che:下一代基于 Web 的 IDE
  3. [Android Memory] android 警告:Exported activity does not require permission
  4. Python输入和输出
  5. SQl 字段中出现某一个词语的次数
  6. bzoj 1419 Red is good(期望DP)
  7. Ubuntu 12.04设置打开远程桌面登录1
  8. delphi关于文件操作集锦
  9. 计算指定文件的MD5值
  10. Oracle导入大数据量(百万以上)dmp文件,报错ora-12592 :包错误
  11. 记华硕小主机装xp并给nokia e7-00 刷机
  12. xshell 使用命令上传、下载文件
  13. Traceback (most recent call last): File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\Packages\ptvsd\_vendored\pydevd\_pydevd_bundle\pyd
  14. namecheap 添加二级域名
  15. git help 机器翻译
  16. Backpack VI
  17. python-selenium,关于页面滑动的操作
  18. activiti 5.13流程图连线名称不显示bug修复
  19. 获取图片src
  20. oauth2.0的授权流程详解

热门文章

  1. 在搞OSS对象存储中发现了自身的一些不足
  2. Java知识系统回顾整理01基础03变量03字面值
  3. 【随笔---转载】xip.io
  4. 达梦产品技术支持培训-day7-DM8数据库备份与还原-原理
  5. Java死锁编码及定位分析的demo
  6. SpringBoot+单机redis
  7. CSS字体属性与文本属性
  8. 多测师讲解自动化测试 _RF自定义关键字_高级讲师肖sir
  9. 多测师讲解自动化 _rf 变量_高级讲师肖sir
  10. java 环境变量配置(win10)