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

[经验分享] zabbix 3.0.2监控mysql

[复制链接]

尚未签到

发表于 2018-9-28 10:48:18 | 显示全部楼层 |阅读模式
  内网有一台mysql服务器,版本是5.7.14
  关于这个版本安装,有兴趣可以参考
  http://xiao987334176.blog.51cto.com/2202382/1783509
  zabbix自带有一个模板Template App MySQL,用来监控mysql的
  但是不能直接使用,否则会因为没有Key,导致获取不到数据。
  下面介绍详细步骤。
  首先在mysql服务器安装zabbix-agent,请参考
  http://xiao987334176.blog.51cto.com/2202382/1768281
  最下面一部分。
  ###################################################################################
  讲解一个比较重要的问题。
  在shell里面,直接运行mysql相关命令,指定密码时,就会有一个提示
  比如: mysql -u zabbix -p123456 运行之后
  Warning: Using a password on the command line interface can be insecure.
  这个提示在mysql 5.5之后会出现。
  而且,这个提示,会被zabbix-servre捕捉到,在zabbix-server.log日志中会出现
  24123:20160826:101433.609 error reason for "110:mysql.status[Bytes_sent]" changed: Received value [mysqladmin: [Warning] Using a password on the command line interface can be insecure.8991074] is not suitable for value type [Numeric (float)]
  提示参数不符合
  在zabbix-server服务器上面,使用zabbix-get命令时
  [root@localhost ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.1.110 -p10050 -k mysql.status[Uptime]
  mysqladmin: [Warning] Using a password on the command line interface can be insecure.
  57577
  ###################################################################################
  那么为了解决这个问题,必须无密码登录才可以,为了安全起见,限定只能在localhost登录
  先创建一个zabbix用户(创建用户,密码不能为空,否则报错)

  grant all PRIVILEGES on *.* to zabbix@'localhost'>  设置密码为root
  update mysql.user set authentication_string=password('root') where user='zabbix' and Host = 'localhost';
  刷新权限
  flush privileges;
  退出
  exit;
  测试无密码登录
  [root@localhost opt]# mysql -u zabbix
  Welcome to the MySQL monitor.  Commands end with ; or \g.

  Your MySQL connection>  Server version: 5.7.14 Source distribution
  Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  Oracle is a registered trademark of Oracle Corporation and/or its
  affiliates. Other names may be trademarks of their respective
  owners.
  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  mysql> exit
  Bye
  发现一个很奇怪的现象,把密码设置和root一样,就可以无密码登录了
  mysql> select Host,User,authentication_string from mysql.user;
  +-----------+-----------+-------------------------------------------+
  | Host      | User      | authentication_string                     |
  +-----------+-----------+-------------------------------------------+
  | localhost | root      | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
  | localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
  | localhost | zabbix    | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
  +-----------+-----------+-------------------------------------------+
  3 rows in set (0.00 sec)
  进入Mysql服务器的zabbix-agent目录
  cd /usr/local/zabbix-agent/
  mkdir alertscripts
  编辑脚本
  vim checkmysql.sh
  内容如下:
  #!/bin/sh
  #MYSQL_SOCK="/data/3306/mysqld.sock"
  #MYSQL_PWD=`cat /usr/local/zabbix-agent/alertscripts/.mysqlpassword`
  ARGS=1
  if [ $# -ne "$ARGS" ];then
  echo "Please input one arguement:"
  fi
  case $1 in
  Uptime)
  result=`mysqladmin -uzabbix status|cut -f2 -d":"|cut -f1 -d"T"`
  echo $result
  ;;
  Com_update)
  result=`mysqladmin -uzabbix extended-status |grep -w "Com_update"|cut -d"|" -f3`
  echo $result
  ;;
  Slow_queries)
  result=`mysqladmin -uzabbix status |cut -f5 -d":"|cut -f1 -d"O"`
  echo $result
  ;;
  Com_select)
  result=`mysqladmin -uzabbix extended-status |grep -w "Com_select"|cut -d"|" -f3`
  echo $result
  ;;
  Com_rollback)
  result=`mysqladmin -uzabbix extended-status |grep -w "Com_rollback"|cut -d"|" -f3`
  echo $result
  ;;
  Questions)
  result=`mysqladmin -uzabbix status|cut -f4 -d":"|cut -f1 -d"S"`
  echo $result
  ;;
  Com_insert)
  result=`mysqladmin -uzabbix extended-status |grep -w "Com_insert"|cut -d"|" -f3`
  echo $result
  ;;
  Com_delete)
  result=`mysqladmin -uzabbix extended-status |grep -w "Com_delete"|cut -d"|" -f3`
  echo $result
  ;;
  Com_commit)
  result=`mysqladmin -uzabbix extended-status |grep -w "Com_commit"|cut -d"|" -f3`
  echo $result
  ;;
  Bytes_sent)
  result=`mysqladmin -uzabbix extended-status |grep -w "Bytes_sent" |cut -d"|" -f3`
  echo $result
  ;;
  Bytes_received)
  result=`mysqladmin -uzabbix extended-status |grep -w "Bytes_received" |cut -d"|" -f3`
  echo $result
  ;;
  Com_begin)
  result=`mysqladmin -uzabbix extended-status |grep -w "Com_begin"|cut -d"|" -f3`
  echo $result
  ;;
  *)
  echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions)"
  ;;
  esac
  设置权限
  chmod 755 checkmysql.sh
  chown zabbix:zabbix -R /usr/local/zabbix-agent/
  编辑配置文件
  vim /usr/local/zabbix-agent/etc/zabbix_agentd.conf
  增加紫色部分,内容如下:
  LogFile=/usr/local/zabbix-agent/logs/zabbix_agentd.log
  ###zabbix 服务端地址
  Server=192.168.1.109
  ##agent服务监听地址,也就是本机地址
  #ListenIP=192.168.1.105
  ###ServerActive=192.168.1.110
  ##zabbix-server端主机地址(zabbix server)
  Hostname=zabbix server
  UserParameter=mysql.version,mysql -V
  UserParameter=mysql.status
  • ,/usr/local/zabbix-agent/alertscripts/checkmysql.sh $1
      UserParameter=mysql.ping,mysqladmin -uzabbix ping | grep -c alive
      重启zabbix_agentd
      /etc/init.d/zabbix_agentd restart
      在zabbix-server服务器上面检查mysql
      [root@localhost alertscripts]# /usr/local/zabbix/bin/zabbix_get -s 192.168.1.110 -p10050 -k mysql.status[Uptime]
      9479
      [root@localhost alertscripts]#
      如果能直接返回数字,没有多余的字符,就说明成功了。
      在zabbix-server添加一台主机
    DSC0000.png

      添加模板的时候,选择Template App MySQL和Template OS Linux
    DSC0001.png

      等待10分钟,图像就会出来了。
    DSC0002.png

    DSC0003.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-603177-1-1.html 上篇帖子: 实现JSP通过Tomcat连接MySQL 下篇帖子: MySQL死锁案例
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

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

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

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

    扫描微信二维码查看详情

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


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


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


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



    合作伙伴: 青云cloud

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