zabbix agentd客户端插件ansible Shell一键自动安装脚本

安装步骤
一,关闭selinux和iptables
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
[root@localhost ~]# iptables -F

安装 ansibles
ansible自动化部署条件
1.建议基于ssh密钥方式建立远程连接
2.基于ssh口令方式建立远程连接(不建议)
[root@localhost ~]# yum install ansible epel-release -y

生成公私钥
[root@localhost ~]# ssh-keygen -t dsa -f /root/.ssh/id_dsa -N ' '    # 也可以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:KuwzFI7Rh5t5tt7KlcOYK8tIZRQLdOeClxv+XzlgCRI root@node1
The key's randomart image is:
+---[RSA 2048]----+
| .o E .          |
|   + B           |
|  ..O.o          |
|  .++=.. .       |
|   +=*  S        |
|  .+*.o* o .     |
|  ..oo=.= +      |
| . ++o.= o .     |
|  . +*=.o        |
+----[SHA256]-----+

修改自己的"/etc/hosts"如下
[root@localhost ~]vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.81  node
192.168.1.82  node1
192.168.1.83  node2

[root@localhost ~] for i in node node1 node2
do
ssh-copy-id   $i
done
然后"输入密码全部的主机"“在'ssh node1,连接不用输入密码公钥就完成了'”

[root@localhost ~] mkdir  /ansible
[root@control ~]# vim  /ansible/ansible.cfg
[defaults]
inventory = /ansible/hosts           

[root@localhost ~] vim /ansible/hosts
[test]        #定义主机组(组名称任意)
node          #定义组中的具体主机,组中包括一台主机node1
[proxy]       #定义主机组(组名称任意),英语词汇:proxy(代理人,委托人)
node1         #proxy组中包括一台主机node2
[webserver]   #这里的node[1:2]等同于node1和node2
node[1:2]

[root@localhost ~] cd  /ansible
弹出三台就好了"ansible'基础配置就好了'"
[root@localhost ansible ~] ansible  all  --list-hosts          #查看所有主机列表
  hosts (3):
    node
    node1
    node2

"zabbbix-agent'部署'案例使用了'script模块','lineinfile'模块' "
想了解更多模块可以'ansible-doc -l','ansible-doc script'****
[root@localhost ~] cd /ansible
[root@localhost ansible ~] vim zabbix_agent.sh
#! /bin/bash*
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
file=/etc/zabbix/zabbix_agentd.conf
yum install net-tools  -y

###请修改 IPzabbix_server ####
IPzabbix_server=192.168.1.82

ipserver=$(ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:")
yum install zabbix-agent  -y
systemctl  enable  zabbix-agent.service  --now
sed  -ri "169s/Zabbix server/$ipserver/"  $file
sed  -ri "117s/127.0.0.1/$IPzabbix_server/"  $file
sed  -ri "158s/127.0.0.1/$IPzabbix_server/"  $file

#大写ZZ 保存
[root@localhost ansible ~] vim zabbix_agent.yml
#注意yml文件的格式
---
- name: zabbix_agent_One_click_deployment
  hosts: test
  tasks:
  - name: zabbix_agent.sh
    script:
      /ansible/zabbix_agent.sh
  - name: Emphasis orientation
    lineinfile:
      path: /etc/zabbix/zabbix_agentd.conf
      line: EnableRemoteCommands = 1
  - name: restart_zabbix-agent.service
    service:
      name: zabbix-agent.service
      state: restarted


"ansible-playbook'就是剧本','演员按照剧本演' "
[root@localhost ansible ~] ansible-playbook zabbix_agent.yml
PLAY [zabbix_agent_One_click_deployment] *********************************************************************************

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

TASK [zabbix_agent.sh] ***************************************************************************************************
changed: [node1]

TASK [Emphasis orientation] **********************************************************************************************
ok: [node1]

TASK [restart_zabbix-agent.service] **************************************************************************************
changed: [node1]

PLAY RECAP ***************************************************************************************************************
node1                      : ok=4    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

已经完成zabbix-agent实现一键部署
     关注一下博主 崔博主更新

posted @   tom-service  阅读(98)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示