您好,登录后才能下订单哦!
前面一篇文章介绍Zabbix服务器的安装教程,下面介绍客户端Zabbix-agent安装两种方式:
一:单个安装
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等等。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。