{"id":202316,"date":"2025-05-10T08:38:57","date_gmt":"2025-05-10T00:38:57","guid":{"rendered":"https:\/\/server.hk\/cnblog\/202316\/"},"modified":"2025-05-10T08:38:57","modified_gmt":"2025-05-10T00:38:57","slug":"centos7-8%e6%80%8e%e4%b9%88%e5%ae%89%e8%a3%85redis5-0-10","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/202316\/","title":{"rendered":"centos7.8\u600e\u4e48\u5b89\u88c5redis5.0.10"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>centos7.8\u600e\u4e48\u5b89\u88c5redis5.0.10<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>golang\u5b66\u4e60\u7f51\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300acentos7.8\u600e\u4e48\u5b89\u88c5redis5.0.10\u300b<\/span>\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u662f\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6570\u636e\u5e93<\/span>\u6216\u8005\u5df2\u7ecf\u662f\u5927\u4f6c\u7ea7\u522b\u4e86\uff0c\u90fd\u975e\u5e38\u6b22\u8fce\u4e5f\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u7ed9\u6211\u5efa\u8bae\u8bc4\u8bba\u54c8~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff01<\/p>\n<h2><strong>\u51c6\u5907<\/strong><\/h2>\n<ul>\n<li>\n<p>centos7.8\u670d\u52a1\u5668\u4e00\u53f0<\/p>\n<\/li>\n<\/ul>\n<h3>\u4fee\u6539\u4e3b\u673a\u540d<\/h3>\n<pre>#&nbsp;hostnamectl&nbsp;set-hostname&nbsp;redishost<\/pre>\n<h2>\u5b89\u88c5redis<\/h2>\n<h3>\u4e0b\u8f7dredis\u5b89\u88c5\u5305<\/h3>\n<pre>#&nbsp;cd&nbsp;\/opt\n#&nbsp;wget&nbsp;https:\/\/download.redis.io\/releases\/redis-5.0.10.tar.gz<\/pre>\n<h3>&nbsp;\u89e3\u538b\u538b\u7f29\u5305<\/h3>\n<pre>#&nbsp;cd&nbsp;\/opt\n#&nbsp;tar&nbsp;-zxf&nbsp;redis-5.0.10.tar.gz<\/pre>\n<h3>&nbsp;\u7f16\u8bd1\u5b89\u88c5<\/h3>\n<pre>#&nbsp;cd&nbsp;\/opt\n#&nbsp;cd&nbsp;redis-5.0.10\n##&nbsp;\u5b89\u88c5gcc\u7f16\u8bd1\u5668\n#&nbsp;yum&nbsp;install&nbsp;gcc\n#&nbsp;make&nbsp;MALLOC=libc\n#&nbsp;#&nbsp;make&nbsp;install\ncd&nbsp;src&nbsp;&amp;&amp;&nbsp;make&nbsp;install\nmake[1]:&nbsp;Entering&nbsp;directory&nbsp;`\/opt\/redis-5.0.10\/src'\n\n\nHint:&nbsp;It's&nbsp;a&nbsp;good&nbsp;idea&nbsp;to&nbsp;run&nbsp;'make&nbsp;test'&nbsp;;)\n\n\n&nbsp;&nbsp;&nbsp;&nbsp;INSTALL&nbsp;install\n&nbsp;&nbsp;&nbsp;&nbsp;INSTALL&nbsp;install\n&nbsp;&nbsp;&nbsp;&nbsp;INSTALL&nbsp;install\n&nbsp;&nbsp;&nbsp;&nbsp;INSTALL&nbsp;install\n&nbsp;&nbsp;&nbsp;&nbsp;INSTALL&nbsp;install\nmake[1]:&nbsp;Leaving&nbsp;directory&nbsp;`\/opt\/redis-5.0.10\/src<\/pre>\n<h3>\u4fee\u6539\u7cfb\u7edf\u53c2\u6570<\/h3>\n<pre>##&nbsp;\u4fee\u6539sysctl.conf\n#&nbsp;(\ncat&nbsp;&lt;&lt;EOF\nnet.core.somaxconn=1024\nvm.overcommit_memory=1\nEOF\n)&nbsp;&gt;&gt;&nbsp;\/etc\/sysctl.conf<\/pre>\n<p>\u4ee5\u4e0a\u64cd\u4f5c\u662f\u89e3\u51b3redis-server\u9ed8\u8ba4\u542f\u52a8\u63d0\u793a\u7684\u524d\u4e24\u4e2a\u8b66\u544a\u7684\u6301\u4e45\u65b9\u6848\uff0c\u9644redis-server\u9ed8\u8ba4\u542f\u52a8\u7684\u4e24\u4e2a\u8b66\u544a\u4fe1\u606f\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\n<p><strong>The TCP backlog setting of 511 cannot be enforced because \/proc\/sys\/net\/core\/somaxconn is set to the lower value of 128.<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add \u2018vm.overcommit_memory = 1\u2019 to\/etc\/sysctl.conf and&nbsp;then reboot&nbsp;or run the command \u2018sysctl vm.overcommit_memory=1\u2019 for this to take effect.<\/strong><\/p>\n<\/li>\n<\/ul>\n<h3>\u4fee\u6539\u7cfb\u7edf\u542f\u52a8\u53c2\u6570\u5173\u95edTCP<\/h3>\n<pre>##&nbsp;\u4fee\u6539\/etc\/default\/grub\n##&nbsp;\u5728\u6307\u5b9a\u884c\u52a0&nbsp;transparent_hugepage=never\n#&nbsp;vi&nbsp;\/etc\/default\/grub\nGRUB_TIMEOUT=5\nGRUB_DISTRIBUTOR=\"$(sed&nbsp;'s,&nbsp;release&nbsp;.*$,,g'&nbsp;\/etc\/system-release)\"\nGRUB_DEFAULT=saved\nGRUB_DISABLE_SUBMENU=true\nGRUB_TERMINAL_OUTPUT=\"console\"\nGRUB_CMDLINE_LINUX=\"crashkernel=auto&nbsp;rd.lvm.lv=centos\/root&nbsp;rd.lvm.lv=centos\/swap&nbsp;rhgb&nbsp;quiet&nbsp;transparent_hugepage=never\"\nGRUB_DISABLE_RECOVERY=\"true\"\n\n\n##&nbsp;\u91cd\u65b0\u751f\u6210grub\u914d\u7f6e\u6587\u4ef6\n#&nbsp;grub2-mkconfig&nbsp;-o&nbsp;\/boot\/grub2\/grub.cfg\nGenerating&nbsp;grub&nbsp;configuration&nbsp;file&nbsp;...\nFound&nbsp;linux&nbsp;image:&nbsp;\/boot\/vmlinuz-3.10.0-1127.el7.x86_64\nFound&nbsp;initrd&nbsp;image:&nbsp;\/boot\/initramfs-3.10.0-1127.el7.x86_64.img\nFound&nbsp;linux&nbsp;image:&nbsp;\/boot\/vmlinuz-0-rescue-385c7efe9475460c95c436866e593af3\nFound&nbsp;initrd&nbsp;image:&nbsp;\/boot\/initramfs-0-rescue-385c7efe9475460c95c436866e593af3.img\ndone<\/pre>\n<p>\u4ee5\u4e0a\u64cd\u4f5c\u662f\u89e3\u51b3redis-server\u9ed8\u8ba4\u542f\u52a8\u63d0\u793a\u7684\u7b2c\u4e09\u4e2a\u8b66\u544a\u7684\u6301\u4e45\u65b9\u6848\uff0c\u9644redis-server\u9ed8\u8ba4\u542f\u52a8\u7684\u7b2c\u4e09\u4e2a\u8b66\u544a\u4fe1\u606f\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\n<p><strong>you have Transparent Huge Pages (THP) support enabled in your kernel.&nbsp;This will create latency and memory usage issues with Redis.&nbsp;To fix thisissue run the&nbsp;command \u2018echo never &gt; \/sys\/kernel\/mm\/transparent_hugepage\/enabled\u2019 as root,&nbsp;and add it to your \/etc\/rc.local in order to retain thesetting after a reboot.&nbsp;Redis must be restarted after THP is disabled.<\/strong><\/p>\n<\/li>\n<\/ul>\n<p>\u6839\u636e\u63d0\u793a\u5c06\u2019echo never &gt; \/sys\/kernel\/mm\/transparent_hugepage\/enabled\u2019 \u5199\u5165\/etc\/rc.local \u5176\u5b9e\u5e76\u6ca1\u6709\u7528\uff0c\u6362\u6210\u4fee\u6539grub\u542f\u52a8\u6587\u4ef6\u53ef\u4ee5\u751f\u6548\u3002<\/p>\n<h3>\u4ee5\u540e\u53f0\u8fdb\u7a0b\u65b9\u5f0f\u542f\u52a8redis<\/h3>\n<h4>\u4fee\u6539\u914d\u7f6e\u6587\u4ef6redis.conf<\/h4>\n<pre>#&nbsp;cd&nbsp;\/opt\/redis-5.0.10\n#&nbsp;mkdir&nbsp;\/etc\/redis\n#&nbsp;cp&nbsp;redis.conf&nbsp;\/etc\/redis\/redis.conf<\/pre>\n<p>\u5728\/etc\/redis\/redis.conf\u4e2d\u4fee\u6539\u4ee5\u4e0b3\u9879<\/p>\n<ul>\n<li>\n<p><strong>\u4ee5\u540e\u53f0\u8fdb\u7a0b\u65b9\u5f0f\u542f\u52a8<\/strong><\/p>\n<\/li>\n<\/ul>\n<p><strong>\u4fee\u6539daemonize no \u4e3adaemonize yes<\/strong><\/p>\n<ul>\n<li>\n<p><strong>\u8bbe\u7f6eredis\u8fdc\u7a0b\u8fde\u63a5<\/strong><\/p>\n<\/li>\n<\/ul>\n<p><strong>\u6ce8\u91ca\u6389bind 127.0.0.1<\/strong><\/p>\n<ul>\n<li>\n<p><strong>\u8bbe\u7f6eredis\u8fde\u63a5\u5bc6\u7801<\/strong><\/p>\n<\/li>\n<\/ul>\n<p><strong>\u5728requirepass foobard\u6539\u4e3arequirepass&nbsp;redis1234<\/strong><\/p>\n<h4>\u8bbe\u7f6esystemctl\u542f\u52a8\u7a0b\u5e8f<\/h4>\n<p><em>\/usr\/lib\/systemd\/system\/redis.service<\/em><\/p>\n<pre>[Unit]\nDescription=Redis&nbsp;6379\nAfter=syslog.target&nbsp;network.target\n[Service]\nType=forking\nPrivateTmp=yes\nRestart=always\nExecStart=\/usr\/local\/bin\/redis-server&nbsp;\/etc\/redis\/redis.conf\nUser=root\nGroup=root\nLimitCORE=infinity\nLimitNOFILE=100000\nLimitNPROC=100000\n[Install]\nWantedBy=multi-user.target<\/pre>\n<h3>\u914d\u7f6e\u81ea\u52a8\u542f\u52a8<\/h3>\n<pre>systemctl&nbsp;daemon-reload&nbsp;&nbsp;\nsystemctl&nbsp;enable&nbsp;redis<\/pre>\n<h4>\u542f\u52a8\u547d\u4ee4<\/h4>\n<pre>systemctl&nbsp;enable&nbsp;redis&nbsp;\nsystemctl&nbsp;start&nbsp;redis\nsystemctl&nbsp;restart&nbsp;redis<\/pre>\n<p>{{o.name}}<\/p>\n<p>{{m.name}}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>centos7.8\u600e\u4e48\u5b89\u88c5red&#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-202316","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202316","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=202316"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202316\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=202316"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=202316"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=202316"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}