{"id":201133,"date":"2025-05-10T08:20:11","date_gmt":"2025-05-10T00:20:11","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201133\/"},"modified":"2025-05-10T08:20:11","modified_gmt":"2025-05-10T00:20:11","slug":"redis%e9%9b%86%e7%be%a4%e6%90%ad%e5%bb%ba_%e5%8a%a8%e5%8a%9b%e8%8a%82%e7%82%b9java%e5%ad%a6%e9%99%a2%e6%95%b4%e7%90%86","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201133\/","title":{"rendered":"redis\u96c6\u7fa4\u642d\u5efa_\u52a8\u529b\u8282\u70b9Java\u5b66\u9662\u6574\u7406"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>redis\u96c6\u7fa4\u642d\u5efa_\u52a8\u529b\u8282\u70b9Java\u5b66\u9662\u6574\u7406<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300aredis\u96c6\u7fa4\u642d\u5efa_\u52a8\u529b\u8282\u70b9Java\u5b66\u9662\u6574\u7406\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\u642d\u5efa\u3001redis\u96c6\u7fa4\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002<\/p>\n<p>\u73b0\u5728\u9879\u76ee\u4e0a\u7528redis\u7684\u8bdd\uff0c\u5f88\u5c11\u8bf4\u4e0d\u7528\u96c6\u7fa4\u7684\u60c5\u51b5\uff0c\u6bd5\u7adf\u5982\u679c\u751f\u4ea7\u4e0a\u53ea\u6709\u4e00\u53f0redis\u4f1a\u6709\u6781\u5927\u7684\u98ce\u9669\uff0c\u6bd4\u5982\u673a\u5668\u6302\u6389\uff0c\u6216\u8005\u5185\u5b58\u7206\u6389\uff0c\u5c31\u6bd4\u5982\u6211\u4eec\u751f\u4ea7\u73af\u5883\u66fe\u4eca\u4e5f\u906d\u9047\u5230\u8fd9\u79cd\u60c5\u51b5\uff0c\u5bfc\u81f4redis\u5185\u5b58\u4e0d\u591f\u6302\u6389\u7684\u60c5\u51b5\uff0c\u5f53\u7136\u8fd9\u4e9b\u90fd\u662f\u6211\u4eec\u53ca\u5176\u4e0d\u80fd\u5bb9\u5fcd\u7684\uff0c\u7b2c\u4e00\u4e2a\u5fc5\u987b\u8981\u505a\u5230\u9ad8\u53ef\u9760\uff0c\u5176\u6b21\u624d\u662f\u9ad8\u6027\u80fd\uff0c\u597d\u4e86\uff0c\u4e0b\u9762\u6211\u6765\u9010\u4e00\u642d\u5efa\u4e00\u4e0b\u3002<\/p>\n<p><span style=\"color: #ff0000\"><strong>\u4e00\uff1aRedis\u96c6\u7fa4\u642d\u5efa<\/strong><\/span><\/p>\n<p><strong>1. \u4e0b\u8f7d<\/strong><\/p>\n<p>\u9996\u5148\u53bb\u5b98\u7f51\u4e0b\u8f7d\u8f83\u65b0\u76843.2.0\u7248\u672c\uff0c\u4e0b\u8f7d\u65b9\u5f0f\u8fd8\u662f\u975e\u5e38\u7b80\u5355\u7684\uff0c\u6bd4\u5982\u5b98\u7f51\u4ecb\u7ecd\u7684\u8fd9\u6837\u3002<\/p>\n<pre>\n$ wget http:\/\/download.redis.io\/releases\/redis-3.2.0.tar.gz\n$ tar xzf redis-3.2.0.tar.gz\n$ cd redis-3.2.0\n$ make\n<\/pre>\n<p><strong>2. redis\u914d\u7f6e<\/strong><\/p>\n<p>\u7531\u4e8e\u6211\u4eec\u8981\u505a\u96c6\u7fa4\uff0c\u800c\u4e14\u8fd8\u8981redis\u81ea\u5e26\u7684redis-trib.rb \u80fd\u6b63\u5e38\u8fd0\u884c\uff0c\u6211\u4eec\u9700\u8981\u5728\u96c6\u7fa4\u4e2d\u5f00\u542f\u4e09\u53f0master\uff0c\u4e09\u53f0slave\uff0c\u6240\u4ee5\u8fd9\u91cc\u6211\u9700\u8981\u5efa\u7acb6\u4e2a\u6587\u4ef6\u5939\uff0c\u800c\u4e14\u6587\u4ef6\u5939\u7684\u540d\u79f0\u5c31\u4f7f\u7528\u7aef\u53e3\u5730\u5740\u7684\u540d\u5b57\uff0c\u6bd4\u5982\uff1a6389. 6380&#8230;.6384\u3002<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20221230\/167237280663ae62466b4f7.jpg\" style=\"max-width:100%\" class=\"aligncenter\"><\/p>\n<p><strong>3. config\u914d\u7f6e\u3002<\/strong><\/p>\n<p>\u73b0\u5728directory\u7684\u5206\u5e03\u60c5\u51b5\u5927\u81f4\u5982\u4e0a\u56fe\uff0c\u63a5\u4e0b\u6765\u8981\u505a\u7684\u4e8b\u60c5\u5c31\u662f\u914d\u7f6eredis.conf\u4e86\uff0c\u5728\u8fd9\u91cc\u9700\u8981\u914d\u7f6e\u56db\u4e2a\u9009\u9879\u3002\u3002\u3002<\/p>\n<p> port &nbsp;\u7aef\u53e3\u5730\u5740\uff0c\u6bd4\u59826380\u6587\u4ef6\u5939\u4e0b\u9762\u7684port\u5c31\u662f6380\uff0c<\/p>\n<pre>\n# Accept connections on the specified port, default is 6379 (IANA #815344).\n# If port 0 is specified Redis will not listen on a TCP socket.\nport 6379<\/pre>\n<p> cluster-enabled \u548c cluster-config-file<\/p>\n<p>\u8fd9\u4e2a\u987e\u540d\u601d\u4e49\uff0c\u9996\u5148\u9700\u8981\u5f00\u542fredis\u7684cluster\u6a21\u5f0f\uff0c\u7136\u540e\u914d\u7f6e\u4e00\u4e2acluster-config-file\u6587\u4ef6\uff0c\u8fd9\u4e2a\u6587\u4ef6\u7528\u4e8e\u5b58\u653eredis\u7684\u5b9e\u65f6\u4fe1\u606f\uff0credis\u4f1a\u52a8\u6001\u8ffd\u52a0\u548c\u4fee\u6539\u8fd9\u4e2aconf\u4e0b\u9762\u7684\u5185\u5bb9\u4fe1\u606f\uff0c\u4e0d\u8fc7\u8981\u8bb0\u4f4f\uff0c\u8fd9\u4e2anodes-6379.conf \u53ef\u4ee5\u6839\u636e \u7aef\u53e3\u6587\u4ef6\u5939\u4f9d\u6b21\u914d\u7f6e\uff0c\u6bd4\u59826380\u6587\u4ef6\u5939\u53ef\u4ee5\u6539\u6210nodes-6380.conf\u8fd9\u6837\u3002\u3002\u3002<\/p>\n<pre>\n# Normal Redis instances can't be part of a Redis Cluster; only nodes that are\n# started as cluster nodes can. In order to start a Redis instance as a\n# cluster node enable the cluster support uncommenting the following:\n#\ncluster-enabled yes\n\n# Every cluster node has a cluster configuration file. This file is not\n# intended to be edited by hand. It is created and updated by Redis nodes.\n# Every Redis Cluster node requires a different cluster configuration file.\n# Make sure that instances running in the same system do not have\n# overlapping cluster configuration file names.\n#\ncluster-config-file nodes-6379.conf\n\n<\/pre>\n<p> directory<\/p>\n<p>\u4e3a\u4e86\u65b9\u4fbf\u7ba1\u7406\uff0c\u6211\u8fd9\u91cc\u914d\u7f6e\u7684root\u76ee\u5f55\u53d6\u51b3\u4e8e\u5728\u54ea\u4e2a\u6587\u4ef6\u5939\uff0c\u6bd4\u59826380\u4e0b\u9762\u6211\u7684dir\u5c31\u662f: dir .\/6380\/<\/p>\n<pre>\n# Note that you must specify a directory here, not a file name.\ndir .\/6379\/<\/pre>\n<p> protected-mode<\/p>\n<p>\u8fd9\u4e2a\u662fredis 3.2 \u624d\u8ffd\u52a0\u7684\u4e00\u4e2a\u529f\u80fd\uff0c\u4ece\u529f\u80fd\u6ce8\u91ca\u4e2d\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u53d1\u73b0\uff0c\u8fd9\u4e2a\u9ed8\u8ba4\u5c31\u662f\u4e0d\u8ba9\u5916\u754c\u53ef\u4ee5\u8bbf\u95eeredis\uff0c\u6240\u4ee5\u8fd9\u91cc\u6211\u4eec\u5c31\u6539\u4e3ano\uff0c\u53ef\u4ee5\u8fdc\u7a0b\u8bbf\u95ee\u3002<\/p>\n<pre>\n# By default protected mode is enabled. You should disable it only if\n# you are sure you want clients from other hosts to connect to Redis\n# even if no authentication is configured, nor a specific set of interfaces\n# are explicitly listed using the \"bind\" directive.\nprotected-mode no<\/pre>\n<p>ok\uff0c\u5230\u73b0\u5728\u4e3a\u6b62\uff0c\u6211\u4eec\u7684config\u5c31\u4fee\u6539\u5b8c\u6bd5\u4e86\uff0c\u5176\u4ed6\u7aef\u53e3\u7684\u6587\u4ef6\u5939\u4e5f\u53ef\u4ee5\u4f9d\u6b21\u914d\u7f6e\u4e4b~<\/p>\n<p><span style=\"color: #ff0000\"><strong>\u4e8c\uff1a\u5f00\u542fredis<\/strong><\/span><\/p>\n<p><span style=\"color: #ff0000\"><font>\u5230\u73b0\u5728\u4e3a\u6b62\uff0c\u5404\u4e2a\u7aef\u53e3\u6587\u4ef6\u5939\u90fd\u914d\u7f6e\u6210\u529f\u4e86\uff0c\u63a5\u4e0b\u6765\u51c6\u5907\u5f00\u542f\u4e86\u3002<\/font><\/span><\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20221230\/167237280763ae62470f1d2.jpg\" style=\"max-width:100%\" class=\"aligncenter\"><\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u53ef\u4ee5\u770b\u4e00\u4e0b\uff0c\u57286379\u4e0b\u9762\u662f\u4e0d\u662f\u6709\u751f\u6210node-6379.conf\u6587\u4ef6\uff0c\u6bd4\u5982\u4e0b\u9762\uff1a<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20221230\/167237280863ae624823ed3.jpg\" style=\"max-width:100%\" class=\"aligncenter\"><\/p>\n<p><span style=\"color: #ff0000\"><strong>\u4e09\uff1a\u914d\u7f6eredis-trib.rb<\/strong><\/span><\/p>\n<p>\u56e0\u4e3aredis-trib.rb\u662fruby\u5199\u7684\uff0c\u800c\u6211\u4eec\u7684\u7535\u8111\u80af\u5b9a\u662f\u6ca1\u6709ruby\u548c\u4e00\u4e9b\u914d\u7f6e\u4f9d\u8d56\u9879\uff0c\u4e0d\u8fc7\u6ca1\u5173\u7cfb\uff0c\u6709\u5f3a\u5927\u7684yum\u5b89\u88c5\uff0c\u4e00\u5207\u90fd\u4e0d\u662f\u95ee\u9898\u3002<\/p>\n<p><strong>1. \u6267\u884creplicas\u547d\u4ee4<\/strong><\/p>\n<pre>\n[jack@localhost ~]$ cluster\/redis-trib.rb create --replicas 1 192.168.161.133:6379 192.168.161.133:6380 192.168.161.133:6381 192.168.161.133:6382 192.168.161.133:6383 192.168.161.133:6384\n\/usr\/bin\/env: ruby: No such file or directory\n[jack@localhost ~]$ <\/pre>\n<p>\u53ef\u4ee5\u770b\u5230ruby\u662f\u6ca1\u6709\u5b89\u88c5\u7684\uff0c\u6240\u4ee5\u4e0b\u4e00\u6b65\u6211\u4eec\u8981\u5b89\u88c5ruby\u4e86\u3002\u3002\u3002<\/p>\n<p><strong>2. \u5b89\u88c5ruby \u3010\u4e00\u5b9a\u8981\u662f\u7ba1\u7406\u5458\u6743\u9650\u54e6\u3011<\/strong><\/p>\n<pre>\n[jack@localhost ~]$ sudo\nusage: sudo [-D level] -h | -K | -k | -V\nusage: sudo -v [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-u user\n      name|#uid]\nusage: sudo -l[l] [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-U user\n      name] [-u user name|#uid] [-g groupname|#gid] [command]\nusage: sudo [-AbEHknPS] [-r role] [-t type] [-C fd] [-D level] [-g\n      groupname|#gid] [-p prompt] [-u user name|#uid] [-g groupname|#gid]\n      [VAR=value] [-i|-s] []\nusage: sudo -e [-AknS] [-r role] [-t type] [-C fd] [-D level] [-g\n      groupname|#gid] [-p prompt] [-u user name|#uid] file ...\n[jack@localhost ~]$ su\nPassword: \njacsu: incorrect password\n[jack@localhost ~]$ yum install ruby\nLoaded plugins: fastestmirror, refresh-packagekit, security\nYou need to be root to perform this command.\n[jack@localhost ~]$ jack\nbash: jack: command not found\n[jack@localhost ~]$ su\nPassword: \n[root@localhost jack]# yum install ruby\nLoaded plugins: fastestmirror, refresh-packagekit, security\nLoading mirror speeds from cached hostfile\n * base: mirror.bit.edu.cn\n * extras: mirror.bit.edu.cn\n * updates: mirror.bit.edu.cn\nSetting up Install Process\nResolving Dependencies\n--&gt; Running transaction check\n---&gt; Package ruby.x86_64 0:1.8.7.374-4.el6_6 will be installed\n--&gt; Processing Dependency: ruby-libs = 1.8.7.374-4.el6_6 for package: ruby-1.8.7.374-4.el6_6.x86_64\n--&gt; Processing Dependency: libruby.so.1.8()(64bit) for package: ruby-1.8.7.374-4.el6_6.x86_64\n--&gt; Running transaction check\n---&gt; Package ruby-libs.x86_64 0:1.8.7.374-4.el6_6 will be installed\n--&gt; Processing Dependency: libreadline.so.5()(64bit) for package: ruby-libs-1.8.7.374-4.el6_6.x86_64\n--&gt; Running transaction check\n---&gt; Package compat-readline5.x86_64 0:5.2-17.1.el6 will be installed\n--&gt; Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package        Arch     Version          Repository Size\n================================================================================\nInstalling:\n ruby          x86_64    1.8.7.374-4.el6_6     base    538 k\nInstalling for dependencies:\n compat-readline5    x86_64    5.2-17.1.el6       base    130 k\n ruby-libs       x86_64    1.8.7.374-4.el6_6     base    1.7 M\n\nTransaction Summary\n================================================================================\nInstall    3 Package(s)\n\nTotal download size: 2.3 M\nInstalled size: 7.8 M\nIs this ok [y\/N]: y\nDownloading Packages:\n(1\/3): compat-readline5-5.2-17.1.el6.x86_64.rpm     | 130 kB   00:00   \n(2\/3): ruby-1.8.7.374-4.el6_6.x86_64.rpm         | 538 kB   00:00   \n(3\/3): ruby-libs-1.8.7.374-4.el6_6.x86_64.rpm      | 1.7 MB   00:02   \n--------------------------------------------------------------------------------\nTotal                      747 kB\/s | 2.3 MB   00:03   \nwarning: rpmts_HdrFromFdno: Header V3 RSA\/SHA256 Signature, key ID c105b9de: NOKEY\nRetrieving key from file:\/\/\/etc\/pki\/rpm-gpg\/RPM-GPG-KEY-CentOS-6\nImporting GPG key 0xC105B9DE:\n Userid : CentOS-6 Key (CentOS 6 Official Signing Key) \n   \n    \n Package: centos-release-6-5.el6.centos.11.1.x86_64 (@anaconda-CentOS-201311272149.x86_64\/6.5)\n From  : \/etc\/pki\/rpm-gpg\/RPM-GPG-KEY-CentOS-6\nIs this ok [y\/N]: y\nRunning rpm_check_debug\nRunning Transaction Test\nTransaction Test Succeeded\nRunning Transaction\n Installing : compat-readline5-5.2-17.1.el6.x86_64             1\/3 \n Installing : ruby-libs-1.8.7.374-4.el6_6.x86_64              2\/3 \n Installing : ruby-1.8.7.374-4.el6_6.x86_64                3\/3 \n Verifying : compat-readline5-5.2-17.1.el6.x86_64             1\/3 \n Verifying : ruby-libs-1.8.7.374-4.el6_6.x86_64              2\/3 \n Verifying : ruby-1.8.7.374-4.el6_6.x86_64                3\/3 \n\nInstalled:\n ruby.x86_64 0:1.8.7.374-4.el6_6                        \n\nDependency Installed:\n compat-readline5.x86_64 0:5.2-17.1.el6 ruby-libs.x86_64 0:1.8.7.374-4.el6_6 \n\nComplete!\n[root@localhost jack]# \n\n\n   <\/pre>\n<p><strong>3. \u5b89\u88c5rubygems<\/strong><\/p>\n<p>\u63a5\u7740\u6211\u4eec\u518d\u6b21\u8fd0\u884c replicas\u547d\u4ee4\uff0c\u770b\u770b\u4f1a\u600e\u4e48\u6837\u3002\u3002\u3002&nbsp;<\/p>\n<pre>\n[root@localhost jack]# cluster\/redis-trib.rb create --replicas 1 192.168.161.133:6379 192.168.161.133:6380 192.168.161.133:6381 192.168.161.133:6382 192.168.161.133:6383 192.168.161.133:6384\ncluster\/redis-trib.rb:24:in `require': no such file to load -- rubygems (LoadError)\n  from cluster\/redis-trib.rb:24\n[root@localhost jack]# <\/pre>\n<p>\u7ed3\u679c\u82e6\u903c\u4e86\uff0c\u8fd8\u662f\u62a5\u9519\uff0c\u770b\u63d0\u793a\u8c8c\u4f3c\u662f\u5c11\u4e86\u4e00\u4e2arubygems\uff0c\u8fd9\u6b21\u6211\u4eec\u8fd8\u662f\u901a\u8fc7yum\u5b89\u88c5\u3002<\/p>\n<pre>\n[root@localhost jack]# yum install -y rubygems\nLoaded plugins: fastestmirror, refresh-packagekit, security\nLoading mirror speeds from cached hostfile\n * base: mirror.bit.edu.cn\n * extras: mirror.bit.edu.cn\n * updates: mirror.bit.edu.cn\nSetting up Install Process\nResolving Dependencies\n--&gt; Running transaction check\n---&gt; Package rubygems.noarch 0:1.3.7-5.el6 will be installed\n--&gt; Processing Dependency: ruby-rdoc for package: rubygems-1.3.7-5.el6.noarch\n--&gt; Running transaction check\n---&gt; Package ruby-rdoc.x86_64 0:1.8.7.374-4.el6_6 will be installed\n--&gt; Processing Dependency: ruby-irb = 1.8.7.374-4.el6_6 for package: ruby-rdoc-1.8.7.374-4.el6_6.x86_64\n--&gt; Running transaction check\n---&gt; Package ruby-irb.x86_64 0:1.8.7.374-4.el6_6 will be installed\n--&gt; Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package      Arch      Version          Repository  Size\n================================================================================\nInstalling:\n rubygems     noarch     1.3.7-5.el6        base     207 k\nInstalling for dependencies:\n ruby-irb     x86_64     1.8.7.374-4.el6_6     base     317 k\n ruby-rdoc     x86_64     1.8.7.374-4.el6_6     base     381 k\n\nTransaction Summary\n================================================================================\nInstall    3 Package(s)\n\nTotal download size: 905 k\nInstalled size: 3.0 M\nDownloading Packages:\n(1\/3): ruby-irb-1.8.7.374-4.el6_6.x86_64.rpm       | 317 kB   00:00   \n(2\/3): ruby-rdoc-1.8.7.374-4.el6_6.x86_64.rpm      | 381 kB   00:00   \n(3\/3): rubygems-1.3.7-5.el6.noarch.rpm          | 207 kB   00:00   \n--------------------------------------------------------------------------------\nTotal                      625 kB\/s | 905 kB   00:01   \nRunning rpm_check_debug\nRunning Transaction Test\nTransaction Test Succeeded\nRunning Transaction\n Installing : ruby-irb-1.8.7.374-4.el6_6.x86_64              1\/3 \n Installing : ruby-rdoc-1.8.7.374-4.el6_6.x86_64              2\/3 \n Installing : rubygems-1.3.7-5.el6.noarch                 3\/3 \n Verifying : ruby-rdoc-1.8.7.374-4.el6_6.x86_64              1\/3 \n Verifying : ruby-irb-1.8.7.374-4.el6_6.x86_64              2\/3 \n Verifying : rubygems-1.3.7-5.el6.noarch                 3\/3 \n\nInstalled:\n rubygems.noarch 0:1.3.7-5.el6                         \n\nDependency Installed:\n ruby-irb.x86_64 0:1.8.7.374-4.el6_6  ruby-rdoc.x86_64 0:1.8.7.374-4.el6_6  \n\nComplete!\n[root@localhost jack]# \n\n \n\n<\/pre>\n<p><strong>4. \u5b89\u88c5redis\u9a71\u52a8<br \/><\/strong><\/p>\n<p>&nbsp;\u8fd8\u662f\u7ee7\u7eed\u4e0d\u6b7b\u5fc3\uff0c\u6211\u4eec\u7ee7\u7eed\u8fd0\u884creplicas\u547d\u4ee4\u547d\u4ee4\u3002<\/p>\n<pre>\n[root@localhost jack]# cluster\/redis-trib.rb create --replicas 1 192.168.161.133:6379 192.168.161.133:6380 192.168.161.133:6381 192.168.161.133:6382 192.168.161.133:6383 192.168.161.133:6384\n\/usr\/lib\/ruby\/site_ruby\/1.8\/rubygems\/custom_require.rb:31:in `gem_original_require': no such file to load -- redis (LoadError)\n  from \/usr\/lib\/ruby\/site_ruby\/1.8\/rubygems\/custom_require.rb:31:in `require'\n  from cluster\/redis-trib.rb:25\n[root@localhost jack]# <\/pre>\n<p>\u8fd8\u662f\u6709\u95ee\u9898\uff0c\u8fd9\u6b21\u8c8c\u4f3c\u662f\u4e00\u4e2agem_original_require\u6ca1\u6709\u5b89\u88c5\uff0c\u5f53\u7136\u8fd9\u4e2a\u4e00\u822c\u662f\u8bf4ruby\u7248\u672c\u592a\u8001\u4e86\uff0c\u6240\u4ee5\u73b0\u5728\u4eb2\u8981\u4e48\u5347\u7ea7ruby\u7248\u672c\uff0c\u8981\u4e48\u76f4\u63a5\u5b89\u88c5ruby\u7684redis\u9a71\u52a8\u3002<\/p>\n<pre>\n[root@localhost jack]# gem install redis\nSuccessfully installed redis-3.3.0\n1 gem installed\nInstalling ri documentation for redis-3.3.0...\nInstalling RDoc documentation for redis-3.3.0...<\/pre>\n<p><strong>6. \u8fd0\u884creplicas\u547d\u4ee4<\/strong><\/p>\n<p>\u7ec8\u4e8e\u8c8c\u4f3c\u6240\u6709\u7684\u4f9d\u8d56\u6211\u4eec\u90fd\u89e3\u51b3\u4e86\uff0c\u63a5\u4e0b\u6765\u5c31\u53ef\u4ee5\u771f\u7684\u6267\u884c\u4e86\u3002<\/p>\n<pre>\n[root@localhost jack]# cluster\/redis-trib.rb create --replicas 1 192.168.161.133:6379 192.168.161.133:6380 192.168.161.133:6381 192.168.161.133:6382 192.168.161.133:6383 192.168.161.133:6384\n&gt;&gt;&gt; Creating cluster\n&gt;&gt;&gt; Performing hash slots allocation on 6 nodes...\nUsing 3 masters:\n192.168.161.133:6379\n192.168.161.133:6380\n192.168.161.133:6381\nAdding replica 192.168.161.133:6382 to 192.168.161.133:6379\nAdding replica 192.168.161.133:6383 to 192.168.161.133:6380\nAdding replica 192.168.161.133:6384 to 192.168.161.133:6381\nM: fdae457e803e2e04a7c549c69b44a2beefdae3bc 192.168.161.133:6379\n  slots:0-5460 (5461 slots) master\nM: 74285cee0fa65e64b443ecc630e447a8a65ee9f8 192.168.161.133:6380\n  slots:5461-10922 (5462 slots) master\nM: 14ed067a1b85044325d5800fa8479a6b4e41a10c 192.168.161.133:6381\n  slots:10923-16383 (5461 slots) master\nS: c50b1ff1fe3a00b16703f3b5705d2dafe046240b 192.168.161.133:6382\n  replicates fdae457e803e2e04a7c549c69b44a2beefdae3bc\nS: 8f7bd92f7ffb48e327820693a5820b5be7ea5556 192.168.161.133:6383\n  replicates 74285cee0fa65e64b443ecc630e447a8a65ee9f8\nS: 4a85ed078b4c99afad7f3a9a8df09082c681a649 192.168.161.133:6384\n  replicates 14ed067a1b85044325d5800fa8479a6b4e41a10c\nCan I set the above configuration? (type 'yes' to accept): yes\n&gt;&gt;&gt; Nodes configuration updated\n&gt;&gt;&gt; Assign a different config epoch to each node\n&gt;&gt;&gt; Sending CLUSTER MEET messages to join the cluster\nWaiting for the cluster to join....\n&gt;&gt;&gt; Performing Cluster Check (using node 192.168.161.133:6379)\nM: fdae457e803e2e04a7c549c69b44a2beefdae3bc 192.168.161.133:6379\n  slots:0-5460 (5461 slots) master\nM: 74285cee0fa65e64b443ecc630e447a8a65ee9f8 192.168.161.133:6380\n  slots:5461-10922 (5462 slots) master\nM: 14ed067a1b85044325d5800fa8479a6b4e41a10c 192.168.161.133:6381\n  slots:10923-16383 (5461 slots) master\nM: c50b1ff1fe3a00b16703f3b5705d2dafe046240b 192.168.161.133:6382\n  slots: (0 slots) master\n  replicates fdae457e803e2e04a7c549c69b44a2beefdae3bc\nM: 8f7bd92f7ffb48e327820693a5820b5be7ea5556 192.168.161.133:6383\n  slots: (0 slots) master\n  replicates 74285cee0fa65e64b443ecc630e447a8a65ee9f8\nM: 4a85ed078b4c99afad7f3a9a8df09082c681a649 192.168.161.133:6384\n  slots: (0 slots) master\n  replicates 14ed067a1b85044325d5800fa8479a6b4e41a10c\n[OK] All nodes agree about slots configuration.\n&gt;&gt;&gt; Check for open slots...\n&gt;&gt;&gt; Check slots coverage...\n[OK] All 16384 slots covered.\n[root@localhost jack]# \n\n<\/pre>\n<p>\u4ece\u4e0a\u9762\u53ef\u4ee5\u770b\u5230\uff0ctrib\u7a0b\u5e8f\u544a\u77e5\u6211\u4eec\u662f\u5426\u7528 6379\uff0c6380\uff0c6381 \u4f5c\u4e3a\u4e3b\uff0c 6382\uff0c6383\uff0c6384\u4f5c\u4e3a\u4ece\u3002\u3002\u7136\u540e\u6211\u5c31\u6069\u51c6\u4e86\u3002\u3002\u5c31\u8fd9\u6837\u6211\u4eec\u7684\u96c6\u7fa4\u5c31\u521b\u5efa\u597d\u4e86<\/p>\n","protected":false},"excerpt":{"rendered":"<p>redis\u96c6\u7fa4\u642d\u5efa_\u52a8\u529b\u8282\u70b9Ja&#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-201133","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201133","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=201133"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201133\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}