♥ zabbix 6.0 客户端 使用ansible部署

环境配置

主机ip
ansible192.168.58.150
agent 客户端192.168.58.45

修改主机映射

[root@ansible ansible]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.58.45 zabbix-agent01
192.168.58.46 zabbix-agent02
192.168.58.150 ansible

密钥的发放

[root@ansible ~]# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
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:8yuso7yB8426UAQE4AXnrDlq4vTpmnI7nI432uf0ab0 root@ansible
The key's randomart image is:
+---[RSA 3072]----+
|Bo.o             |
|..=              |
| ..o             |
| .o              |
| +.     S        |
|....     o       |
|++o.o  o  .      |
|*+X=o=o.+  .     |
|+OO%B+=oEo.      |
+----[SHA256]-----+
[root@ansible ~]# vim /etc/hosts
[root@ansible ~]# ssh-copy-id zabbix-agent01

ansible剧本的编写

首先先测试一下192.168.58.45主机是否可以通

[root@ansible ansible]# ansible -m ping 192.168.58.45
192.168.58.45 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false,
    "ping": "pong"
}

显示绿色 表示通过

剧本的编写

---
- name: zabbix6.0 install
  hosts: 192.168.58.45
  become: yes
  tasks:
    - name: rpm
      ansible.builtin.get_url:
        url:  https://repo.zabbix.com/zabbix/6.0/rhel/9/x86_64/zabbix-release-6.0-4.el9.noarch.rpm
        dest: ~/zabbix-release-6.0-4.el9.noarch.rpm
    - name: 安装 agent2
      ansible.builtin.yum: 
        name:
          - zabbix-release-6.0-4.el9.noarch.rpm 
          - zabbix-agent2
          - zabbix-agent2-plugin-*
    - name: 服务
      service:
        name: zabbix-agent2
        state: started
        enabled: yes

执行结果

[root@ansible ansible]# vim zabbix6.0.yaml 
[root@ansible ansible]# ansible-playbook zabbix6.0.yaml 

PLAY [zabbix6.0 install] ********************************************************************************

TASK [Gathering Facts] **********************************************************************************
ok: [192.168.58.45]

TASK [rpm] **********************************************************************************************
changed: [192.168.58.45]

TASK [安装 agent2] **************************************************************************************
changed: [192.168.58.45]

TASK [服务] *********************************************************************************************
changed: [192.168.58.45]

PLAY RECAP **********************************************************************************************
192.168.58.45              : ok=4    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

步骤大概 拉取rpm 包 然后下载安装 并开启服务 becom允许 root 

修改客户端的配置文件剧本

---
- name: modify file
  hosts: 192.168.58.45
  become: yes  #表示此任务需要root权限运行
  tasks:
    - name: replace line in file
      ansible.builtin.replace: #用于文件编辑模块 
        path: /etc/zabbix/zabbix_agent2.conf
        regexp: '^Server=127.0.0.1'        #指定查找和替换的模式
        replace: 'Server=192.168.58.20'   #定义新的行内容
        backup: yes

结束啦

  • 14
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

伟大的Akk

初入茅庐小小者加油!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值