设为首页 收藏本站
查看: 3117|回复: 0

[经验分享] Zabbix---添加linux服务器监控

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-9-14 09:41:40 | 显示全部楼层 |阅读模式
一,首先配置防火墙
1,添加zabbix 服务端的端口,如下配置:
[iyunv@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,重启防火墙,使配置生效。
[iyunv@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  ]
[iyunv@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/
[iyunv@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用户和组:
[iyunv@AppServerA conf]# useradd zabbix
[iyunv@AppServerA conf]# useradd -g zabbix zabbix
4,解压下载的软件包:
[iyunv@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增加服务器的端口号:
,[iyunv@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,启动客户端:
[iyunv@AppServerB conf]# /usr/local/zabbix_agent/sbin/zabbix_agentd -c /usr/local/zabbix_agent/conf/zabbix_agent
查看服务是否启动:
[iyunv@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工具进行和客户端进行测试。
[iyunv@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添加可执行的的权限并添加到到服务自启动。
[iyunv@AppServerA zabbix]# chmod +x /etc/init.d/zabbix_agented
[iyunv@AppServerA zabbix]# chkconfig --add zabbix_agentd
[iyunv@AppServerA init.d]# chkconfig zabbix_agented on

11,添加agentd通过配置-----主机------创建主机,如下图一的配置:
QQ截图20150914094109.png
12,配置模板,新建主机没见添加模板的话,里面没有监控信息,选中模板,添加相应的监控信息。
QQ截图20150914094115.png


13,在server端进行查看,如下图:
QQ截图20150914094123.png




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-113380-1-1.html 上篇帖子: zabbix监控之主动监控 下篇帖子: zabbix之主动、被动检测 服务器 linux 监控
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表