1 引言
#agent 172.16.212.133
#Centos7 ansible 172.16.212.134
2 自动安装zabbix-agent
CentOS7安装ansible参照 https://blog.csdn.net/qq_35550345/article/details/102700183
- 配置hosts
[zabbixagent]
172.16.212.133
- 生成roles目录
mkdir /etc/ansible/roles/zabbixagent/{files,tasks} -pv
- 创建剧本
#vim /etc/ansible/roles/zabbixagent/tasks/main.yml
- name: copy script
copy: src=~/zabbixagent.sh dest=~/ mode=0700
- name: run script
shell: ~/zabbixagent.sh
- name: config zabbix
copy: src=/etc/ansible/roles/zabbixagent/files/zabbix_agentd.conf dest=/etc/zabbix/
- name: start service
service: name=zabbix-agent state=started
#vim /etc/ansible/zabbixagent.yml
- hosts: zabbixagent
remote_user: root
roles:
- zabbixagent
- 创建脚本
#vim zabbixagent.sh
#!/bin/bash
curl https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
curl https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
mkdir /etc/yum.repos.d/back
mv CentOS-7.* /etc/yum.repos.d/back
wget -P /etc/yum.repos.d http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache -y
yum -y install zabbix zabbix-agent
- 创建配置文件
#cat /etc/ansible/roles/zabbixagent/files/zabbix.repo
[zabbix]
name=Zabbix Official Repository - \$basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/\$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - \$basearch
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/\$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
#cat /etc/ansible/roles/zabbixagent/files/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
LogRemoteCommands=1
Server=172.16.212.129
ServerActive=172.16.212.129
Hostname=agent
Include=/etc/zabbix/zabbix_agentd.d/*.conf
- 执行ansible剧本
ansible-playbook /etc/ansible/zabbixagent.yml
注意:129那个是zabbix-server,这么安装好之后,其agentd.conf配置文件不正确。这个问题将会在批量安装的笔记中解决。
添加了自动发现的规则之后,可以看到agent这台机器了,然后可以添加配置模版等等