{"id":43266,"date":"2024-10-04T23:47:33","date_gmt":"2024-10-04T15:47:33","guid":{"rendered":"https:\/\/server.hk\/cnblog\/43266\/"},"modified":"2024-10-04T23:47:33","modified_gmt":"2024-10-04T15:47:33","slug":"centos-7-%e4%b8%8b-redis-%e7%9a%84%e5%ae%89%e8%a3%9d%e8%88%87%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/43266\/","title":{"rendered":"CentOS 7 \u4e0b Redis \u7684\u5b89\u88dd\u8207\u914d\u7f6e"},"content":{"rendered":"<h1 id=\"centos-7-%e4%b8%8b-redis-%e7%9a%84%e5%ae%89%e8%a3%9d%e8%88%87%e9%85%8d%e7%bd%ae-oAjnolQicR\">CentOS 7 \u4e0b Redis \u7684\u5b89\u88dd\u8207\u914d\u7f6e<\/h1>\n<p>Redis \u662f\u4e00\u6b3e\u9ad8\u6548\u80fd\u7684\u9375\u503c\u5b58\u5132\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u7de9\u5b58\u3001\u6d88\u606f\u968a\u5217\u548c\u6578\u64da\u6301\u4e45\u5316\u7b49\u5834\u666f\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 CentOS 7 \u7cfb\u7d71\u4e0a\u5b89\u88dd\u548c\u914d\u7f6e Redis\uff0c\u5e6b\u52a9\u7528\u6236\u5feb\u901f\u4e0a\u624b\u3002<\/p>\n<h2 id=\"%e4%b8%80%e3%80%81%e5%ae%89%e8%a3%9d%e5%89%8d%e7%9a%84%e6%ba%96%e5%82%99-oAjnolQicR\">\u4e00\u3001\u5b89\u88dd\u524d\u7684\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u5b89\u88dd Redis \u4e4b\u524d\uff0c\u8acb\u78ba\u4fdd\u60a8\u7684 CentOS 7 \u7cfb\u7d71\u5df2\u7d93\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u66f4\u65b0\uff1a<\/p>\n<pre><code>sudo yum update -y<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u5b89\u88dd\u4e00\u4e9b\u5fc5\u8981\u7684\u4f9d\u8cf4\u5305\uff0c\u9019\u4e9b\u5305\u5c07\u5e6b\u52a9\u60a8\u9806\u5229\u5b89\u88dd Redis\uff1a<\/p>\n<pre><code>sudo yum install gcc make -y<\/code><\/pre>\n<h2 id=\"%e4%ba%8c%e3%80%81%e5%ae%89%e8%a3%9d-redis-oAjnolQicR\">\u4e8c\u3001\u5b89\u88dd Redis<\/h2>\n<p>Redis \u7684\u5b89\u88dd\u53ef\u4ee5\u901a\u904e\u6e90\u78bc\u7de8\u8b6f\u6216\u4f7f\u7528\u9810\u7de8\u8b6f\u7684 RPM \u5305\u3002\u9019\u88e1\u6211\u5011\u5c07\u4f7f\u7528\u6e90\u78bc\u7de8\u8b6f\u7684\u65b9\u5f0f\u9032\u884c\u5b89\u88dd\u3002<\/p>\n<h3 id=\"1-%e4%b8%8b%e8%bc%89-redis-%e6%ba%90%e7%a2%bc-oAjnolQicR\">1. \u4e0b\u8f09 Redis \u6e90\u78bc<\/h3>\n<p>\u9996\u5148\uff0c\u524d\u5f80 Redis \u7684\u5b98\u65b9\u7db2\u7ad9\u4e0b\u8f09\u6700\u65b0\u7248\u672c\u7684\u6e90\u78bc\u5305\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528 wget \u547d\u4ee4\u4f86\u4e0b\u8f09\uff1a<\/p>\n<pre><code>wget http:\/\/download.redis.io\/releases\/redis-6.2.6.tar.gz<\/code><\/pre>\n<h3 id=\"2-%e8%a7%a3%e5%a3%93%e6%ba%90%e7%a2%bc%e5%8c%85-oAjnolQicR\">2. \u89e3\u58d3\u6e90\u78bc\u5305<\/h3>\n<p>\u4e0b\u8f09\u5b8c\u6210\u5f8c\uff0c\u4f7f\u7528 tar \u547d\u4ee4\u89e3\u58d3\u6e90\u78bc\u5305\uff1a<\/p>\n<pre><code>tar xzf redis-6.2.6.tar.gz<\/code><\/pre>\n<h3 id=\"3-%e7%b7%a8%e8%ad%af-redis-oAjnolQicR\">3. \u7de8\u8b6f Redis<\/h3>\n<p>\u9032\u5165\u89e3\u58d3\u5f8c\u7684\u76ee\u9304\uff0c\u7136\u5f8c\u57f7\u884c make \u547d\u4ee4\u9032\u884c\u7de8\u8b6f\uff1a<\/p>\n<pre><code>cd redis-6.2.6\nmake<\/code><\/pre>\n<p>\u7de8\u8b6f\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u5b89\u88dd Redis\uff1a<\/p>\n<pre><code>sudo make install<\/code><\/pre>\n<h2 id=\"%e4%b8%89%e3%80%81%e9%85%8d%e7%bd%ae-redis-oAjnolQicR\">\u4e09\u3001\u914d\u7f6e Redis<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u9700\u8981\u9032\u884c\u4e00\u4e9b\u57fa\u672c\u914d\u7f6e\u3002Redis \u7684\u914d\u7f6e\u6587\u4ef6\u4f4d\u65bc \/etc\/redis.conf\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528 vi \u6216 nano \u7de8\u8f2f\u5668\u4f86\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo vi \/etc\/redis.conf<\/code><\/pre>\n<h3 id=\"1-%e4%bf%ae%e6%94%b9%e5%ae%88%e8%ad%b7%e9%80%b2%e7%a8%8b%e8%a8%ad%e7%bd%ae-oAjnolQicR\">1. \u4fee\u6539\u5b88\u8b77\u9032\u7a0b\u8a2d\u7f6e<\/h3>\n<p>\u627e\u5230\u4ee5\u4e0b\u884c\uff0c\u5c07\u5176\u8a2d\u7f6e\u70ba yes\uff0c\u4ee5\u4fbf Redis \u5728\u5f8c\u53f0\u904b\u884c\uff1a<\/p>\n<pre><code>daemonize yes<\/code><\/pre>\n<h3 id=\"2-%e8%a8%ad%e7%bd%ae%e6%8c%81%e4%b9%85%e5%8c%96-oAjnolQicR\">2. \u8a2d\u7f6e\u6301\u4e45\u5316<\/h3>\n<p>Redis \u652f\u6301 RDB \u548c AOF \u5169\u7a2e\u6301\u4e45\u5316\u65b9\u5f0f\u3002\u60a8\u53ef\u4ee5\u6839\u64da\u9700\u6c42\u9078\u64c7\u5408\u9069\u7684\u65b9\u5f0f\u3002\u4ee5\u4e0b\u662f RDB \u7684\u914d\u7f6e\u793a\u4f8b\uff1a<\/p>\n<pre><code>save 900 1\nsave 300 10\nsave 60 10000<\/code><\/pre>\n<h3 id=\"3-%e8%a8%ad%e7%bd%ae%e5%af%86%e7%a2%bc%e4%bf%9d%e8%ad%b7-oAjnolQicR\">3. \u8a2d\u7f6e\u5bc6\u78bc\u4fdd\u8b77<\/h3>\n<p>\u70ba\u4e86\u63d0\u9ad8\u5b89\u5168\u6027\uff0c\u5efa\u8b70\u8a2d\u7f6e\u5bc6\u78bc\u3002\u627e\u5230\u4ee5\u4e0b\u884c\uff0c\u4e26\u53d6\u6d88\u8a3b\u91cb\uff0c\u7136\u5f8c\u8a2d\u7f6e\u60a8\u7684\u5bc6\u78bc\uff1a<\/p>\n<pre><code>requirepass yourpassword<\/code><\/pre>\n<h2 id=\"%e5%9b%9b%e3%80%81%e5%95%9f%e5%8b%95-redis-oAjnolQicR\">\u56db\u3001\u555f\u52d5 Redis<\/h2>\n<p>\u914d\u7f6e\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5 Redis \u670d\u52d9\uff1a<\/p>\n<pre><code>redis-server \/etc\/redis.conf<\/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=\"%e4%ba%94%e3%80%81%e8%a8%ad%e7%bd%ae%e9%96%8b%e6%a9%9f%e8%87%aa%e5%95%9f-oAjnolQicR\">\u4e94\u3001\u8a2d\u7f6e\u958b\u6a5f\u81ea\u555f<\/h2>\n<p>\u70ba\u4e86\u8b93 Redis \u5728\u7cfb\u7d71\u555f\u52d5\u6642\u81ea\u52d5\u555f\u52d5\uff0c\u60a8\u53ef\u4ee5\u5275\u5efa\u4e00\u500b systemd \u670d\u52d9\u55ae\u5143\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo vi \/etc\/systemd\/system\/redis.service<\/code><\/pre>\n<p>\u5728\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u5167\u5bb9\uff1a<\/p>\n<pre><code>[Unit]\nDescription=Redis In-Memory Data Store\nAfter=network.target\n\n[Service]\nExecStart=\/usr\/local\/bin\/redis-server \/etc\/redis.conf\nExecStop=\/usr\/local\/bin\/redis-cli shutdown\nRestart=always\n\n[Install]\nWantedBy=multi-user.target<\/code><\/pre>\n<p>\u4fdd\u5b58\u4e26\u9000\u51fa\u5f8c\uff0c\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\u555f\u7528\u4e26\u555f\u52d5 Redis \u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl enable redis\nsudo systemctl start redis<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-oAjnolQicR\">\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86\u5982\u4f55\u5728 CentOS 7 \u7cfb\u7d71\u4e0a\u5b89\u88dd\u548c\u914d\u7f6e Redis\u3002\u901a\u904e\u9019\u4e9b\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u8f15\u9b06\u5730\u5c07 Redis \u90e8\u7f72\u5230\u60a8\u7684\u4f3a\u670d\u5668\u4e0a\uff0c\u4e26\u6839\u64da\u9700\u6c42\u9032\u884c\u76f8\u61c9\u7684\u914d\u7f6e\u3002\u5982\u679c\u60a8\u9700\u8981\u66f4\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8003\u616e\u4f7f\u7528\u6211\u5011\u7684\u670d\u52d9\uff0c\u8b93\u60a8\u7684\u61c9\u7528\u904b\u884c\u5f97\u66f4\u52a0\u6d41\u66a2\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 CentOS 7 \u4e0a\u5b89\u88dd\u8207\u914d\u7f6e Redis\uff0c\u63d0\u5347\u6578\u64da\u5b58\u5132\u6548\u7387\uff0c\u7c21\u5316\u61c9\u7528\u958b\u767c\u904e\u7a0b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-43266","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43266","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=43266"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43266\/revisions"}],"predecessor-version":[{"id":43267,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43266\/revisions\/43267"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=43266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=43266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=43266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}