一,首先配置防火墙
1,添加zabbix 服务端的端口,如下配置:
[root@AppServerB conf]# vi /etc/sysconfig/iptables
-A INPUT -p udp --dport 10051 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 18091 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 10050:10051 -j ACCEPT
# Generated by iptables-save v1.4.7 on Fri May 22 16:42:47 2015
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [312404188:85274465529]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -p udp --dport 123 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -p udp --dport 161 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -s 192.168.1.244 -m state --state NEW -m udp -p udp --dport 10050:10051 -j ACCEPT
-A INPUT -s 192.168.1.244 -m state --state NEW -m tcp -p tcp --dport 10050:10051 -j ACCEPT
(只添加192.168.1.244服务器的访问)
2,重启防火墙,使配置生效。
[root@AppServerB conf]# service iptables restart
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]
[root@AppServerB conf]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
3 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:123 state NEW,ESTABLISHED
4 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:161 state NEW,ESTABLISHED
5 ACCEPT udp -- 192.168.1.244 0.0.0.0/0 state NEW udp dpts:10050:10051
6 ACCEPT tcp -- 192.168.1.244 0.0.0.0/0 state NEW tcp dpts:10050:10051
注意,如果防火墙关闭的话,以上步骤可以省略。
二,在客户端服务器需要以下操作:
1,安装zabbix_agentd需要从官网上下载相对应的软件,http://www.zabbix.com/download2.php
我使用的是2.0.8
2,把下载的包上传到所加的linux服务器上。我上传的路径是/tmp/install/
[root@AppServerB zabbix_agent]# ll /tmp/install/
total 452
-rw-r--r--. 1 root root 178068 Aug 25 12:47 net-snmp-utils-5.5-49.el6_5.3.x86_64.rpm
-rw-r--r--. 1 root root 279646 Sep 11 13:10 zabbix_agents_2.0.8.linux2_6.amd64.tar.gz
3,创建zabbix用户和组:
[root@AppServerA conf]# useradd zabbix
[root@AppServerA conf]# useradd -g zabbix zabbix
4,解压下载的软件包:
[root@AppServerB install]# tar zxvf zabbix_agents_2.0.8.linux2_6.amd64.tar.gz /usr/local/zabbix_agent
sbin/zabbix_agent
sbin/zabbix_agentd
bin/zabbix_get
bin/zabbix_sender
conf/zabbix_agent.conf
conf/zabbix_agentd.conf
conf/zabbix_agentd/userparameter_examples.conf
conf/zabbix_agentd/userparameter_mysql.conf
5,编辑解压出来的zabbix_agentd.conf文件,修改下面的参数:
Hostname=本机名 //在本机上用hostname查看的结果必须和服务端添加的相同
Server=Zabbix Server IP //zabbix服务器的ip
LogFile=本机agentd日志保存文件
SourceIP=本机IP
ListenPort=10050
6,修改/etc/services增加服务器的端口号:
,[root@AppServerB conf]# cat >> /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
EOF
Ctrl+c 直接退出。
7,启动客户端:
[root@AppServerB conf]# /usr/local/zabbix_agent/sbin/zabbix_agentd -c /usr/local/zabbix_agent/conf/zabbix_agent
查看服务是否启动:
[root@AppServerB conf]# ps -ef|grep zabbix
zabbix 6640 1 0 13:45 ? 00:00:00 /usr/local/zabbix_agent/sbin/zabbix_agentd -c /usr/local/zabbix_agent/conf/zabbix_agentd.conf
zabbix 6641 6640 0 13:45 ? 00:00:00 /usr/local/zabbix_agent/sbin/zabbix_agentd -c /usr/local/zabbix_agent/conf/zabbix_agentd.conf
zabbix 6642 6640 0 13:45 ? 00:00:00 /usr/local/zabbix_agent/sbin/zabbix_agentd -c /usr/local/zabbix_agent/conf/zabbix_agentd.conf
zabbix 6643 6640 0 13:45 ? 00:00:00 /usr/local/zabbix_agent/sbin/zabbix_agentd -c /usr/local/zabbix_agent/conf/zabbix_agentd.conf
zabbix 6644 6640 0 13:45 ? 00:00:00 /usr/local/zabbix_agent/sbin/zabbix_agentd -c /usr/local/zabbix_agent/conf/zabbix_agentd.conf
zabbix 6645 6640 0 13:45 ? 00:00:00 /usr/local/zabbix_agent/sbin/zabbix_agentd -c /usr/local/zabbix_agent/conf/zabbix_agentd.conf
root 6659 3755 0 13:45 pts/0 00:00:00 grep zabbix
8,在服务端通过zabbix_agent工具进行和客户端进行测试。
[root@localhost ~]# zabbix_get -s192.168.1.250 -p10050 -k"system.uptime"
1980619
返回数值,说明配置正确。
9,把zabbix_agentd配置成服务,把以下脚本考到/etc/init.d/zabbix_agentd下:
#!/bin/bash
#
# chkconfig: - 55 45
# description: zabbix_agentd
# probe: false
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up. If you are running without a network, comment this out.
[ "${NETWORKING}" = "no" ] && exit 0
RETVAL=0
progdir="/usr/local/zabbix/sbin/"
prog="zabbix_agentd"
FULLPATH=$progdir/$prog
CONF_FILE="/usr/local/zabbix/conf/zabbix_agentd.conf"
action $"starting $prog: " $FULLPATH -c $CONF_FILE
start() {
# Start daemons.
if [ -n "`/sbin/pidof $prog`" ]; then
echo -n "$prog: already running"
failure $"$prog start"
echo
return 1
fi
echo -n $"Starting $prog: "
# we can‘t seem to use daemon here - emulate its functionality
su -c $progdir$prog - $USER
RETVAL=$?
usleep 100000
if [ -z "`/sbin/pidof $progdir$prog`" ]; then
# The child processes have died after fork()ing, e.g.
# because of a broken config file
RETVAL=1
fi
[ $RETVAL -ne 0 ] && failure $"$prog startup"
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog && success $"$prog startup"
echo
return $RETVAL
}
stop() {
RETVAL=0
pid=
# Stop daemons.
echo -n $"Stopping $prog: "
pid=`/sbin/pidof -s $prog`
if [ -n "$pid" ]; then
kill -TERM $pid
else
failure $"$prog stop"
echo
return 1
fi
RETVAL=$?
[ $RETVAL -ne 0 ] && failure $"$prog stop"
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog && success $"$prog stop"
echo
return $RETVAL
}
restart() {
stop
# wait for forked daemons to die
usleep 1000000
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
condrestart)
[ -f /var/lock/subsys/$prog ] && restart
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart}"
exit 1
esac
exit $?
10,给zabbix_agentd添加可执行的的权限并添加到到服务自启动。
[root@AppServerA zabbix]# chmod +x /etc/init.d/zabbix_agented
[root@AppServerA zabbix]# chkconfig --add zabbix_agentd
[root@AppServerA init.d]# chkconfig zabbix_agented on
11,添加agentd通过配置-----主机------创建主机,如下图一的配置:
12,配置模板,新建主机没见添加模板的话,里面没有监控信息,选中模板,添加相应的监控信息。
13,在server端进行查看,如下图:
本文出自 “清风明月” 博客,请务必保留此出处http://liqingbiao.blog.51cto.com/3044896/1693795
原文地址:http://liqingbiao.blog.51cto.com/3044896/1693795