设为首页 收藏本站
查看: 831|回复: 0

[经验分享] ansible自动部署 zabbix-agent 的模块

[复制链接]

尚未签到

发表于 2018-7-29 11:25:59 | 显示全部楼层 |阅读模式
  ansible自动部署 zabbix-agent 模块  的准备阶段
  ansible所在的服务端可以免密钥登录所被部署的机器称为客户端。
  免密钥的做法
  服务端 ssh-keygen  一路回车生成密钥对
  ssh-copy-id 指定IP 将公钥发给指定的ip 即可
  ssh-copy-id 192.168.1.18
  下面红色是代表文件或目录  黑色字体代表是内容
  使用了 roles 方法  整体的目录结构是
  /etc/ansible/zabbix-agent.yml
  
  [root@localhost ansible]# pwd
  /etc/ansible
  /etc/ansibl/hosts
  [root@localhost ansible]# cat hosts
  192.168.1.145  #centso 系统
  192.168.1.147  #   centos 系统   加入 ansible 的客户端ip  本次示例中是这几个 ip
  192.168.1.148  #ubuntu 系统
  [root@localhost ansible]# cat zabbix-agent.yml
  ---
  - hosts: all
  roles:
  - zabbix-agent
  
  /etc/ansible/roles
  
  [root@localhost ansible]#  ls
  zabbix-agent
  /etc/ansible/zabbix-agent
  
  [root@localhost zabbix-agent]# ls
  files  handlers  tasks  templates
  
  /etc/ansible/zabbix-agent/files  
  
  [root@fzt146 zabbix-agent]# ls files/
  zabbix
  
  /etc/ansible/zabbix-agent/handlers
  
  
  [root@fzt146 zabbix-agent]# ls handlers/
  main.yml
  
  /etc/ansible/zabbix-agent/tasks
  
  [root@fzt146 zabbix-agent]# ls tasks/
  files.yml  main.yml  package.yml  service.yml
  
  /etc/ansible/zabbix-agnet/templates
  
  [root@fzt146 zabbix-agent]# ls templates/
  zabbix_agentd.conf
  /etc/ansible/zabbix-agent/files/zabbix/conf.d
  
  
  [root@fzt146 zabbix-agent]# ls files/zabbix/conf.d/  #zabbix-agent的配置文件 键值
  impression.conf  imsecret.conf  mystar.conf  resonance.conf  tagme.conf  userReg.conf
  /etc/ansible/zabbix-agent/files/zabbix/scripts 要复制去客户端的文件
  [root@fzt146 zabbix-agent]# ls files/zabbix/scripts/  下边是zabbix 可执行的脚本用来监控
  /etc/ansible/zabbix-agent/handlers/main.yml  这个是开启zabbix-agent的
  
  [root@fzt146 zabbix-agent]# cat handlers/main.yml
  ---
  - name: start zabbix_agentd
  service: name=zabbix-agentd state=started
  /etc/ansible/zabbix-agent/tasks/files.yml 将 /etc/ansible/zabbix-agent/files/* 复制到客户端的配置
  [root@fzt146 zabbix-agent]# cat tasks/files.yml
  ---
  - name: copy centos template conf file
  template: src=zabbix_agentd.conf  dest=/etc/
  when: ansible_os_family == "RedHat" #判断系统
  - name: copy ubuntu template conf file
  template: src=zabbix_agentd.conf  dest=/etc/zabbix/
  when: ansible_os_family == "Debian"
  - name: crete conf.d and scripts
  file: path=` item ` state=directory owner=root group=root mode=0755
  with_items:
  - /etc/zabbix/scripts
  - /etc/zabbix/conf.d
  - /etc/zabbix/scripts1
  - name: copy the scripts/file
  copy: src=zabbix/scripts/ dest=/etc/zabbix/scripts/ mode=0755
  - name: copy the scripts1/file
  copy: src=zabbix/scripts1/ dest=/etc/zabbix/scripts1/ mode=0755
  - name: copy the conf.d/file
  copy: src=zabbix/conf.d/ dest=/etc/zabbix/conf.d/
  
  /etc/ansible/zabbix-agent/tasks/main.yml 主的配置 在同级目录下会先执行这个main
  
  [root@localhost zabbix-agent]# cat tasks/main.yml
  ---
  - include: 'package.yml'
  - include: 'files.yml'
  - include: 'service.yml'
  
  /etc/ansible/zabbix-agent/tasks/package.yml 安装zabbix-agent的配置
  
  [root@localhost zabbix-agent]# cat tasks/package.yml
  ---
  - name: useraddd the zabbix
  user: name=zabbix
  - name: install epel-release
  yum: name=epel-release.noarch state=latest
  when: ansible_os_family == "RedHat"
  - name: install epel-release and  zabbix_agent_package
  yum: name=` item ` state=present
  with_items:
  - zabbix22-agent-2.2.18-1.el6.x86_64
  - zabbix22-2.2.18-1.el6.x86_64
  when: ansible_os_family == "RedHat"
  - name: apt-get install to ubuntu
  apt: name=` item ` state=present
  with_items:
  - zabbix-agent
  when: ansible_os_family == "Debian"
  
  /etc/ansible/zabbix-agent/tasks/service.yml   开启脚本 万无一失  2重开启
  
  [root@localhost zabbix-agent]# cat tasks/service.yml
  ---
  - name: start zabbix-agentd
  service: name=zabbix-agentd state=started
  when: ansible_os_family == "RedHat"
  - name: start ubuntu zabbix-agent
  service: name=zabbix-agent state=started
  when: ansible_os_family == "Debian"
  /etc/ansible/zabbix-agent/templates/zabbix_agentd.conf  配置文件的模板放在这里
  
  
  [root@localhost zabbix-agent]# cat templates/zabbix_agentd.conf
  PidFile=/var/run/zabbix/zabbix_agentd.pid
  LogFile=/var/log/zabbix/zabbix_agentd.log
  LogFileSize=100
  Server=192.168.1.100  #zabbix 服务端所在的 ip
  ServerActive=192.168.1.100  # zabbix-agent 主动模式 配置
  Hostname=` ansible_hostname `  #这个是系统变量
  Include=/etc/zabbix/conf.d/
  UnsafeUserParameters=1
  # UserParameter  自定义的 监控项
  具体执行
  [root@localhost ansible]# pwd
  /etc/ansible
  [root@localhost ansible]# ansible-playbook zabbix-agent.yml  
  [root@localhost ansible]# ansible-playbook zabbix-agent.yml   -vvvv
  加  -vvv  可以看到更详细的过程  其实是 没必要的  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-542965-1-1.html 上篇帖子: ansible sudo 用法 下篇帖子: centos7 使用ansible批量挂载硬盘
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表