Zabbix 监控安装使用文档
Zabbix监控安装使用文档 系统环境:centos 6.5_64 webUi 运行环境lnmp/lamp 都可以实验使用的lamp Zabbix版本zabbix-2.4.7.tar.gz一.运行环境安装#这里使用yum安装的运行环境 #yum install phpphp-mysqlphp-gd mysqlmysql-server mysql-develhttpd-y #安装编译器及依赖包# yum install gcc gcc-c++ libxml2 libxml2-develnet-snmp net-snmp-deve libcurl libcurl-devel -y#切记 关闭 iptables关闭 selinux二.安装及配置zabbix①编译安装zabbixWgethttp://ncu.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.4.7/zabbix-2.4.7.tar.gz#安装包上传到/usr/local/src/ # cd /usr/local/src/# tar -zxvf zabbix-2.4.7.tar.gz# cd /usr/local/src/ #./configure--prefix=/usr/local/zabbix-2.4.7/--enable-server --enable-agent--with-mysql--with-net-snmp--with-libcurl--with-libxml2#make#makeinstall创建用户为了安全考虑 zabbix 只使用普通用户运行#groupaddzabbix#useradd-gzabbixzabbix②初始化数据库 zabbixserver 与 proxy 需要数据库,angent 不需要。尤其要注意的是 proxy 只需要导入一个 sql 文件,而 server 一共要导入 3 个 sql 文件。我当时在搭建 proxy 的时候导入了 3 个 sql,导致出现报错。后来才发现 proxy只需要导入一个表结构即可#/etc/init.d/mysqld start;chkconfigmysqldon#启动mysql服务 ③配置mysql root 密码 # mysqladmin -u root password zabbix ④导入zabbix的数据库 # mysql -uroot -pzabbix zabbix < /usr/local/src/zabbix-2.4.7/database/mysql/schema.sql # mysql -uroot -pzabbix zabbix < /usr/local/src/zabbix-2.4.7/database/mysql/images.sql # mysql -uroot -pzabbix zabbix < /usr/local/src/zabbix-2.4.7/database/mysql/data.sql ⑤配置zabbix #vi /usr/local/zabbix-2.4.7/etc/zabbix_server.conf # grep -E -v "^#|^$" /usr/local/zabbix-2.4.7/etc/zabbix_server.confLogFile=/tmp/zabbix_server.logDBName=zabbixDBUser=rootDBPassword=zabbixDBPort=3306⑥启动zabbix server # /usr/local/zabbix-2.4.7/sbin/zabbix_server#默认端口 10051 ⑦日志查看 tail -f /tmp/zabbix_server.log #日志我们会经常检查我们的配置是否有问题经常看的 ⑧客户端安装配置 由于,我们编译安装server的时候已经安装客户端了,这里无需再次安装这里只需要在被控端,安装即可,zabbix_server 也需要配置zabbix_agent,只需配置agent即可 #安装包上传到/usr/local/src/ # cd /usr/local/src/# tar -zxvf zabbix-2.4.7.tar.gz# cd /usr/local/src/ #./configure--prefix=/usr/local/zabbix-2.4.7/--enable-server --enable-agent#make#makeinstall创建用户为了安全考虑 zabbix 只使用普通用户运行#groupaddzabbix#useradd-gzabbixzabbix ⑨zabbix 客户端配置 # vi /usr/local/zabbix-2.4.7/etc/zabbix_agentd.conf#配置文件别搞错了# grep -E -v "^#|^$" /usr/local/zabbix-2.4.7/etc/zabbix_agentd.confLogFile=/tmp/zabbix_agentd.logServer=127.0.0.1ServerActive=127.0.0.1Hostname=zabbix-server 这里的hostname建议添加到/etc/hosts 做主机名解析 其中 Server 和 ServerActive 都指定 zabbixserver 的 IP 地址,不同的是,前者是被动后者是主动。也就是说 Server 这个配置是用来允许 127.0.0.1 这个 ip 来我这取数据。而 serverActive 的 127.0.0.1 的意思是,客户端主动提交数据给他。明白了吗?为什么要分主动和被动?后续再来讨论这个问题!其他主机安装客户端记得添加 zabbix 用户。 ⑩zabbix 客户端启动 # /usr/local/zabbix-2.4.7/sbin/zabbix_agentd 三.zabbix 管理网站配置 # cd /usr/local/src/zabbix-2.4.7#cp -rp frontends/php/ /var/www/html/①配置Apache 虚拟主机# vi /etc/httpd/conf/httpd.confNameVirtualHost *:80<VirtualHost *:80> DocumentRoot /var/www/html/php ServerName 172.16.1.183</VirtualHost> ②启动Apache# /etc/init.d/httpdrestart ;chkconfig httpd on 访问 http://ip需要修改php.ini 满足安装需求,才能下一步 ③修改php参数 # vi/etc/php.ini date.timezone = Asia/Shanghaimax_input_time = 300max_execution_time = 300post_max_size = 16M# yum install php-bcmath php-xmlphp-mbstring-y #安装这些依赖软件包 修改过,重启Apache 这样就OK 了,我们可以下一步安装了 这里填写,数据库信息,填写完毕,点击 “test connection ” 这里,点击下一步即可 如果这里报错,那就把这个文件下载下来,丢到对应目录、 到此,说明,我们已经安装完毕 访问,我们配置的主机,默认账号admin密码zabbix 四.Zabbix 监控 VMware主机 ①修改配置文件,启用VMware监控# vi /usr/local/zabbix-2.4.7/etc/zabbix_server.conf#################vmware################StartVMwareCollectors=5#预启动的VMware数据采集线程数量,值范围:0~250VMwareFrequency=60 #VMware的数据检测缓存大小,值范围:256K~2GVMwareCacheSize=8M #数据采集的频率,值范围:10~86400 ②添加,被监控主机 点击 “crate host” 添加主机 添加上,三个模块 填入这几个参数,root/ password就是VMware esxi 或者vcenter的账号密码{$PASSWORD} password{$URL} https://10.0.2.15/sdk {$USERNAME} root 填写完毕,点击 “添加” 然后重启 zabbix -server 我们监控日志,可以看到VMware监控已经开启,等待一会,就能获得发现到的虚拟机 过了一会,就会发现,很多VMware esxi 或者vcenter上面的虚机 了 四.Zabbix 监控 Mysql ①在客户端安装zabbix_agentdchk_mysql.sh 脚本放在/etc/zabbix/目录下面并修改里面的mysql密码,根据自己情况写#!/bin/bash# ------------------------------------------------------------------------------- # 用户名MYSQL_USER='root' # 密码MYSQL_PWD='redhat' # 主机地址/IPMYSQL_HOST='172.16.1.219' # 端口MYSQL_PORT='3306' # 数据连接MYSQL_CONN="/usr/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}" # 参数是否正确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_queries) 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_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)" ;; esac
# vi /etc/zabbix_agentd.conf UserParameter=mysql.version,mysql -V# 获取mysql性能指标,这个是上面定义好的脚本,此脚本,会附带需要改里面的主机密码UserParameter=mysql.status[*],/etc/zabbix/chk_mysql.sh$1# 获取mysql运行状态UserParameter=mysql.ping,mysqladmin -uroot-predhat-P3306 -h127.0.0.1 ping | grep -c alive 重启 zabbix_agentd 添加mysql模板 这里就可以看到,监控数据 五.Zabbix 监控 linux主机上面有写安装zabbix-client端,这里我用脚本安装的,方便批量部署脚本内容如下: #!/bin/bash# Guying2015/12/2 15:42#version v1###zabbix client install ##############关闭selinux 和防火墙#########/etc/init.d/iptables stop;chkconfig iptables offsed -i"s/SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config/usr/sbin/setenforce0###################################################yum install epel-release -y&& yum installzabbix22-agent -y#######这里提示输入的是zabb-server 的ip地址######################echo "Pleaseinput zabbix server ipaddress:"readipaddresssed -i "s/Server=.*/Server=$ipaddress/g" /etc/zabbix_agentd.confsed -i "s/ServerActive=.*/ServerActive=$ipaddress:10051/g" /etc/zabbix_agentd.conf#这里提示输入的主机名要和,添加监控主机名对应,否则无法通讯,建议将主机名添加到#zabbix-server 的/etc/hosts 文件里面#echo "Please input hostname:"readhostnamesed -i "s/Hostname=.*/Hostname=$hostname/g" /etc/zabbix_agentd.conf/etc/init.d/zabbix-agentd restart ;chkconfigzabbix-agentd on 执行过脚本,只需在zabbix UI 上面,添加该主机即可注意:主机名写到zabbix-server /etc/hosts 里面,主机名和,添加主机的名字对应 六.zabbix 监控 nginx ①先运行我们的脚本,配置好zabbix client端 ②配置 client端使用git 下载下来 Git地址 https://github.com/blacked/zbx_nginx_template.git # gitclonehttps://github.com/blacked/zbx_nginx_template.git我们需要改这个文件zbx_nginx_stats.pyzabbix_host = '172.16.1.218' # Zabbix server IPzabbix_port = 10051 # Zabbix server port hostname = 'nginx-node4.example.com' # Name of monitored host, like it shows in zabbix web uitime_delta = 1 # grep interval in minutes # URL to nginx stat (http_stub_status_module)stat_url = 'http://172.16.1.222/nginx_stat' # Nginx log file pathnginx_log_file_path = '/usr/local/nginx/logs/access.log' # Optional Basic Authusername = 'user'password = 'pass' # Temp file, with log file cursor positionseek_file = '/tmp/nginx_log_stat'修改完毕放入 /etc/zabbix/ 里面这些需要我们修改③赋予,脚本可执行权限,我们zabbix客户端需要调用这个脚本chmod +x /etc/zabbix/zbx_nginx_stats.py④写计划任务,来运行这个脚本收集数据# sudo crontab -e*/1 * * * * /etc/zabbix/zbx_nginx_stats.py ⑤.在zabbix web界面 导入 zbx_nginx_template.xml 模块这个不细讲了,web界面,点击configure ---模板 ----导入模板,导入即可⑥ 配置nginx 开启 nginx_satus功能location /nginx_stat {stub_status on; # Turn on nginx statsaccess_log off; # We do not need logs for statsallow 127.0.0.1; # Security: Only allow access from IPdeny all; # Deny requests from the other of the world}配置过后,主机上添加上这个模板进行测试 参考官方文档:https://github.com/blacked/zbx_nginx_template
{:6_441:}
页:
[1]