Ansible批量安装Zabbix-agnet客户端;
前面一篇文章介绍Zabbix服务器的安装教程,下面介绍客户端Zabbix-agent安装两种方式:
创新互联公司主要为客户提供服务项目涵盖了网页视觉设计、VI标志设计、全网营销推广、网站程序开发、HTML5响应式网站建设公司、手机网站制作设计、微商城、网站托管及网站建设维护、WEB系统开发、域名注册、国内外服务器租用、视频、平面设计、SEO优化排名。设计、前端、后端三个建站步骤的完善服务体系。一人跟踪测试的建站服务标准。已经为成都酒店设计行业客户提供了网站营销推广服务。
一:单个安装
1、安装客户端
[root@centos78 ~]# yum install zabbix-agent –y
2、编辑配置文件
[root@centos78 ~]# vim /etc/zabbix/zabbix_agentd.conf
修改server、hostname、serveractive信息
[root@centos78 ~]# systemctl restart zabbix-agent
[root@centos78 ~]# systemctl enable zabbix-agent
二、批量安装:
如果客户端比较多,要使用运维自动化进行批量安装,这里就要结合ansible进行批量安装客户端
1、安装关联组件
[root@centos78 ~]# yum install gcc* pcre* -y (缺少必要组件脚本推送会报错)
[root@centos78 ~]# yum install epel-release -y
2、安装ansible组件
[root@centos78 ~]# yum install ansible –y
3、配置ssh免密通信
[root@centos78 ~]# ssh-keygen (连续敲回车即可)
[root@centos78 ~]# ssh-copy-id 192.168.101.78
[root@centos78 ~]# ssh-copy-id 192.168.101.75
4、配置ansible,编辑hosts,定义组
[root@centos78 ~]# vim /etc/ansible/hosts
[zabbix]
192.168.101.75
192.168.101.78
ping客户端是否通讯
[root@centos78 ~]# ansible zabbix -m ping
192.168.101.78 | SUCCESS => {
"changed": false,
"ping": "pong"
}
192.168.101.75 | SUCCESS => {
"changed": false,
"ping": "pong"
}
5、配置批量推送脚本
[root@centos78 ~]# cd /etc/ansible/
[root@centos78 ansible]# cat zabbix_agent.yml (使用ansible的jinjia模板来部署ansible客户端)
- hosts: zabbix
remote_user: root
tasks:
- name: install zabbix_agent packages
yum: name={{ item }} state=latest
with_items:
- curl-devel
- name: copy install_shell to clien
copy: src=/etc/ansible/zabbix_agent.sh dest=/usr/local/src/zabbix_agent.sh
- name: sent tar
copy: src=/usr/local/src/zabbix-3.4.12.tar.gz dest=/usr/local/src/zabbix-3.4.12.tar.gz (没有安装包的可以按照操作下载)
notify: install shell
handlers:
- name: install shell
shell: /bin/bash /usr/local/src/zabbix_agent.sh
6、下载用于批量安装的客户端zabbix-3.4.12.tar.gz
[root@centos78 ansible]# cd /usr/local/src/ (下载路径和脚本路径一致)
[root@centos78 src]# wget https:
//nchc
.dl.sourceforge.net
/project/zabbix/ZABBIX
%20Latest%20Stable
/3
.4.12
/zabbix-3
.4.12.
tar
.gz
[root@centos78 ansible]# cd /usr/local/src/ (下载路径和脚本路径一致)
7、编辑脚本内容
[root@centos78 ansible]# cat zabbix_agent.sh
#!/bin/bashuseradd zabbix -s /sbin/nologincd /usr/local/srctar -xf zabbix-3.4.12.tar.gzcd zabbix-3.4.12 ./configure --with-net-snmp --with-libcurl --enable-agent --prefix=/usr/local/zabbixmake && make installcp misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/chmod 700 /etc/init.d/zabbix_agentdsed -i 's\ZABBIX_BIN="/usr/local/sbin/zabbix_agentd\ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd\g' /etc/init.d/zabbix_agentdsed -i 's\Server=127.0.0.1\Server=192.168.101.78\g' /usr/local/zabbix/etc/zabbix_agentd.confsed -i 's\ServerActive=127.0.0.1\ServerActive=192.168.101.78\g' /usr/local/zabbix/etc/zabbix_agentd.conf /etc/init.d/zabbix_agentd startchkconfig zabbix_agentd on
8、执行脚本批量安装客户端
[root@centos78 ansible]# ansible-playbook zabbix_agent.yml
PLAY [zabbix] ******************************************************************
TASK [Gathering Facts] *********************************************************
ok: [192.168.101.78]
ok: [192.168.101.75]
TASK [install zabbix_agent packages] *******************************************
ok: [192.168.101.75] => (item=[u'curl-devel'])
ok: [192.168.101.78] => (item=[u'curl-devel'])
TASK [copy install_shell to clien] *********************************************
ok: [192.168.101.78]
ok: [192.168.101.75]
TASK [sent tar] ****************************************************************
ok: [192.168.101.78]
ok: [192.168.101.75]
PLAY RECAP *********************************************************************
192.168.101.75 : ok=4 changed=0 unreachable=0 failed=0
192.168.101.78 : ok=4 changed=0 unreachable=0 failed=0
查看zabbix客户端是否在运行
[root@centos78 ansible]# ansible zabbix -m shell -a "ps -ef |grep zabbix_agentd"
192.168.101.78 | SUCCESS | rc=0 >>
zabbix 11785 1 0 22:33 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_agentd
zabbix 11787 11785 0 22:33 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix 11788 11785 0 22:33 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix 11789 11785 0 22:33 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix 11790 11785 0 22:33 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix 11791 11785 0 22:33 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
root 17136 17131 0 23:52 pts/1 00:00:00 /bin/sh -c ps -ef |grep zabbix_agentd
root 17138 17136 0 23:52 pts/1 00:00:00 grep zabbix_agentd
192.168.101.75 | SUCCESS | rc=0 >>
zabbix 21448 1 0 22:20 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_agentd
zabbix 21450 21448 0 22:20 ? 00:00:01 /usr/local/zabbix/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix 21451 21448 0 22:20 ? 00:00:01 /usr/local/zabbix/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix 21452 21448 0 22:20 ? 00:00:01 /usr/local/zabbix/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix 21453 21448 0 22:20 ? 00:00:01 /usr/local/zabbix/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix 21454 21448 0 22:20 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
root 23645 23640 0 23:52 pts/1 00:00:00 /bin/sh -c ps -ef |grep zabbix_agentd
root 23647 23645 0 23:52 pts/1 00:00:00 grep zabbix_agentd
使用ansible批量安装zabbix客户端就已经配置完成了,批量安装时,客户端基本组件也要安装好,比如make等等。
网页名称:Ansible批量安装Zabbix-agnet客户端;
文章出自:http://azwzsj.com/article/jisocs.html