Zabbix实战-简易教程--Proxy和Agent端安装

Posted

On The Way!

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Zabbix实战-简易教程--Proxy和Agent端安装相关的知识,希望对你有一定的参考价值。

3.3.1 zabbix proxy安装(源码方式)

1.创建目录

mkdir -p /usr/local/zabbix

 2.安装必要软件

yum install -y fping(若安装不成功) 或 wget http://pkgs.repoforge.org/fping/fping-3.1-1.el6.rf.i686.rpm
 
yum install -y gcc make cmake mysql-server mysql-devel php php-gd php-devel php-mysql php-bcmath php-ctytpe php-xml php-xmlreader php-xlmwriter php-session php-net-socket php-mbstring php-gettext httpd net-snmp curl curl-devel net-snmp net-snmp-devel perl-DBI libxml libxml2-devel

 

 3. 添加用户

groupadd zabbix
useradd -g zabbix zabbix -s /sbin/nologin

 4. 创建数据库

service mysqld start
mysql -uroot -p
>create database zabbix_proxy default charset utf8;
> grant all on zabbix_proxy.* to [email protected] identified by zabbix;
>flush privileges;
>exit

 5. 导入数据库中的表

cd /root/zabbix-2.2.4/database/mysql
# mysql -uzabbix -pzabbix zabbix < schema.sql (proxy端只需要这一步,不需要数据)

6. 编译安装(proxy和client)

proxy:
cd /root/zabbix-2.2.4 ./configure --enable-agent --enable-proxy --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --prefix=/usr/local/zabbix make && make install

agent:
cd /root/zabbix-2.2.4
./configure --enable-agent  --prefix=/usr/local/zabbix
make && make install

 7. 编辑配置文件(zabbix_proxy)

cd /usr/local/zabbix/etc/
 
vi /usr/local/zabbix/etc/zabbix_proxy.conf
Server=42.62.70.75
Hostname=db-proxy
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
ProxyLocalBuffer=24
ProxyOfflineBuffer=24
ConfigFrequency=300
DataSenderFrequency=3
StartPollers=20
StartIPMIPollers=2
StartPollersUnreachable=2
StartTrappers=10
StartPingers=15
StartHTTPPollers=3
StartVMwareCollectors=3
VMwareCacheSize=40M
StartSNMPTrapper=1
CacheSize=100M
StartDBSyncers=6
HistoryCacheSize=100M
HistoryTextCacheSize=200M
Timeout=30
LogSlowQueries=3000
AllowRoot=1

 

8. 配置proxy的agent文件

vi /usr/local/zabbix/etc/zabbix_agentd.conf修改如下内容:
Server=42.62.70.75
ServerActive=42.62.70.75
Hostname=db-proxy
RefreshActiveChecks=60
MaxLinesPerSecond=800
Timeout=30
AllowRoot=1
UnsafeUserParameters=1
UserParameter=system.agent.checkSecure,/usr/local/ServerScript/check_secure.sh

 9. 添加到services

# vi /etc/services
在文件最后面添加如下的内容:
zabbix-agent 10050/tcp # Zabbix Agent
zabbix-agent 10050/udp # Zabbix Agent
zabbix-trapper 10051/tcp # Zabbix Trapper
zabbix-trapper 10051/udp # Zabbix Trapper
 

 10. 启动守护进程

vi /etc/init.d/zabbix_proxy
vi /etc/init.d/zabbix_agentd
添加后面的脚本
chmod a+x /etc/init.d/zabbix_proxy
chmod a+x /etc/init.d/zabbix_agentd
service zabbix_proxy start
service zabbix_agentd start

11. 添加开机启动

chkconfig zabbix_proxy on
chkconfig zabbix_agentd on

12. 允许10050和10051通过防火墙

iptables -A INPUT -p tcp --dport 10050 -j ACCEPT
iptables -A INPUT -p tcp --dport 10051 -j ACCEPT
或者关闭防火墙
service iptables stop
setenforce 0

13. 启动服务

service zabbix_proxy start
service zabbix_agentd start

3.3.2 Agent端配置

1.修改客户(agent)端配置文件

vi /usr/local/zabbix/etc/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agented_om.pid
LogFile=/var/log/zabbix/zabbix_agented_om.log
LogFileSize=0
Server=10.19.1.18
ListenPort=10060
ServerActive=10.19.1.18
Hostname=db-proxy
Include=/etc/zabbix_agentd_om/etc/zabbix_agentd.conf.d/

 2.重启客户端

service zabbix_agentd restart

3.脚本zabbix_proxy

 1 #!/bin/sh
 2 # chkconfig: 345 95 95
 3 # desctription: Zabbix Proxy
 4 # Zabbix
 5 # Copyright (C) 2001-2013 Zabbix SIA
 6 #
 7 # This program is free software; you can redistribute it and/or modify
 8 # it under the terms of the GNU General Public License as published by
 9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  
21  
22 # Start/Stop the Zabbix agent daemon.
23 # Place a startup script in /sbin/init.d, and link to it from /sbin/rc[023].d
24  
25  
26 SERVICE="Zabbix proxy"
27 DAEMON=/usr/local/zabbix/sbin/zabbix_proxy
28 PIDFILE=/tmp/zabbix_agentd.pid
29 BASEDIR=/usr/local/zabbix/
30 ZABBIX_AGENTD=$BASEDIR/sbin/zabbix_proxy
31 case $1 in
32 start)
33 if [ -x ${DAEMON} ]
34 then
35 $DAEMON
36 # Error checking here would be good...
37 echo "${SERVICE} started."
38 else
39 echo "Can‘t find file ${DAEMON}."
40 echo "${SERVICE} NOT started."
41 fi
42 ;;
43 stop)
44 if [ -s ${PIDFILE} ]
45 then
46 if kill `cat ${PIDFILE}` >/dev/null 2>&1
47 then
48 echo "${SERVICE} terminated."
49 rm -f ${PIDFILE}
50 fi
51 fi
52 ;;
53 restart)
54 $0 stop
55 sleep 10
56 $0 start
57 ;;
58 *)
59 echo "Usage: $0 start|stop|restart"
60 ;;
61 esac
62  
63  

 4.脚本zabbix_agentd

 1 #!/bin/sh
 2 #chkconfig: 345 95 95
 3 #description:Zabbix agent
 4 # Zabbix
 5 # Copyright (C) 2001-2013 Zabbix SIA
 6 #
 7 # This program is free software; you can redistribute it and/or modify
 8 # it under the terms of the GNU General Public License as published by
 9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  
21  
22 # Start/Stop the Zabbix agent daemon.
23 # Place a startup script in /sbin/init.d, and link to it from /sbin/rc[023].d
24  
25  
26 SERVICE="Zabbix agent"
27 DAEMON=/usr/local/zabbix/sbin/zabbix_agentd
28 PIDFILE=/tmp/zabbix_agentd.pid
29 BASEDIR=/usr/local/zabbix
30 ZABBIX_AGENTD=$BASEDIR/sbin/zabbix_agentd
31  
32  
33 case $1 in
34 start)
35 if [ -x ${DAEMON} ]
36 then
37 $DAEMON
38 # Error checking here would be good...
39 echo "${SERVICE} started."
40 else
41 echo "Can‘t find file ${DAEMON}."
42 echo "${SERVICE} NOT started."
43 fi
44 ;;
45 stop)
46 if [ -s ${PIDFILE} ]
47 then
48 if kill `cat ${PIDFILE}` >/dev/null 2>&1
49 then
50 echo "${SERVICE} terminated."
51 rm -f ${PIDFILE}
52 fi
53 fi
54 ;;
55 restart)
56 $0 stop
57 sleep 10
58 $0 start
59 ;;
60 *)
61 echo "Usage: $0 start|stop|restart"
62 ;;
63 Esac

 

以上是关于Zabbix实战-简易教程--Proxy和Agent端安装的主要内容,如果未能解决你的问题,请参考以下文章

Zabbix实战-简易教程--低层次发现(LLD)

Zabbix实战-简易教程--DB安装和表分区

Zabbix实战-简易教程--动作(Actions)--自动发现

zabbix实战-简易教程

Zabbix实战-简易教程--动作(Actions)--自动注册

Zabbix实战-简易教程--Server端安装