gfdg 发表于 2015-9-14 09:41:40

Zabbix---添加linux服务器监控

一,首先配置防火墙1,添加zabbix 服务端的端口,如下配置:# 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 :FORWARD ACCEPT :OUTPUT ACCEPT -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,重启防火墙,使配置生效。 # service iptables restartiptables: Setting chains to policy ACCEPT: filter iptables: Flushing firewall rules: iptables: Unloading modules: iptables: Applying firewall rules: # service iptables statusTable: filterChain INPUT (policy ACCEPT)numtarget   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/# 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用户和组:# useradd zabbix# useradd -g zabbix zabbix 4,解压下载的软件包:# tar zxvf zabbix_agents_2.0.8.linux2_6.amd64.tar.gz/usr/local/zabbix_agentsbin/zabbix_agentsbin/zabbix_agentdbin/zabbix_getbin/zabbix_senderconf/zabbix_agent.confconf/zabbix_agentd.confconf/zabbix_agentd/userparameter_examples.confconf/zabbix_agentd/userparameter_mysql.conf 5,编辑解压出来的zabbix_agentd.conf文件,修改下面的参数:Hostname=本机名//在本机上用hostname查看的结果必须和服务端添加的相同Server=Zabbix Server IP//zabbix服务器的ipLogFile=本机agentd日志保存文件SourceIP=本机IPListenPort=10050 6,修改/etc/services增加服务器的端口号: ,# cat >> /etc/services zabbix-agent 10050/tcp Zabbix Agentzabbix-agent 10050/udp Zabbix Agentzabbix-trapper 10051/tcp Zabbix Trapperzabbix-trapper 10051/udp Zabbix TrapperEOFCtrl+c 直接退出。 7,启动客户端:# /usr/local/zabbix_agent/sbin/zabbix_agentd -c /usr/local/zabbix_agent/conf/zabbix_agent查看服务是否启动:# ps -ef|grep zabbixzabbix    6640   10 13:45 ?      00:00:00 /usr/local/zabbix_agent/sbin/zabbix_agentd -c /usr/local/zabbix_agent/conf/zabbix_agentd.confzabbix    664166400 13:45 ?      00:00:00 /usr/local/zabbix_agent/sbin/zabbix_agentd -c /usr/local/zabbix_agent/conf/zabbix_agentd.confzabbix    664266400 13:45 ?      00:00:00 /usr/local/zabbix_agent/sbin/zabbix_agentd -c /usr/local/zabbix_agent/conf/zabbix_agentd.confzabbix    664366400 13:45 ?      00:00:00 /usr/local/zabbix_agent/sbin/zabbix_agentd -c /usr/local/zabbix_agent/conf/zabbix_agentd.confzabbix    664466400 13:45 ?      00:00:00 /usr/local/zabbix_agent/sbin/zabbix_agentd -c /usr/local/zabbix_agent/conf/zabbix_agentd.confzabbix    664566400 13:45 ?      00:00:00 /usr/local/zabbix_agent/sbin/zabbix_agentd -c /usr/local/zabbix_agent/conf/zabbix_agentd.confroot      665937550 13:45 pts/0    00:00:00 grep zabbix 8,在服务端通过zabbix_agent工具进行和客户端进行测试。# 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=0progdir="/usr/local/zabbix/sbin/"prog="zabbix_agentd" FULLPATH=$progdir/$progCONF_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 1esac exit $? 10,给zabbix_agentd添加可执行的的权限并添加到到服务自启动。# chmod +x /etc/init.d/zabbix_agented # chkconfig --add zabbix_agentd# chkconfig zabbix_agented on
11,添加agentd通过配置-----主机------创建主机,如下图一的配置:

12,配置模板,新建主机没见添加模板的话,里面没有监控信息,选中模板,添加相应的监控信息。



13,在server端进行查看,如下图:




页: [1]
查看完整版本: Zabbix---添加linux服务器监控