您好,登錄后才能下訂單哦!
前面一篇文章介紹Zabbix服務(wù)器的安裝教程,下面介紹客戶端Zabbix-agent安裝兩種方式:
一:單個(gè)安裝
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?
二、批量安裝:
如果客戶端比較多,要使用運(yùn)維自動(dòng)化進(jìn)行批量安裝,這里就要結(jié)合ansible進(jìn)行批量安裝客戶端
1、安裝關(guān)聯(lián)組件
[root@centos78 ~]#?yum?install?gcc*?pcre* -y? ?(缺少必要組件腳本推送會(huì)報(bào)錯(cuò))
[root@centos78 ~]#?yum install epel-release -y
2、安裝ansible組件
[root@centos78 ~]#?yum install ansible –y
3、配置ssh免密通信
[root@centos78 ~]# ssh-keygen? ?(連續(xù)敲回車即可)
[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、編輯腳本內(nèi)容
[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、執(zhí)行腳本批量安裝客戶端
[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客戶端是否在運(yùn)行
[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客戶端就已經(jīng)配置完成了,批量安裝時(shí),客戶端基本組件也要安裝好,比如make等等。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。