前面一篇文章介紹Zabbix服務器的安裝教程,下面介紹客戶端Zabbix-agent安裝兩種方式:
shell
一:單個安裝vim
一、安裝客戶端centos
[root@centos78 ~]# yum install zabbix-agent –ybash
二、編輯配置文件服務器
[root@centos78 ~]# vim /etc/zabbix/zabbix_agentd.confapp
修改server、hostname、serveractive信息運維
[root@centos78 ~]# systemctl restart zabbix-agentssh
[root@centos78 ~]# systemctl enable zabbix-agent curl
2、批量安裝:
ide
若是客戶端比較多,要使用運維自動化進行批量安裝,這裏就要結合ansible進行批量安裝客戶端
一、安裝關聯組件
[root@centos78 ~]# yum install gcc* pcre* -y (缺乏必要組件腳本推送會報錯)
[root@centos78 ~]# yum install epel-release -y
二、安裝ansible組件
[root@centos78 ~]# yum install ansible –y
三、配置ssh免密通訊
[root@centos78 ~]# ssh-keygen (連續敲回車便可)
[root@centos78 ~]# ssh-copy-id 192.168.101.78
[root@centos78 ~]# ssh-copy-id 192.168.101.75
四、配置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"
}
五、配置批量推送腳本
[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
六、下載用於批量安裝的客戶端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/ (下載路徑和腳本路徑一致)
七、編輯腳本內容
[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
八、執行腳本批量安裝客戶端
[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等等。