用ansible部署zabbix_agent
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用ansible部署zabbix_agent相关的知识,希望对你有一定的参考价值。
前期准备
批量配置yum源
ansible -i t4 st -m copy -a ‘src=/opt/shell/yum/rhe65.repo dest=/tmp/ owner=watson group=watson mode=644 backup=yes‘
rhe65.repo文件内容:
[rhe65] name=rhe65 baseurl=ftp://192.168.20.25/pub/rhel65/ gpgcheck=0 enabled=1
1、脚本准备好
#!/bin/bash cd /tmp wget ftp://192.168.20.25/zabbix/zabbix_agent.zip unzip zabbix_agent.zip mv zabbix_agent /usr/local/ mv zabbix_agentd /etc/init.d/ useradd zabbix chmod 755 /etc/init.d/zabbix_agentd cp /usr/local/zabbix_agent/sbin/zabbix_agentd /usr/local/sbin/ service zabbix_agentd start rm -rf /tmp/zabbix_agent.zip
2、把脚本复制到远程主机
ansible -i /opt/shell/lizuofang/beleve/19/hosts_19 dev -m copy -a ‘src=/opt/shell/zabbix/install_agent.sh dest=/tmp/ owner=watson group=watson mode=755 backup=yes‘
3、用root用户执行远程主机脚本
ansible -i /opt/shell/lizuofang/beleve/19/hosts_19 dev -m shell -a ‘bash /tmp/install_agent.sh‘ -K --become
错误1
"msg": "Aborting, target uses selinux but python bindings (libselinux-python) aren‘t installed!"
cat t3 |grep FA|awk ‘{print $1}‘
ansible -i t2 sh -m shell -a ‘yum install libselinux-python -y ‘ -K --become
yum install libselinux-python -y
错误2
/tmp/install_agent.sh: line 7: useradd: command not found
/tmp/install_agent.sh: line 10: service: command not found
j解决:
ansible -i t2 sh -m shell -a ‘yum install lsof -y ‘ -K --become#如果提示已经安装,没能解决就用下面的命令
ansible -i /opt/shell/lizuofang/beleve/19/hosts_19 dev -m shell -a ‘PAHT="/usr/local/sbin:/usr/sbin:/sbin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin";source /etc/profile;bash /tmp/install_agent.sh‘ -K --become
下面出错同理
4、检查agent端口是否起来
ansible /opt/shell/lizuofang/beleve/19/hosts_19 dev -m shell -a ‘lsof -i:10050‘ -K --become
错误
/bin/sh: lsof: command not found
错误解决同上
以上是关于用ansible部署zabbix_agent的主要内容,如果未能解决你的问题,请参考以下文章
ansible-playbook 批量安装zabbix_agent