{"id":201548,"date":"2025-05-10T10:28:23","date_gmt":"2025-05-10T02:28:23","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201548\/"},"modified":"2025-05-10T10:28:23","modified_gmt":"2025-05-10T02:28:23","slug":"%e8%81%8a%e8%81%8aredis%e8%bd%bb%e4%be%bf%e5%bc%8f%e5%9b%be%e5%bd%a2%e5%8f%af%e8%a7%86%e5%8c%96%e7%9b%91%e6%8e%a7%e5%b7%a5%e5%85%b7%ef%bc%81","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201548\/","title":{"rendered":"\u804a\u804aRedis\u8f7b\u4fbf\u5f0f\u56fe\u5f62\u53ef\u89c6\u5316\u76d1\u63a7\u5de5\u5177\uff01"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u804a\u804aRedis\u8f7b\u4fbf\u5f0f\u56fe\u5f62\u53ef\u89c6\u5316\u76d1\u63a7\u5de5\u5177\uff01<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5206\u4eab\u300a\u804a\u804aRedis\u8f7b\u4fbf\u5f0f\u56fe\u5f62\u53ef\u89c6\u5316\u76d1\u63a7\u5de5\u5177\uff01\u300b\uff0c\u8986\u76d6\u4e86\u6570\u636e\u5e93\u7684\u5e38\u89c1\u57fa\u7840\u77e5\u8bc6\uff0c\u5176\u5b9e\u4e00\u4e2a\u8bed\u8a00\u7684\u5168\u90e8\u77e5\u8bc6\u70b9\u4e00\u7bc7\u6587\u7ae0\u662f\u4e0d\u53ef\u80fd\u8bf4\u5b8c\u7684\uff0c\u4f46\u5e0c\u671b\u901a\u8fc7\u8fd9\u4e9b\u95ee\u9898\uff0c\u8ba9\u8bfb\u8005\u5bf9\u81ea\u5df1\u7684\u638c\u63e1\u7a0b\u5ea6\u6709\u4e00\u5b9a\u7684\u8ba4\u8bc6(B \u6570)\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u66f4\u597d\u7684\u638c\u63e1\u5b83\u3002<\/p>\n<h3>\u7b80\u4ecb<\/h3>\n<p>\u8f7b\u4fbf\u5f0fRedis Monitor\u662f\u9762\u5411\u7814\u53d1\u4eba\u5458\u7684\u56fe\u5f62\u53ef\u89c6\u5316\u76d1\u63a7\u5de5\u5177\uff0c\u501f\u9274\u4e86LEPUS(\u5929\u5154)\u76d1\u63a7\u5e73\u53f0\u4ee5\u53caredis-cli info\u547d\u4ee4\u8f93\u51fa\u7684\u76d1\u63a7\u6307\u6807\u9879\uff0c\u53bb\u6389\u4e86\u4e00\u4e9b\u4e0d\u5fc5\u8981\u3001\u770b\u4e0d\u61c2\u7684\u76d1\u63a7\u9879\uff0c\u76ee\u524d\u91c7\u96c6\u4e86\u6570\u636e\u5e93\u8fde\u63a5\u6570\u3001QPS\u3001\u5185\u5b58\u4f7f\u7528\u7387\u7edf\u8ba1\u548c\u540c\u6b65\u590d\u5236\u5ef6\u8fdf\u65f6\u957f\u3002<\/p>\n<p>Redis Monitor\u53ef\u4ee5\u76d1\u63a7\u5355\u673a\u6a21\u5f0f\u3001\u54e8\u5175\u6a21\u5f0f\u3001\u96c6\u7fa4\u6a21\u5f0f\uff0c\u5e76\u4e14\u5f55\u5165\u4e00\u4e2a\u4e3b\u5e93\u6216\u8005\u4ece\u5e93IP\uff0c\u81ea\u52a8\u53d1\u73b0\u4e3b\u5e93\u6216\u8005\u4ece\u5e93IP\u4fe1\u606f\uff0c\u65e0\u9700\u4eba\u5de5\u518d\u6b21\u5f55\u5165\u3002<\/p>\n<p>\u91c7\u7528\u8fdc\u7a0b\u8fde\u63a5\u65b9\u5f0f\u83b7\u53d6\u6570\u636e\uff0c\u6240\u4ee5\u65e0\u9700\u5728Redis\u670d\u52a1\u5668\u7aef\u90e8\u7f72\u76f8\u5173agent\u6216\u8ba1\u5212\u4efb\u52a1\uff0c\u53ef\u5b9e\u73b0\u5fae\u4fe1\u548c\u90ae\u4ef6\u62a5\u8b66\u3002<\/p>\n<p>\u6ce8\uff1a\u76d1\u63a7\u73af\u5883\u4e3aRedis 6.2\u4ee5\u4e0a\u7248\u672c\u3002<\/p>\n<h4>1\uff09Redis\u72b6\u6001\u76d1\u63a7&nbsp;<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230128\/167489823363d4eb3947fb4.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<h4>2\uff09\u70b9\u51fb\u56fe\u8868\uff0c\u53ef\u4ee5\u67e5\u770b\u5386\u53f2\u66f2\u7ebf\u56fe<\/h4>\n<p>\u8fde\u63a5\u6570<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230128\/167489823363d4eb3991c8a.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<ul>\n<li>\n<p>QPS\u6bcf\u79d2\u67e5\u8be2\u91cf<\/p>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230128\/167489823363d4eb39ee7a4.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<ul>\n<li>\n<p>\u5185\u5b58\u4f7f\u7528\u7387<\/p>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230128\/167489823463d4eb3a3cae8.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<h3>\u73af\u5883\u642d\u5efa<\/h3>\n<h4>1\u3001php-redis\u9a71\u52a8\u5b89\u88c5\uff08Centos 7\u7cfb\u7edf\uff09<\/h4>\n<p>shell&gt; yum install -y php-pear php-devel php httpd mysql php-mysqlnd php-redis<\/p>\n<h4>2\u3001\u91cd\u542fhttpd\u670d\u52a1<\/h4>\n<p>shell&gt; systemctl restart httpd.service<\/p>\n<h4>3\u3001redis\u9700\u8981\u6388\u6743\u8fde\u63a5<\/h4>\n<p>&gt; config set requirepass yourPassword<\/p>\n<h3>Redis monitor\u90e8\u7f72<\/h3>\n<p>\u628ahttps:\/\/github.com\/hcymysql\/redis_monitor\/archive\/master.zip<\/p>\n<p>\u5b89\u88c5\u5305\u89e3\u538b\u7f29\u5230 \/var\/www\/html\/\u76ee\u5f55\u4e0b<\/p>\n<p>cd \/var\/www\/html\/redis_monitor\/<\/p>\n<p>chmod 755 .\/mail\/sendEmail<\/p>\n<p>chmod 755 .\/weixin\/wechat.py<\/p>\n<p>\uff08\u6ce8\uff1a\u90ae\u4ef6\u548c\u5fae\u4fe1\u62a5\u8b66\u8c03\u7528\u7684\u7b2c\u4e09\u65b9\u5de5\u5177\uff0c\u6240\u4ee5\u8fd9\u91cc\u8981\u8d4b\u4e88\u53ef\u6267\u884c\u6743\u9650755\uff09<\/p>\n<h4>1\u3001\u5bfc\u5165Redis Monitor\u76d1\u63a7\u5de5\u5177\u8868\u7ed3\u6784\uff08redis_monitor\u5e93\uff09<\/h4>\n<p>cd \/var\/www\/html\/mongo_monitor\/<\/p>\n<p>mysql <span style=\"color: #d73a49\">&#8211;<\/span>uroot <span style=\"color: #d73a49\">&#8211;<\/span>p123456 <span style=\"color: #d73a49\"> redis_monitor_schema<span style=\"color: #005cc5\">.sql<\/span><\/span><\/p>\n<p>\uff08\u6ce8\uff1amysql_status_history\u8868\u5f15\u64ce\u53ef\u4ee5\u66f4\u6539\u4e3aRocksDB\u5f15\u64ce\uff0c\u652f\u6301\u6570\u636e\u538b\u7f29\uff0c\u8fd9\u5bf9\u4e8e\u51cf\u5c0f\u5b58\u50a8\u7a7a\u95f4\u4ee5\u53ca\u589e\u5febIO\u6548\u7387\u90fd\u6709\u76f4\u63a5\u7684\u5e2e\u52a9\uff09<\/p>\n<p>https:\/\/www.percona.com\/blog\/2018\/04\/30\/a-look-at-myrocks-performance\/<\/p>\n<h4>2\u3001\u5f55\u5165\u88ab\u76d1\u63a7\u4e3b\u673a\u7684\u4fe1\u606f<\/h4>\n<p>mysql<span style=\"color: #d73a49\">&gt;<\/span> <span style=\"color: #d73a49\">INSERT<\/span> <span style=\"color: #d73a49\">INTO<\/span> `redis_status_info`<span style=\"color: #997\">(<\/span>`id`,`host`,`tag`,`pwd`,`port`,`monitor`,`send_mail`,`send_mail_to_list`,`send_weixin`,`send_weixin_to_list`,`alarm_threads_running`,`threshold_alarm_threads_running`,`alarm_used_memory_status`,`threshold_warning_used_memory`<span style=\"color: #997\">)<\/span> <span style=\"color: #d73a49\">VALUES<\/span> <span style=\"color: #997\">(<\/span><span style=\"color: #005cc5\">1<\/span>,<span style=\"color: #690\">&#8216;192.168.176.27&#8217;<\/span>,<span style=\"color: #690\">&#8216;Redis\u6d4b\u8bd5&#8217;<\/span>,<span style=\"color: #690\">&#8216;hechunyang123456&#8217;<\/span>,<span style=\"color: #005cc5\">6379<\/span>,<span style=\"color: #005cc5\">1<\/span>,<span style=\"color: #005cc5\">1<\/span>,<span style=\"color: #690\">&#8216;hechunyang@126.com&#8217;<\/span>,<span style=\"color: #005cc5\">1<\/span>,<span style=\"color: #690\">&#8216;hechunyang&#8217;<\/span>,<span style=\"color: #905\">NULL<\/span>,<span style=\"color: #005cc5\">150<\/span>,<span style=\"color: #905\">NULL<\/span>,<span style=\"color: #690\">&#8216;200M&#8217;<\/span><span style=\"color: #997\">)<\/span>;<\/p>\n<p>\u6ce8\uff0c\u4ee5\u4e0b\u5b57\u6bb5\u53ef\u4ee5\u6309\u7167\u9700\u6c42\u53d8\u66f4\uff1a<\/p>\n<ul>\n<li>\n<p>ip\u5b57\u6bb5\u542b\u4e49\uff1a\u8f93\u5165\u88ab\u76d1\u63a7Redis\u7684IP\u5730\u5740<\/p>\n<\/li>\n<li>\n<p>tag\u5b57\u6bb5\u542b\u4e49\uff1a\u8f93\u5165\u88ab\u76d1\u63a7Redis\u7684\u4e1a\u52a1\u540d\u5b57<\/p>\n<\/li>\n<li>\n<p>pwd\u5b57\u6bb5\u542b\u4e49\uff1a\u8f93\u5165\u88ab\u76d1\u63a7Redis<\/p>\n<\/li>\n<li>\n<p>port\u5b57\u6bb5\u542b\u4e49\uff1a\u8f93\u5165\u88ab\u76d1\u63a7Redis\u7684\u7aef\u53e3\u53f7<\/p>\n<\/li>\n<li>\n<p>monitor\u5b57\u6bb5\u542b\u4e49\uff1a0\u4e3a\u5173\u95ed\u76d1\u63a7\uff08\u4e5f\u4e0d\u91c7\u96c6\u6570\u636e\uff0c\u76f4\u63a5\u8df3\u8fc7\uff09\uff1b1\u4e3a\u5f00\u542f\u76d1\u63a7\uff08\u91c7\u96c6\u6570\u636e\uff09<\/p>\n<\/li>\n<li>\n<p>send_mail\u5b57\u6bb5\u542b\u4e49\uff1a0\u4e3a\u5173\u95ed\u90ae\u4ef6\u62a5\u8b66\uff1b1\u4e3a\u5f00\u542f\u90ae\u4ef6\u62a5\u8b66<\/p>\n<\/li>\n<li>\n<p>send_mail_to_list\u5b57\u6bb5\u542b\u4e49\uff1a\u90ae\u4ef6\u4eba\u5217\u8868<\/p>\n<\/li>\n<li>\n<p>send_weixin\u5b57\u6bb5\u542b\u4e49\uff1a0\u4e3a\u5173\u95ed\u5fae\u4fe1\u62a5\u8b66\uff1b1\u4e3a\u5f00\u542f\u5fae\u4fe1\u62a5\u8b66<\/p>\n<\/li>\n<li>\n<p>send_weixin_to_list\u5b57\u6bb5\u542b\u4e49\uff1a\u5fae\u4fe1\u516c\u4f17\u53f7<\/p>\n<\/li>\n<li>\n<p>threshold_alarm_threads_running\u5b57\u6bb5\u542b\u4e49\uff1a\u8bbe\u7f6e\u8fde\u63a5\u6570\u9600\u503c\uff08\u5355\u4f4d\u4e2a\uff09<\/p>\n<\/li>\n<li>\n<p>threshold_warning_used_memory\u5b57\u6bb5\u542b\u4e49\uff1a\u8bbe\u7f6e\u5df2\u7528\u5185\u5b58\u62a5\u8b66\u9600\u503c\uff08\u5355\u4f4dM\uff09<\/p>\n<\/li>\n<\/ul>\n<h4>3\u3001\u4fee\u6539conn.php\u914d\u7f6e\u6587\u4ef6<\/h4>\n<p>vim \/var\/www\/html\/redis_monitor\/conn.php<\/p>\n<p>$con <span style=\"color: #d73a49\">=<\/span> mysqli_connect<span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;127.0.0.1&#8221;<\/span>,<span style=\"color: #690\">&#8220;admin&#8221;<\/span>,<span style=\"color: #690\">&#8220;hechunyang&#8221;<\/span>,<span style=\"color: #690\">&#8220;redis_monitor&#8221;<\/span>,<span style=\"color: #690\">&#8220;3306&#8221;<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #d73a49\">or<\/span> die<span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;\u6570\u636e\u5e93\u94fe\u63a5\u9519\u8bef&#8221;<\/span><span style=\"color: #005cc5\">.mysql_error<\/span><span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span><span style=\"color: #997\">)<\/span>;<\/p>\n<p>\u6539\u6210\u4f60\u7684Redis Monitor\u76d1\u63a7\u5de5\u5177\u8868\u7ed3\u6784\uff08redis_monitor\u5e93\uff09\u8fde\u63a5\u4fe1\u606f\u3002<\/p>\n<h4>4\u3001\u4fee\u6539\u90ae\u4ef6\u62a5\u8b66\u4fe1\u606f<\/h4>\n<p>cd \/var\/www\/html\/redis_monitor\/mail\/<\/p>\n<p>vim mail.php<\/p>\n<p>system<span style=\"color: #997\">(<\/span><span style=\"color: #690\">&#8220;.\/mail\/sendEmail -f chunyang_he@139.com -t &#8216;{$this-&gt;send_mail_to_list}&#8217; -s smtp.139.com:25 -u &#8216;{$this-&gt;alarm_subject}&#8217; -o message-charset=utf8 -o message-content-type=html -m &#8216;\u62a5\u8b66\u4fe1\u606f\uff1a<br \/> {$this-&gt;alarm_info}&#8217; -xu chunyang_he@139.com -xp &#8216;123456&#8217; -o tls=no&#8221; <\/span><span style=\"color: #997\">)<\/span>;<\/p>\n<p>\u6539\u6210\u4f60\u7684\u53d1\u4ef6\u4eba\u5730\u5740\uff0c\u8d26\u53f7\u5bc6\u7801\uff0c\u91cc\u9762\u7684\u53d8\u91cf\u4e0d\u7528\u4fee\u6539\u3002<\/p>\n<h4>5\u3001\u4fee\u6539\u5fae\u4fe1\u62a5\u8b66\u4fe1\u606f<\/h4>\n<p>cd \/var\/www\/html\/redis_monitor\/weixin\/<\/p>\n<p>vim wechat.py<\/p>\n<p>\u5fae\u4fe1\u4f01\u4e1a\u53f7\u8bbe\u7f6e\u79fb\u6b65<\/p>\n<p>https:\/\/github.com\/X-Mars\/Zabbix-Alert-WeChat\/blob\/master\/README.md<\/p>\n<p>\u770b\u6b64\u6559\u7a0b\u914d\u7f6e\u3002<\/p>\n<h4>6\u3001\u5b9a\u65f6\u4efb\u52a1\u6bcf\u5206\u949f\u6293\u53d6\u4e00\u6b21<\/h4>\n<p>crontab -l<\/p>\n<p><span style=\"color: #d73a49\">*\/<\/span><span style=\"color: #005cc5\">1<\/span> <span style=\"color: #d73a49\">*<\/span> <span style=\"color: #d73a49\">*<\/span> <span style=\"color: #d73a49\">*<\/span> <span style=\"color: #d73a49\">*<\/span> <span style=\"color: #d73a49\">\/<\/span>usr<span style=\"color: #d73a49\">\/<\/span>bin<span style=\"color: #d73a49\">\/<\/span>php <span style=\"color: #d73a49\">\/<\/span>var<span style=\"color: #d73a49\">\/<\/span>www<span style=\"color: #d73a49\">\/<\/span>html<span style=\"color: #d73a49\">\/<\/span>redis_monitor<span style=\"color: #d73a49\">\/<\/span>check_redis_status<span style=\"color: #005cc5\">.php<\/span> <span style=\"color: #d73a49\">&gt;<\/span> <span style=\"color: #d73a49\">\/<\/span>dev<span style=\"color: #d73a49\">\/<\/span><span style=\"color: #905\">null<\/span> <span style=\"color: #005cc5\">2<\/span> <span style=\"color: #d73a49\">&gt;&amp;<\/span><span style=\"color: #005cc5\">1<\/span><\/p>\n<p>check_redis_status.php\uff08\u7528\u6765\u91c7\u96c6\u88ab\u76d1\u63a7\u7aefRedis\u72b6\u6001\u4fe1\u606f\u548c\u89e6\u53d1\u62a5\u8b66\uff09<\/p>\n<h4>7\u3001\u66f4\u6539\u9875\u9762\u81ea\u52a8\u5237\u65b0\u9891\u7387<\/h4>\n<p>vim redis_status_monitor.php<\/p>\n<p>http<span style=\"color: #d73a49\">&#8211;<\/span>equiv<span style=\"color: #d73a49\">=<\/span><span style=\"color: #690\">&#8220;refresh&#8221;<\/span> cnotallow<span style=\"color: #d73a49\">=<\/span><span style=\"color: #690\">&#8220;600&#8221;<\/span><\/p>\n<p>\u9ed8\u8ba4\u9875\u9762\u6bcf600\u79d2\u81ea\u52a8\u5237\u65b0\u4e00\u6b21\u3002<\/p>\n<h4>8\u3001\u9875\u9762\u8bbf\u95ee<\/h4>\n<p>http:\/\/yourIP\/redis_monitor\/redis_status_monitor.php<\/p>\n<p>\u52a0\u4e00\u4e2a\u8d85\u94fe\u63a5\uff0c\u53ef\u65b9\u4fbf\u5730\u63a5\u5165\u4f60\u4eec\u7684\u81ea\u52a8\u5316\u8fd0\u7ef4\u5e73\u53f0\u91cc\u3002<\/p>\n<h4>\u5de5\u5177\u7814\u53d1\u8005\u4ecb\u7ecd<\/h4>\n<p>\u8d3a\u6625\u65f8\uff0c\u51e1\u666e\u91d1\u79d1\u548c\u7231\u94b1\u8fdbDBA\u56e2\u961f\u8d1f\u8d23\u4eba\uff0c\u300aMySQL\u7ba1\u7406\u4e4b\u9053\uff1a\u6027\u80fd\u8c03\u4f18\u3001\u9ad8\u53ef\u7528\u4e0e\u76d1\u63a7\u300b\u7b2c\u4e00&amp;\u4e8c\u7248\u3001\u300aMySQL\u8fd0\u7ef4\u8fdb\u9636\u6307\u5357\u300b\u4f5c\u8005\uff0c\u66fe\u4efb\u804c\u4e8e\u4e2d\u56fd\u79fb\u52a8\u98de\u4fe1\u3001\u5b89\u5353\u673a\u950b\u7f51\u3002\u4e94\u6b21\u8363\u83b7dbaplus\u5e74\u5ea6MVP\uff0c\u81f4\u529b\u4e8eMariaDB\u3001MongoDB\u7b49\u5f00\u6e90\u6280\u672f\u7684\u7814\u7a76\uff0c\u4e3b\u8981\u8d1f\u8d23\u6570\u636e\u5e93\u6027\u80fd\u8c03\u4f18\u3001\u76d1\u63a7\u548c\u67b6\u6784\u8bbe\u8ba1\u3002<\/p>\n<p>\u5de5\u5177\u4e0b\u8f7d\uff1ahttps:\/\/github.com\/hcymysql\/redis_monitor<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u804a\u804aRedis\u8f7b\u4fbf\u5f0f\u56fe\u5f62\u53ef\u89c6\u5316\u76d1&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-201548","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201548","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=201548"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201548\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}