{"id":201419,"date":"2025-05-10T11:27:17","date_gmt":"2025-05-10T03:27:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201419\/"},"modified":"2025-05-10T11:27:17","modified_gmt":"2025-05-10T03:27:17","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8centos-7%e4%b8%8a%e5%ae%89%e8%a3%85redis%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201419\/","title":{"rendered":"\u5982\u4f55\u5728CentOS 7\u4e0a\u5b89\u88c5Redis\u670d\u52a1\u5668"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u5728CentOS 7\u4e0a\u5b89\u88c5Redis\u670d\u52a1\u5668<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u672c\u7bc7\u6587\u7ae0\u4e3b\u8981\u662f\u7ed3\u5408\u6211\u4e4b\u524d\u9762\u8bd5\u7684\u5404\u79cd\u7ecf\u5386\u548c\u5b9e\u6218\u5f00\u53d1\u4e2d\u9047\u5230\u7684\u95ee\u9898\u89e3\u51b3\u7ecf\u9a8c\u6574\u7406\u7684\uff0c\u5e0c\u671b\u8fd9\u7bc7\u300a\u5982\u4f55\u5728CentOS 7\u4e0a\u5b89\u88c5Redis\u670d\u52a1\u5668\u300b\u5bf9\u4f60\u6709\u5f88\u5927\u5e2e\u52a9\uff01\u6b22\u8fce\u6536\u85cf\uff0c\u5206\u4eab\u7ed9\u66f4\u591a\u7684\u9700\u8981\u7684\u670b\u53cb\u5b66\u4e60~<\/p>\n<p>&nbsp;\u3000\u3000\u5927\u5bb6\u597d\uff0c\u672c\u6587\u7684\u4e3b\u9898\u662f Redis\uff0c\u6211\u4eec\u5c06\u8981\u5728 CentOS 7 \u4e0a\u5b89\u88c5\u5b83\u3002\u7f16\u8bd1\u6e90\u4ee3\u7801\uff0c\u5b89\u88c5\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u521b\u5efa\u3001\u5b89\u88c5\u6587\u4ef6\u3002\u5728\u5b89\u88c5\u4e86\u5b83\u7684\u7ec4\u4ef6\u4e4b\u540e\uff0c\u6211\u4eec\u8fd8\u4f1a\u914d\u7f6e redis \uff0c\u5c31\u50cf\u914d\u7f6e\u64cd\u4f5c\u7cfb\u7edf\u53c2\u6570\u4e00\u6837\uff0c\u76ee\u6807\u5c31\u662f\u8ba9 redis \u8fd0\u884c\u7684\u66f4\u52a0\u53ef\u9760\u548c\u5feb\u901f\u3002<\/p>\n<\/p>\n<p>\u3000\u3000Redis \u670d\u52a1\u5668<\/p>\n<p>\u3000\u3000Redis \u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u591a\u5e73\u53f0\u6570\u636e\u5b58\u50a8\u8f6f\u4ef6\uff0c\u4f7f\u7528 ANSI C \u7f16\u5199\uff0c\u76f4\u63a5\u5728\u5185\u5b58\u4f7f\u7528\u6570\u636e\u96c6\uff0c\u8fd9\u4f7f\u5f97\u5b83\u5f97\u4ee5\u5b9e\u73b0\u975e\u5e38\u9ad8\u7684\u6548\u7387\u3002Redis \u652f\u6301\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\uff0c\u5305\u62ec Lua, C, Java, Python, Perl, PHP \u548c\u5176\u4ed6\u5f88\u591a\u8bed\u8a00\u3002redis \u7684\u4ee3\u7801\u91cf\u5f88\u5c0f\uff0c\u53ea\u6709\u7ea63\u4e07\u884c\uff0c\u5b83\u53ea\u505a\u201c\u5f88\u5c11\u201d\u7684\u4e8b\uff0c\u4f46\u662f\u505a\u7684\u5f88\u597d\u3002\u5c3d\u7ba1\u662f\u5728\u5185\u5b58\u91cc\u5de5\u4f5c\uff0c\u4f46\u662f\u6570\u636e\u6301\u4e45\u5316\u7684\u4fdd\u5b58\u8fd8\u662f\u6709\u7684\uff0c\u800credis \u7684\u53ef\u9760\u6027\u5c31\u5f88\u9ad8\uff0c\u540c\u65f6\u4e5f\u652f\u6301\u96c6\u7fa4\uff0c\u8fd9\u4e9b\u53ef\u4ee5\u5f88\u597d\u7684\u4fdd\u8bc1\u4f60\u7684\u6570\u636e\u5b89\u5168\u3002<\/p>\n<p>\u3000\u3000<strong>\u6784\u5efa Redis<\/strong><\/p>\n<p>\u3000\u3000redis \u76ee\u524d\u6ca1\u6709\u5b98\u65b9 RPM \u5b89\u88c5\u5305\uff0c\u6211\u4eec\u9700\u8981\u4ece\u6e90\u4ee3\u7801\u7f16\u8bd1\uff0c\u800c\u4e3a\u4e86\u8981\u7f16\u8bd1\u5c31\u9700\u8981\u5b89\u88c5 Make \u548c GCC\u3002<\/p>\n<p>\u3000\u3000\u5982\u679c\u6ca1\u6709\u5b89\u88c5\u8fc7 GCC \u548c Make\uff0c\u90a3\u4e48\u5c31\u4f7f\u7528 yum \u5b89\u88c5\u3002<\/p>\n<\/p>\n<pre>yum&nbsp;install&nbsp;gcc&nbsp;make&nbsp;\r\n<\/pre>\n<p>\u3000\u3000\u4ece\u5b98\u7f51\u4e0b\u8f7d tar \u538b\u7f29\u5305\u3002<\/p>\n<\/p>\n<pre>curl&nbsp;http:\/\/download.redis.io\/releases\/redis-3.0.4.tar.gz&nbsp;-o&nbsp;redis-3.0.4.tar.gz&nbsp;\r\n<\/pre>\n<p>\u3000\u3000\u89e3\u538b\u7f29\u3002<\/p>\n<\/p>\n<pre>tar&nbsp;zxvf&nbsp;redis-3.0.4.tar.gz&nbsp;\r\n<\/pre>\n<p>\u3000\u3000\u8fdb\u5165\u89e3\u538b\u540e\u7684\u76ee\u5f55\u3002<\/p>\n<\/p>\n<pre>cd&nbsp;redis-3.0.4&nbsp;\r\n<\/pre>\n<p>\u3000\u3000\u4f7f\u7528Make \u7f16\u8bd1\u6e90\u6587\u4ef6\u3002<\/p>\n<\/p>\n<pre>make&nbsp;\r\n<\/pre>\n<p>\u3000\u3000<strong>\u5b89\u88c5<\/strong><\/p>\n<p>\u3000\u3000\u8fdb\u5165\u6e90\u6587\u4ef6\u7684\u76ee\u5f55\u3002<\/p>\n<\/p>\n<pre>make&nbsp;\r\n<\/pre>\n<p>\u3000\u3000\u590d\u5236 Redis \u7684\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u5230 \/usr\/local\/bin\u3002<\/p>\n<\/p>\n<pre>cp&nbsp;redis-server&nbsp;redis-cli&nbsp;\/usr\/local\/bin&nbsp;\r\n<\/pre>\n<p>\u3000\u3000***\u4e5f\u628a sentinel\uff0cbenchmark \u548c check \u590d\u5236\u8fc7\u53bb\u3002<\/p>\n<\/p>\n<pre>cp&nbsp;redis-sentinel&nbsp;redis-benchmark&nbsp;redis-check-aof&nbsp;redis-check-dump&nbsp;\/usr\/local\/bin&nbsp;\r\n<\/pre>\n<p>\u3000\u3000\u521b\u5efaredis \u914d\u7f6e\u6587\u4ef6\u5939\u3002<\/p>\n<\/p>\n<pre>mkdir&nbsp;\/etc\/redis&nbsp;\r\n<\/pre>\n<p>\u3000\u3000\u5728\/var\/lib\/redis \u4e0b\u521b\u5efa\u6709\u6548\u7684\u4fdd\u5b58\u6570\u636e\u7684\u76ee\u5f55\u3002<\/p>\n<\/p>\n<pre>mkdir&nbsp;-p&nbsp;\/var\/lib\/redis\/6379&nbsp;\r\n<\/pre>\n<p>\u3000\u3000<strong>\u7cfb\u7edf\u53c2\u6570<\/strong><\/p>\n<p>\u3000\u3000\u4e3a\u4e86\u8ba9 redis \u6b63\u5e38\u5de5\u4f5c\u9700\u8981\u914d\u7f6e\u4e00\u4e9b\u5185\u6838\u53c2\u6570\u3002<\/p>\n<p>\u3000\u3000\u914d\u7f6e vm.overcommit_memory \u4e3a1\uff0c\u8fd9\u53ef\u4ee5\u907f\u514d\u6570\u636e\u88ab\u622a\u65ad\uff0c\u8be6\u60c5\u3002<\/p>\n<\/p>\n<pre>sysctl&nbsp;-w&nbsp;vm.overcommit_memory=1&nbsp;\r\n<\/pre>\n<p>\u3000\u3000\u4fee\u6539 backlog \u8fde\u63a5\u6570\u7684***\u503c\u8d85\u8fc7 redis.conf \u4e2d\u7684 tcp-backlog \u503c\uff0c\u5373\u9ed8\u8ba4\u503c511\u3002\u4f60\u53ef\u4ee5\u5728 \u627e\u5230\u66f4\u591a\u6709\u5173\u57fa\u4e8e sysctl \u7684 ip \u7f51\u7edc\u96a7\u9053\u7684\u4fe1\u606f\u3002<\/p>\n<\/p>\n<pre>sysctl&nbsp;-w&nbsp;net.core.somaxconn=512&nbsp;\r\n<\/pre>\n<p>\u3000\u3000\u53d6\u6d88\u5bf9\u900f\u660e\u5de8\u9875\u5185\u5b58(transparent huge pages)\u7684\u652f\u6301\uff0c\u56e0\u4e3a\u8fd9\u4f1a\u9020\u6210 redis \u4f7f\u7528\u8fc7\u7a0b\u4ea7\u751f\u5ef6\u65f6\u548c\u5185\u5b58\u8bbf\u95ee\u95ee\u9898\u3002<\/p>\n<\/p>\n<pre>echo&nbsp;never&nbsp;&gt;&nbsp;\/sys\/kernel\/mm\/transparent_hugepage\/enabled&nbsp;\r\n<\/pre>\n<p>\u3000\u3000<strong>redis.conf<\/strong><\/p>\n<p>\u3000\u3000redis.conf \u662f redis \u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u7136\u800c\u4f60\u4f1a\u770b\u5230\u8fd9\u4e2a\u6587\u4ef6\u7684\u540d\u5b57\u662f 6379.conf \uff0c\u800c\u8fd9\u4e2a\u6570\u5b57\u5c31\u662f redis \u76d1\u542c\u7684\u7f51\u7edc\u7aef\u53e3\u3002\u5982\u679c\u4f60\u60f3\u8981\u8fd0\u884c\u8d85\u8fc7\u4e00\u4e2a\u7684 redis \u5b9e\u4f8b\uff0c\u63a8\u8350\u7528\u8fd9\u6837\u7684\u540d\u5b57\u3002<\/p>\n<p>\u3000\u3000\u590d\u5236\u793a\u4f8b\u7684 redis.conf \u5230 \/etc\/redis\/6379.conf\u3002<\/p>\n<\/p>\n<pre>echo&nbsp;never&nbsp;&gt;&nbsp;\/sys\/kernel\/mm\/transparent_hugepage\/enabled&nbsp;\r\n<\/pre>\n<p>\u3000\u3000\u73b0\u5728\u7f16\u8f91\u8fd9\u4e2a\u6587\u4ef6\u5e76\u4e14\u914d\u7f6e\u53c2\u6570\u3002<\/p>\n<\/p>\n<pre>vi&nbsp;\/etc\/redis\/6379.conf&nbsp;\r\n<\/pre>\n<p>\u3000\u3000<strong>daemonize<\/strong><\/p>\n<p>\u3000\u3000\u8bbe\u7f6e daemonize \u4e3a no\uff0csystemd \u9700\u8981\u5b83\u8fd0\u884c\u5728\u524d\u53f0\uff0c\u5426\u5219 redis \u4f1a\u7a81\u7136\u6302\u6389\u3002<\/p>\n<\/p>\n<pre>vi&nbsp;\/etc\/redis\/6379.conf&nbsp;\r\n<\/pre>\n<p>\u3000\u3000<strong>pidfile<\/strong><\/p>\n<p>\u3000\u3000\u8bbe\u7f6e pidfile \u4e3a \/var\/run\/redis_6379.pid\u3002<\/p>\n<\/p>\n<pre>vi&nbsp;\/etc\/redis\/6379.conf&nbsp;\r\n<\/pre>\n<p>\u3000\u3000<strong>port<\/strong><\/p>\n<p>\u3000\u3000\u5982\u679c\u4e0d\u51c6\u5907\u7528\u9ed8\u8ba4\u7aef\u53e3\uff0c\u53ef\u4ee5\u4fee\u6539\u3002<\/p>\n<\/p>\n<pre>port&nbsp;6379&nbsp;\r\n<\/pre>\n<p>\u3000\u3000<strong>loglevel<\/strong><\/p>\n<p>\u3000\u3000\u8bbe\u7f6e\u65e5\u5fd7\u7ea7\u522b\u3002<\/p>\n<\/p>\n<pre>port&nbsp;6379&nbsp;\r\n<\/pre>\n<p>\u3000\u3000#p#<\/p>\n<p><strong>logfile<\/strong><\/p>\n<p>\u3000\u3000\u4fee\u6539\u65e5\u5fd7\u6587\u4ef6\u8def\u5f84\u3002<\/p>\n<\/p>\n<pre>logfile&nbsp;\/var\/log\/redis_6379.log&nbsp;\r\n<\/pre>\n<p>\u3000\u3000<strong>dir<\/strong><\/p>\n<p>\u3000\u3000\u8bbe\u7f6e\u76ee\u5f55\u4e3a \/var\/lib\/redis\/6379<\/p>\n<\/p>\n<pre>dir&nbsp;\/var\/lib\/redis\/6379&nbsp;\r\n<\/pre>\n<p>\u3000\u3000<strong>\u5b89\u5168<\/strong><\/p>\n<p>\u3000\u3000\u4e0b\u9762\u6709\u51e0\u4e2a\u53ef\u4ee5\u63d0\u9ad8\u5b89\u5168\u6027\u7684\u64cd\u4f5c\u3002<\/p>\n<p>\u3000\u3000<strong>Unix sockets<\/strong><\/p>\n<p>\u3000\u3000\u5728\u5f88\u591a\u60c5\u51b5\u4e0b\uff0c\u5ba2\u6237\u7aef\u7a0b\u5e8f\u548c\u670d\u52a1\u5668\u7aef\u7a0b\u5e8f\u8fd0\u884c\u5728\u540c\u4e00\u4e2a\u673a\u5668\u4e0a\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u76d1\u542c\u7f51\u7edc\u4e0a\u7684 socket\u3002\u5982\u679c\u8fd9\u548c\u4f60\u7684\u4f7f\u7528\u60c5\u51b5\u7c7b\u4f3c\uff0c\u4f60\u5c31\u53ef\u4ee5\u4f7f\u7528 unix socket \u66ff\u4ee3\u7f51\u7edc socket\uff0c\u4e3a\u6b64\u4f60\u9700\u8981\u914d\u7f6e port \u4e3a0\uff0c\u7136\u540e\u914d\u7f6e\u4e0b\u9762\u7684\u9009\u9879\u6765\u542f\u7528 unix socket\u3002<\/p>\n<p>\u3000\u3000\u8bbe\u7f6e unix socket \u7684\u5957\u63a5\u5b57\u6587\u4ef6\u3002<\/p>\n<\/p>\n<pre>unixsocket&nbsp;\/tmp\/redis.sock&nbsp;\r\n<\/pre>\n<p>\u3000\u3000\u9650\u5236 socket \u6587\u4ef6\u7684\u6743\u9650\u3002<\/p>\n<\/p>\n<pre>unixsocketperm&nbsp;700&nbsp;\r\n<\/pre>\n<p>\u3000\u3000\u73b0\u5728\u4e3a\u4e86\u8ba9 redis-cli \u53ef\u4ee5\u8bbf\u95ee\uff0c\u5e94\u8be5\u4f7f\u7528 -s \u53c2\u6570\u6307\u5411\u8be5 socket \u6587\u4ef6\u3002<\/p>\n<\/p>\n<pre>redis-cli&nbsp;-s&nbsp;\/tmp\/redis.sock&nbsp;\r\n<\/pre>\n<p>\u3000\u3000<strong>requirepass<\/strong><\/p>\n<p>\u3000\u3000\u4f60\u53ef\u80fd\u9700\u8981\u8fdc\u7a0b\u8bbf\u95ee\uff0c\u5982\u679c\u662f\uff0c\u90a3\u4e48\u4f60\u5e94\u8be5\u8bbe\u7f6e\u5bc6\u7801\uff0c\u8fd9\u6837\u5b50\u6bcf\u6b21\u64cd\u4f5c\u4e4b\u524d\u8981\u6c42\u8f93\u5165\u5bc6\u7801\u3002<\/p>\n<\/p>\n<pre>requirepass&nbsp;\"bTFBx1NYYWRMTUEyNHhsCg\"&nbsp;\r\n<\/pre>\n<p>\u3000\u3000<strong>rename-command<\/strong><\/p>\n<p>\u3000\u3000\u60f3\u8c61\u4e00\u4e0b\u5982\u4e0b\u6307\u4ee4\u7684\u8f93\u51fa\u3002\u662f\u7684\uff0c\u8fd9\u4f1a\u8f93\u51fa\u670d\u52a1\u5668\u7684\u914d\u7f6e\uff0c\u6240\u4ee5\u4f60\u5e94\u8be5\u5728\u4efb\u4f55\u53ef\u80fd\u7684\u60c5\u51b5\u4e0b\u62d2\u7edd\u8fd9\u79cd\u8bbf\u95ee\u3002<\/p>\n<\/p>\n<pre>CONFIG&nbsp;GET&nbsp;*&nbsp;\r\n<\/pre>\n<p>\u3000\u3000\u4e3a\u4e86\u9650\u5236\u751a\u81f3\u7981\u6b62\u8fd9\u6761\u6216\u8005\u5176\u4ed6\u6307\u4ee4\uff0c\u53ef\u4ee5\u4f7f\u7528 rename-command \u547d\u4ee4\u3002\u4f60\u5fc5\u987b\u63d0\u4f9b\u4e00\u4e2a\u547d\u4ee4\u540d\u548c\u66ff\u4ee3\u7684\u540d\u5b57\u3002\u8981\u7981\u6b62\u7684\u8bdd\uff0c\u9700\u8981\u8bbe\u7f6e\u66ff\u4ee3\u7684\u540d\u5b57\u4e3a\u7a7a\u5b57\u7b26\u4e32\uff0c\u8fd9\u6837\u7981\u6b62\u4efb\u4f55\u4eba\u731c\u6d4b\u547d\u4ee4\u7684\u540d\u5b57\u4f1a\u6bd4\u8f83\u5b89\u5168\u3002<\/p>\n<\/p>\n<pre>rename-command&nbsp;FLUSHDB&nbsp;\"FLUSHDB_MY_SALT_G0ES_HERE09u09u\"&nbsp;\r\nrename-command&nbsp;FLUSHALL&nbsp;\"\"&nbsp;\r\nrename-command&nbsp;CONFIG&nbsp;\"CONFIG_MY_S4LT_GO3S_HERE09u09u\"&nbsp;\r\n<\/pre>\n<\/p>\n<p>\u3000\u3000\u4f7f\u7528\u5bc6\u7801\u901a\u8fc7 unix socket \u8bbf\u95ee\uff0c\u548c\u4fee\u6539\u547d\u4ee4<\/p>\n<p>\u3000\u3000<strong>\u5feb\u7167<\/strong><\/p>\n<p>\u3000\u3000\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0credis \u4f1a\u5468\u671f\u6027\u7684\u5c06\u6570\u636e\u96c6\u8f6c\u50a8\u5230\u6211\u4eec\u8bbe\u7f6e\u7684\u76ee\u5f55\u4e0b\u7684 dump.rdb \u6587\u4ef6\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 save \u547d\u4ee4\u914d\u7f6e\u8f6c\u50a8\u7684\u9891\u7387\uff0c\u5b83\u7684***\u4e2a\u53c2\u6570\u662f\u4ee5\u79d2\u4e3a\u5355\u4f4d\u7684\u65f6\u95f4\u5e27\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u5728\u6570\u636e\u6587\u4ef6\u4e0a\u8fdb\u884c\u4fee\u6539\u7684\u6570\u91cf\u3002<\/p>\n<p>\u3000\u3000\u6bcf\u969415\u5206\u949f\u5e76\u4e14\u6700\u5c11\u4fee\u6539\u8fc7\u4e00\u6b21\u952e\u3002<\/p>\n<\/p>\n<pre>save&nbsp;900&nbsp;1&nbsp;\r\n<\/pre>\n<p>\u3000\u3000\u6bcf\u96945\u5206\u949f\u5e76\u4e14\u6700\u5c11\u4fee\u6539\u8fc710\u6b21\u952e\u3002<\/p>\n<\/p>\n<pre>save&nbsp;300&nbsp;10&nbsp;\r\n<\/pre>\n<p>\u3000\u3000\u6bcf\u96941\u5206\u949f\u5e76\u4e14\u6700\u5c11\u4fee\u6539\u8fc710000\u6b21\u952e\u3002<\/p>\n<\/p>\n<pre>save&nbsp;60&nbsp;10000&nbsp;\r\n<\/pre>\n<p>\u3000\u3000\u6587\u4ef6 \/var\/lib\/redis\/6379\/dump.rdb \u5305\u542b\u4e86\u4ece\u4e0a\u6b21\u4fdd\u5b58\u4ee5\u6765\u5185\u5b58\u91cc\u6570\u636e\u96c6\u7684\u8f6c\u50a8\u6570\u636e\u3002\u56e0\u4e3a\u5b83\u5148\u521b\u5efa\u4e34\u65f6\u6587\u4ef6\uff0c\u7136\u540e\u66ff\u6362\u4e4b\u524d\u7684\u8f6c\u50a8\u6587\u4ef6\uff0c\u8fd9\u91cc\u4e0d\u5b58\u5728\u6570\u636e\u7834\u574f\u7684\u95ee\u9898\uff0c\u4f60\u4e0d\u7528\u62c5\u5fc3\uff0c\u53ef\u4ee5\u76f4\u63a5\u590d\u5236\u8fd9\u4e2a\u6587\u4ef6\u3002<\/p>\n<p>\u3000\u3000<strong>\u5f00\u673a\u65f6\u542f\u52a8<\/strong><\/p>\n<p>\u3000\u3000\u4f60\u53ef\u4ee5\u4f7f\u7528 systemd \u5c06 redis \u6dfb\u52a0\u5230\u7cfb\u7edf\u5f00\u673a\u542f\u52a8\u5217\u8868\u3002<\/p>\n<p>\u3000\u3000\u590d\u5236\u793a\u4f8b\u7684 init_script \u6587\u4ef6\u5230 \/etc\/init.d\uff0c\u6ce8\u610f\u811a\u672c\u540d\u6240\u4ee3\u8868\u7684\u7aef\u53e3\u53f7\u3002<\/p>\n<\/p>\n<pre>cp&nbsp;utils\/redis_init_script&nbsp;\/etc\/init.d\/redis_6379&nbsp;\r\n<\/pre>\n<p>\u3000\u3000\u73b0\u5728\u6211\u4eec\u8981\u4f7f\u7528 systemd\uff0c\u6240\u4ee5\u5728 \/etc\/systems\/system \u4e0b\u521b\u5efa\u4e00\u4e2a\u5355\u4f4d\u6587\u4ef6\u540d\u5b57\u4e3a redis_6379.service\u3002<\/p>\n<\/p>\n<pre>vi&nbsp;\/etc\/systemd\/system\/redis_6379.service&nbsp;\r\n<\/pre>\n<p>\u3000\u3000\u586b\u5199\u4e0b\u9762\u7684\u5185\u5bb9\uff0c\u8be6\u60c5\u53ef\u89c1 systemd.service\u3002\u3000\u3000<\/p>\n<\/p>\n<pre>[Unit]&nbsp;\r\nDescription=Redis&nbsp;on&nbsp;port&nbsp;6379&nbsp;\r\n[Service]&nbsp;\r\nType=forking&nbsp;\r\nExecStart=\/etc\/init.d\/redis_6379&nbsp;start&nbsp;\r\nExecStop=\/etc\/init.d\/redis_6379&nbsp;stop&nbsp;\r\n[Install]&nbsp;\r\nWantedBy=multi-user.target&nbsp;\r\n<\/pre>\n<p>\u3000\u3000\u73b0\u5728\uff0c\u6dfb\u52a0\u6211\u4e4b\u524d\u5728 \/etc\/sysctl.conf \u91cc\u9762\u4fee\u6539\u8fc7\u7684\u5185\u5b58\u8fc7\u91cf\u4f7f\u7528\u548c backlog ***\u503c\u7684\u9009\u9879\u3002<\/p>\n<\/p>\n<pre>vm.overcommit_memory&nbsp;=&nbsp;1&nbsp;\r\nnet.core.somaxconn=512&nbsp;\r\n<\/pre>\n<p>\u3000\u3000\u5bf9\u4e8e\u900f\u660e\u5de8\u9875\u5185\u5b58\u652f\u6301\uff0c\u5e76\u6ca1\u6709\u76f4\u63a5 sysctl \u547d\u4ee4\u53ef\u4ee5\u63a7\u5236\uff0c\u6240\u4ee5\u9700\u8981\u5c06\u4e0b\u9762\u7684\u547d\u4ee4\u653e\u5230 \/etc\/rc.local \u7684\u7ed3\u5c3e\u3002<\/p>\n<\/p>\n<pre>echo&nbsp;never&nbsp;&gt;&nbsp;\/sys\/kernel\/mm\/transparent_hugepage\/enabled&nbsp;\r\n<\/pre>\n<p>\u3000\u3000<strong>\u603b\u7ed3<\/strong><\/p>\n<p>\u3000\u3000\u8fd9\u6837\u5c31\u53ef\u4ee5\u542f\u52a8\u4e86\uff0c\u901a\u8fc7\u8bbe\u7f6e\u8fd9\u4e9b\u9009\u9879\u4f60\u5c31\u53ef\u4ee5\u90e8\u7f72 redis \u670d\u52a1\u5230\u5f88\u591a\u7b80\u5355\u7684\u573a\u666f\uff0c\u7136\u800c\u5728 redis.conf \u8fd8\u6709\u5f88\u591a\u4e3a\u590d\u6742\u73af\u5883\u51c6\u5907\u7684 redis \u9009\u9879\u3002\u5728\u4e00\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 \u548c \u6765\u63d0\u9ad8\u53ef\u7528\u6027\uff0c\u6216\u8005\u5728\u591a\u4e2a\u670d\u52a1\u5668\u4e0a\uff0c\u521b\u5efa\u670d\u52a1\u5668\u96c6\u7fa4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728CentOS 7\u4e0a\u5b89\u88c5Re&#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-201419","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201419","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=201419"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201419\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}