{"id":121182,"date":"2024-10-25T11:13:25","date_gmt":"2024-10-25T03:13:25","guid":{"rendered":"https:\/\/server.hk\/cnblog\/121182\/"},"modified":"2024-10-25T11:13:26","modified_gmt":"2024-10-25T03:13:26","slug":"redis-%e6%a5%b5%e9%80%9f%e9%80%b2%e9%9a%8e%e5%bf%ab%e9%80%9f%e9%83%a8%e7%bd%b2%e7%94%9f%e7%94%a2%e7%92%b0%e5%a2%83%e6%94%bb%e7%95%a5","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/121182\/","title":{"rendered":"Redis \u6975\u901f\u9032\u968e\u5feb\u901f\u90e8\u7f72\u751f\u7522\u74b0\u5883\u653b\u7565"},"content":{"rendered":"<h1 id=\"redis-%e6%a5%b5%e9%80%9f%e9%80%b2%e9%9a%8e%e5%bf%ab%e9%80%9f%e9%83%a8%e7%bd%b2%e7%94%9f%e7%94%a2%e7%92%b0%e5%a2%83%e6%94%bb%e7%95%a5-vhvKBGygIJ\">Redis \u6975\u901f\u9032\u968e\u5feb\u901f\u90e8\u7f72\u751f\u7522\u74b0\u5883\u653b\u7565<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u4e16\u754c\u4e2d\uff0cRedis \u4f5c\u70ba\u4e00\u500b\u9ad8\u6548\u7684\u9375\u503c\u5b58\u5132\u7cfb\u7d71\uff0c\u5df2\u7d93\u6210\u70ba\u8a31\u591a\u61c9\u7528\u7a0b\u5e8f\u7684\u6838\u5fc3\u7d44\u4ef6\u3002\u7121\u8ad6\u662f\u7528\u65bc\u7de9\u5b58\u3001\u6d88\u606f\u968a\u5217\u9084\u662f\u6578\u64da\u6301\u4e45\u5316\uff0cRedis \u90fd\u80fd\u63d0\u4f9b\u5353\u8d8a\u7684\u6027\u80fd\u548c\u9748\u6d3b\u6027\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u5982\u4f55\u5feb\u901f\u90e8\u7f72 Redis \u751f\u7522\u74b0\u5883\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u6700\u4f73\u5be6\u8e10\u548c\u914d\u7f6e\u5efa\u8b70\u3002<\/p>\n<h2 id=\"1-redis-%e7%b0%a1%e4%bb%8b-vhvKBGygIJ\">1. Redis \u7c21\u4ecb<\/h2>\n<p>Redis\uff08REmote DIctionary Server\uff09\u662f\u4e00\u500b\u958b\u6e90\u7684\u5167\u5b58\u6578\u64da\u7d50\u69cb\u5b58\u5132\u7cfb\u7d71\uff0c\u652f\u6301\u591a\u7a2e\u6578\u64da\u7d50\u69cb\uff0c\u5982\u5b57\u7b26\u4e32\u3001\u54c8\u5e0c\u3001\u5217\u8868\u3001\u96c6\u5408\u7b49\u3002\u5b83\u7684\u9ad8\u6027\u80fd\u4f7f\u5176\u6210\u70ba\u8a31\u591a\u9ad8\u6d41\u91cf\u7db2\u7ad9\u548c\u61c9\u7528\u7a0b\u5e8f\u7684\u9996\u9078\u3002Redis \u7684\u4e3b\u8981\u7279\u9ede\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u9ad8\u6027\u80fd\uff1a\u80fd\u5920\u6bcf\u79d2\u8655\u7406\u6578\u5341\u842c\u6b21\u8b80\u5beb\u64cd\u4f5c\u3002<\/li>\n<li>\u6301\u4e45\u5316\uff1a\u652f\u6301 RDB \u548c AOF \u5169\u7a2e\u6301\u4e45\u5316\u65b9\u5f0f\u3002<\/li>\n<li>\u5206\u4f48\u5f0f\uff1a\u652f\u6301\u4e3b\u5f9e\u8907\u88fd\u548c\u5206\u7247\u3002<\/li>\n<li>\u8c50\u5bcc\u7684\u6578\u64da\u7d50\u69cb\uff1a\u652f\u6301\u591a\u7a2e\u6578\u64da\u985e\u578b\uff0c\u9748\u6d3b\u6027\u9ad8\u3002<\/li>\n<\/ul>\n<h2 id=\"2-%e7%92%b0%e5%a2%83%e6%ba%96%e5%82%99-vhvKBGygIJ\">2. \u74b0\u5883\u6e96\u5099<\/h2>\n<p>\u5728\u90e8\u7f72 Redis \u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u6e96\u5099\u597d\u4f3a\u670d\u5668\u74b0\u5883\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u57fa\u672c\u6b65\u9a5f\uff1a<\/p>\n<ul>\n<li>\u9078\u64c7\u5408\u9069\u7684\u4f3a\u670d\u5668\uff1a\u6839\u64da\u9810\u671f\u7684\u6d41\u91cf\u548c\u6578\u64da\u91cf\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u6216\u96f2\u4f3a\u670d\u5668\u3002<\/li>\n<li>\u5b89\u88dd\u64cd\u4f5c\u7cfb\u7d71\uff1a\u5efa\u8b70\u4f7f\u7528 Ubuntu \u6216 CentOS\uff0c\u56e0\u70ba\u9019\u4e9b\u7cfb\u7d71\u5c0d Redis \u7684\u652f\u6301\u8f03\u597d\u3002<\/li>\n<li>\u66f4\u65b0\u7cfb\u7d71\uff1a\u78ba\u4fdd\u7cfb\u7d71\u662f\u6700\u65b0\u7684\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u66f4\u65b0\uff1a<\/li>\n<\/ul>\n<pre><code>sudo apt update &amp;&amp; sudo apt upgrade -y<\/code><\/pre>\n<h2 id=\"3-%e5%ae%89%e8%a3%9d-redis-vhvKBGygIJ\">3. \u5b89\u88dd Redis<\/h2>\n<p>\u5b89\u88dd Redis \u7684\u904e\u7a0b\u76f8\u5c0d\u7c21\u55ae\u3002\u4ee5\u4e0b\u662f\u5b89\u88dd\u6b65\u9a5f\uff1a<\/p>\n<ul>\n<li>\u5b89\u88dd\u4f9d\u8cf4\u5305\uff1a<\/li>\n<\/ul>\n<pre><code>sudo apt install build-essential tcl<\/code><\/pre>\n<ul>\n<li>\u4e0b\u8f09 Redis \u6e90\u78bc\uff1a<\/li>\n<\/ul>\n<pre><code>curl -O http:\/\/download.redis.io\/redis-stable.tar.gz<\/code><\/pre>\n<ul>\n<li>\u89e3\u58d3\u4e26\u7de8\u8b6f\uff1a<\/li>\n<\/ul>\n<pre><code>tar xzvf redis-stable.tar.gz\ncd redis-stable\nmake<\/code><\/pre>\n<ul>\n<li>\u904b\u884c\u6e2c\u8a66\uff1a<\/li>\n<\/ul>\n<pre><code>make test<\/code><\/pre>\n<ul>\n<li>\u5b89\u88dd Redis\uff1a<\/li>\n<\/ul>\n<pre><code>sudo make install<\/code><\/pre>\n<h2 id=\"4-%e9%85%8d%e7%bd%ae-redis-vhvKBGygIJ\">4. \u914d\u7f6e Redis<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u9700\u8981\u9032\u884c\u4e00\u4e9b\u57fa\u672c\u914d\u7f6e\u3002Redis \u7684\u914d\u7f6e\u6587\u4ef6\u901a\u5e38\u4f4d\u65bc \/etc\/redis\/redis.conf\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u91cd\u8981\u7684\u914d\u7f6e\u9805\uff1a<\/p>\n<ul>\n<li><strong>daemonize<\/strong>: \u5c07\u5176\u8a2d\u7f6e\u70ba yes\uff0c\u4ee5\u4fbf Redis \u5728\u5f8c\u53f0\u904b\u884c\u3002<\/li>\n<li><strong>supervised<\/strong>: \u6839\u64da\u7cfb\u7d71\u9078\u64c7 systemd \u6216\u5176\u4ed6\u9078\u9805\u3002<\/li>\n<li><strong>bind<\/strong>: \u8a2d\u7f6e\u5141\u8a31\u8a2a\u554f\u7684 IP \u5730\u5740\uff0c\u5efa\u8b70\u53ea\u5141\u8a31\u5167\u90e8\u7db2\u7d61\u3002<\/li>\n<li><strong>requirepass<\/strong>: \u8a2d\u7f6e\u5bc6\u78bc\u4ee5\u589e\u5f37\u5b89\u5168\u6027\u3002<\/li>\n<\/ul>\n<h2 id=\"5-%e5%95%9f%e5%8b%95-redis-%e6%9c%8d%e5%8b%99-vhvKBGygIJ\">5. \u555f\u52d5 Redis \u670d\u52d9<\/h2>\n<p>\u914d\u7f6e\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5 Redis \u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl start redis.service<\/code><\/pre>\n<p>\u8981\u6aa2\u67e5 Redis \u662f\u5426\u6b63\u5e38\u904b\u884c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>redis-cli ping<\/code><\/pre>\n<p>\u5982\u679c\u8fd4\u56de PONG\uff0c\u5247\u8868\u793a Redis \u6b63\u5728\u6b63\u5e38\u904b\u884c\u3002<\/p>\n<h2 id=\"6-%e7%9b%a3%e6%8e%a7%e8%88%87%e7%b6%ad%e8%ad%b7-vhvKBGygIJ\">6. \u76e3\u63a7\u8207\u7dad\u8b77<\/h2>\n<p>\u5728\u751f\u7522\u74b0\u5883\u4e2d\uff0c\u76e3\u63a7 Redis \u7684\u6027\u80fd\u548c\u5065\u5eb7\u72c0\u614b\u81f3\u95dc\u91cd\u8981\u3002\u53ef\u4ee5\u4f7f\u7528 Redis \u63d0\u4f9b\u7684\u547d\u4ee4\u4f86\u6aa2\u67e5\u72c0\u614b\uff1a<\/p>\n<pre><code>redis-cli info<\/code><\/pre>\n<p>\u6b64\u5916\uff0c\u5efa\u8b70\u5b9a\u671f\u5099\u4efd\u6578\u64da\uff0c\u4e26\u6839\u64da\u9700\u8981\u8abf\u6574\u914d\u7f6e\u4ee5\u61c9\u5c0d\u6d41\u91cf\u8b8a\u5316\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-vhvKBGygIJ\">\u7e3d\u7d50<\/h2>\n<p>Redis \u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u80fd\u5920\u986f\u8457\u63d0\u9ad8\u61c9\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u3002\u901a\u904e\u4e0a\u8ff0\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u5feb\u901f\u90e8\u7f72\u4e00\u500b\u7a69\u5b9a\u7684 Redis \u751f\u7522\u74b0\u5883\u3002\u7121\u8ad6\u662f\u9078\u64c7 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u4f3a\u670d\u5668\uff0c\u78ba\u4fdd\u60a8\u7684\u74b0\u5883\u80fd\u5920\u652f\u6301 Redis \u7684\u9ad8\u6548\u904b\u884c\uff0c\u4e26\u6839\u64da\u5be6\u969b\u9700\u6c42\u9032\u884c\u8abf\u6574\u548c\u512a\u5316\u3002\u5e0c\u671b\u9019\u7bc7\u6587\u7ae0\u80fd\u5e6b\u52a9\u60a8\u9806\u5229\u90e8\u7f72 Redis\uff0c\u63d0\u5347\u60a8\u7684\u61c9\u7528\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u638c\u63e1Redis\u6975\u901f\u9032\u968e\u6280\u5de7\uff0c\u5feb\u901f\u90e8\u7f72\u751f\u7522\u74b0\u5883\uff0c\u63d0\u5347\u6027\u80fd\u8207\u7a69\u5b9a\u6027\uff0c\u52a9\u4f60\u8f15\u9b06\u61c9\u5c0d\u9ad8\u6d41\u91cf\u6311\u6230\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-121182","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/121182","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"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=121182"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/121182\/revisions"}],"predecessor-version":[{"id":121183,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/121182\/revisions\/121183"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=121182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=121182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=121182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}