Zabbix

在这里插入图片描述
Zabbix组件
Zabbix Server:负责接收agent发送的报告信息的核心组件,所有配置、统计数据及操作数据均由其组织进行
Database Storage:专用于存储所有配置信息,以及有zabbix收集的数据
Web interface(frontend):zabbix的GUI接口,通常与server运行在同一台机器上
Proxy:可选组件,常用于分布式监控环境中,代理Server收集部分被监控数据并统一发往Server端
Agent:部署在被监控主机上,负责收集本地数据并发往Server端或者Proxy端
在这里插入图片描述
Zabbix常用术语

host(主机):要监控的网络设备,可由IP或DNS名称指定

host group(主机组):主机的逻辑容器,可以包含主机和模板,但同一个组内的主机和模板不能互相链接;主机组通常在给用户或用户组指派监控权限时使用

item(监控项):一个特定监控指标的相关数据,这些数据来自于被监控对象;item是zabbix进行数据收集的核心,没有item,将没有数据;相对某监控对象来说,每个item都有"key"进行标识

trigger(触发器):一个表达式,用于评估某监控对象的某特定item内所接收到的数据是否在合理范围内,即阀值;接受到的数据大于阀值是,触发器状态将从OK转变为Problem,当数据量再次回归到合理范围时,其状态将从Problem转换回OK

event(事件):即发生的一个值得关注的事件,例如触发器的状态转变,新的agent或重新上线的agent的自动注册等

action(动作):指对于特定事件事先定义的处理方法,通过包含操作(如发送通知)和条件(何时执行操作)

escalation(报警升级):发送警报或执行远程命令的自定义方案,如每隔5min发送一次警报,共发送5次等

media(媒介):发送通知的手段和通道,如Email、Jabber或SMS

notification(通知):通过选定的媒介向用户发送的有关某事件的信息

remote command(远程命令):预定义的命令,可在被监控主机处于某个特定条件下时自动执行

template(模板):用于快速定义被监控主机的预设条目集合,通常包含了item、trigger、graph、screen、application以及low-level

discovery rule;模板可以直接链接至单个主机

application(应用):一组item的集合

web scennaro(web场景):用于检测web站点可用性的一个或多个http请求

frontend(前端):zabbix的web接口

[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog rpm
[root@localhost rpm]# mount /dev/sr0 /media/cdrom
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@localhost rpm]# yum -y install createrepo
[root@localhost rpm]# createrepo ./
[root@localhost rpm]# createrepo -v ./
在这里插入图片描述

[root@localhost rpm]# vim /etc/yum.repos.d/CentOS-Media.repo 
[c6-media]
name=CentOS-$releasever - Media
baseurl=file:///media/CentOS/
        file:///media/cdrom/
        file:///media/cdrecorder/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
[rpm]
name=rpm
baseurl=file:///root/rpm/
gpgcheck=0
enabled=1

 [root@localhost rpm]# yum -y install pcre pcre-devel zlib-devel libaio libaio-devel libxml2 libxml2-devel bzip2-devel openssl onet-snmp-devel net-snmp curl-devel gd gcc gcc-c++ make libjpeg-devel libpng-devel libcurl-devel perl-ExtUtils-CBuilder perl-Exter mysql-devel net-snmp-utils

[root@localhost rpm]# cat /etc/yum.repos.d/CentOS-Media.repo

#[c6-media]
#name=CentOS-$releasever - Media
#baseurl=file:///media/CentOS/
        #file:///media/cdrom/
       #file:///media/cdrecorder/
#gpgcheck=1
#enabled=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
[rpm]
name=rpm
baseurl=file:///root/rpm/
gpgcheck=0
enabled=1

   [root@localhost rpm]# yum clean all
   [root@localhost rpm]# yum makecache
   [root@localhost rpm]# yum -y install libvpx-devel gd-devel

安装nginx

[root@localhost ~]# useradd -s /sbin/nologin -M www
[root@localhost ~]# tar xf nginx-1.10.2.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/nginx-1.10.2/
[root@localhost nginx-1.10.2]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module && make && make install
[root@localhost nginx-1.10.2]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/

#创建nginx配置文件模版

[root@localhost nginx-1.10.2]# cd /usr/local/nginx/conf/
[root@localhost conf]# egrep -v "^$|#" nginx.conf.default > nginx.conf

#将nginx配置文件改成如下内容
[root@localhost conf]# vim nginx.conf
[root@localhost conf]# cat nginx.conf

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
    location / {
        root   html;
        index  index.php index.html index.htm;
    }
    location = /nginx-status {
                stub_status on;
                access_log off;
        }
    location ~ \.php$ {
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_index index.php;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

[root@localhost conf]# nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax
is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test
is successful

安装mysql

[root@localhost ~]# tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# mv mysql-5.5.32-linux2.6-x86_64 mysql
[root@localhost local]# cd mysql/
[root@localhost mysql]# /bin/cp support-files/my-small.cnf /etc/my.cnf 
[root@localhost mysql]# useradd -s /sbin/nologin -M mysql
[root@localhost mysql]# chown -R mysql.mysql data
[root@localhost mysql]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chmod +x /etc/init.d/mysqld 
[root@localhost mysql]# /etc/init.d/mysqld start

Starting MySQL… SUCCESS!

[root@localhost mysql]# netstat -antup | grep 3306

tcp 0 0 0.0.0.0:3306 0.0.0.0:*
LISTEN 3990/mysqld

安装libmcrypt

[root@localhost ~]# tar xf libmcrypt-2.5.8.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/libmcrypt-2.5.8/
[root@localhost libmcrypt-2.5.8]# ./configure && make && make install

安装GD

[root@localhost ~]# tar xf GD-2.18.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/GD-2.18/
[root@localhost GD-2.18]# perl Makefile.PL
[root@localhost GD-2.18]# make && make install

安装PHP

 [root@localhost ~]# tar xf php-5.6.30.tar.gz -C /usr/src/
 [root@localhost ~]# cd /usr/src/php-5.6.30/
 [root@localhost php-5.6.30]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-bz2 --with-curl --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
 [root@localhost php-5.6.30]# make && make install

#创建php配置文件

[root@localhost php-5.6.30]# cp php.ini-development /usr/local/php/etc/php.ini

#修改php配置文件php.ini

[root@localhost php-5.6.30]# cat -n /usr/local/php/etc/php.ini | sed -n '372p;382p;393p;660p;702p;820p;936p'

372 max_execution_time = 300
382 max_input_time = 300
393 memory_limit = 256M
660 post_max_size = 32M
702 always_populate_raw_post_data = -1
820 upload_max_filesize = 16M
936 date.timezone =Asia/Shanghai
#创建php-fpm配置文件

[root@localhost php-5.6.30]# cd /usr/local/php/etc/
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf

#修改php-fpm.conf配置文件

[root@localhost etc]# cat -n php-fpm.conf | sed -n '149,150p'
   149  user = www
   150  group = www

在这里插入图片描述
[root@localhost ~]# /etc/init.d/zabbix_server start
[root@localhost ~]# /etc/init.d/zabbix-agent start

Zabbix监控MySQL数据库操作实战

编写监控脚本

在nginx服务器(192.168.163.160)上安装一个MySQL 下面是监控mysql状态的一个shell脚本,内容如下:

[root@nginx scripts]# pwd
/server/scripts
[root@nginx scripts]# cat check_mysql.sh 
#!/bin/bash
# author:

MySQL_USER="root"
MySQL_PWD="123123"
MySQL_HOST="127.0.0.1"
MySQL_PORT="3306"

MySQL_CONN="/usr/local/mysql/bin/mysqladmin -u${MySQL_USER} -h${MySQL_HOST} -P${MySQL_PORT} -p${MySQL_PWD}"

if [ $# -ne "1" ];then
    echo "arg error!"
fi

case $1 in
	Uptime)
		result=`${MySQL_CONN} status | cut -f2 -d":" | cut -f1 -d "T"`
		echo $result
        ;;
    Com_update)
        result=`${MySQL_CONN} extended-status | grep -w "Com_update" | cut -d"|" -f3`
        echo $result
		;;
	Slow_querles)
		result=`${MySQL_CONN} status | cut -f5 -d":" | cut -f1 -d"O"`
		echo $result
        ;;
    Com_select)
        result=`${MySQL_CONN} extended-status | grep -w "Com_select" | cut -d "|" -f3`
        echo $result
		;;
	Com_rollback)
		result=`${MySQL_CONN} extended-status | grep -w "Com_rollback" | cut -d"|" -f3`
		echo $result
        ;;
    Questions)
        result=`${MySQL_CONN} status | cut -f4 -d":" | cut -f1 -d"S"`
        echo $result
		;;
	Com_insert)
		result=`${MySQL_CONN} extended-status | grep -w "Com_insert" | cut -d"|" -f3`
		echo $result
        ;;
    Com_delete)
        result=`${MySQL_CONN} extended-status | grep -w "Com_delete" | cut -d"|" -f3`
        echo $result
		;;
	Com_commit)
		result=`${MySQL_CONN} extended-status | grep -w "Com_commit" | cut -d"|" -f3`
		echo $result
        ;;
    Bytes_sent)
        result=`${MySQL_CONN} extended-status | grep -w "Bytes_sent" | cut -d"|" -f3`
        echo $result
		;;
	Bytes_received)
		result=`${MySQL_CONN} extended-status | grep -w "Bytes_received" | cut -d"|" -f3`
		echo $result
        ;;
    Com_begin)
        result=`${MySQL_CONN} extended-status | grep -w "Com_begin" | cut -d"|" -f3`
        echo $result
		;;
	*)
	echo "Usage:$0(Uptime|Com_update|Slow_querles|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)"
        ;;
esac
[root@nginx scripts]# chmod +x check_mysql.sh 
[root@nginx scripts]# chown zabbix.zabbix check_mysql.sh
[root@nginx zabbix]# cd /etc/zabbix/zabbix_agentd.d/

[root@localhost zabbix_agentd.d]# cat mysql_status.conf 
UserParameter=mysql.status[*],/server/scripts/check_mysql.sh $1
UserParameter=mysql.ping,/usr/local/mysql/bin/mysqladmin -uroot -p123123 ping | grep -c alive
UserParameter=mysql.version,mysql -h"127.0.0.1" -uroot -p123123 -e "select version();"|awk 'END {print}'   

重启zabbix-agentd服务

[root@nginx zabbix_agentd.d]# /etc/init.d/zabbix-agent restart
Shutting down Zabbix agent:    [ OK ]
Starting Zabbix agent:              [ OK ]

测试

[root@Zabbix_Server scripts]# zabbix_get -s 192.168.163.160 -p 10050 -k "mysql.status[Uptime]"
2791
[root@Zabbix_Server scripts]# zabbix_get -s 192.168.163.160 -p 10050 -k "mysql.status[Com_commit]"
0
[root@Zabbix_Server scripts]# zabbix_get -s 192.168.163.160 -p 10050 -k "mysql.status[Bytes_sent]"
144628
[root@Zabbix_Server scripts]# zabbix_get -s 192.168.163.160 -p 10050 -k "mysql.status[Bytes_received]"
3934
[root@Zabbix_Server scripts]# zabbix_get -s 192.168.163.160-p 10050 -k "mysql.ping"
1
[root@Zabbix_Server scripts]# zabbix_get -s 192.168.163.160 -p 10050 -k "mysql.version"
5.5.32

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值