redis伺服器說明
<code>10.0.0.5 6379</code>
<code>10.0.0.5 6380</code>
<code>10.0.0.5 6381</code>
<code> </code>
<code>10.0.0.6 6382</code>
<code>10.0.0.6 6383</code>
<code>10.0.0.6 6384</code>
#安裝完畢後
<code>yum -y </code><code>install</code> <code>gcc openssl-devel libyaml-devel libffi-devel readline-devel autoconf</code>
<code>yum -y </code><code>install</code> <code>ruby rubygems zlib-devel gdbm-devel ncurses-devel gcc-c++ automake</code>
#換源
<code>gem </code><code>source</code> <code>-l </code>
<code>gem </code><code>source</code> <code>–remove http:</code><code>//rubygems</code><code>.org/ </code>
<code>gem sources –add https:</code><code>//gems</code><code>.ruby-china.org/ –remove https:</code><code>//rubygems</code><code>.org/ </code>
<code>gem </code><code>source</code> <code>-l</code>
<code>gem </code><code>install</code> <code>redis</code>
<code>ERROR: Error installing redis:</code>
<code>redis requires Ruby version >= 2.2.2.</code>
#原因rvm版本過低
執行以下指令更新rvm
<code>gpg2 —keyserver hkp:</code><code>//keys</code><code>.gnupg.net –recv-keys D39DC0E3</code>
<code>curl -L get.rvm.io | </code><code>bash</code> <code>-s stable</code>
<code>source</code> <code>/usr/local/rvm/scripts/rvm</code>
<code>rvm </code><code>install</code> <code>2.3.3</code>
<code>rvm use 2.3.3</code>
<code>rvm use 2.3.3 –default</code>
<code>rvm remove 2.0.0</code>
#檢視現在版本為2.3.3則對
<code>ruby –version</code>
兩台主機均修改以下配置檔案
<code>port 6379 </code><code>//</code><code>先預設端口,等會再改</code>
<code>bind 本機ip </code><code>//</code><code>預設ip為127.0.0.1 需要改為其他節點機器可通路的ip 否則建立叢集時無法通路對應的端口,無法建立叢集</code>
<code>daemonize </code><code>yes</code> <code>//redis</code><code>背景運作</code>
<code>pidfile </code><code>/var/run/redis_6379</code><code>.pid </code><code>//pidfile</code><code>檔案對應</code>
<code>cluster-enabled </code><code>yes</code> <code>//</code><code>開啟叢集 把注釋</code><code>#去掉</code>
<code>cluster-config-</code><code>file</code> <code>nodes_6379.conf </code><code>//</code><code>叢集的配置檔案</code>
<code>cluster-node-timeout 15000 </code><code>//</code><code>請求逾時 預設15秒,可自行設定</code>
<code>appendonly </code><code>yes</code> <code>//aof</code><code>日志開啟 有需要就開啟,它會每次寫操作都記錄一條日志</code>
執行個體10.0.0.5
<code>mkdir</code> <code>/data/redis/conf/</code>
<code>cp</code> <code>/redis-3</code><code>.2.8</code><code>/redis</code><code>.conf </code><code>/data/redis/conf/6379</code><code>.conf</code>
<code>sed</code> <code>-i “s</code><code>/6379/6380/g</code><code>” </code><code>/etc/redis/redis-6380</code><code>.conf </code>
<code>cp</code> <code>/redis-3</code><code>.2.8</code><code>/redis</code><code>.conf </code><code>/data/redis/conf/6380</code><code>.conf</code>
<code>sed</code> <code>-i “s</code><code>/6379/6380/g</code><code>” </code><code>/date/redis/conf/6380</code><code>.conf </code>
<code>cp</code> <code>/redis-3</code><code>.2.8</code><code>/redis</code><code>.conf </code><code>/data/redis/conf/6381</code><code>.conf</code>
<code>sed</code> <code>-i “s</code><code>/6379/6382/g</code><code>” </code><code>/date/redis/conf/6381</code><code>.conf</code>
#啟動
<code>redis-server </code><code>/data/redis/conf/6379</code><code>.conf</code>
<code>redis-server </code><code>/data/redis/conf/6380</code><code>.conf</code>
<code>redis-server </code><code>/data/redis/conf/6381</code><code>.conf</code>
執行個體 10.0.0.6
<code>cp</code> <code>/redis-3</code><code>.2.8</code><code>/redis</code><code>.conf </code><code>/data/redis/conf/6382</code><code>.conf</code>
<code>sed</code> <code>-i “s</code><code>/6379/6382/g</code><code>” </code><code>/date/redis/conf/6382</code><code>.conf</code>
<code>cp</code> <code>/redis-3</code><code>.2.8</code><code>/redis</code><code>.conf </code><code>/data/redis/conf/6383</code><code>.conf</code>
<code>sed</code> <code>-i “s</code><code>/6379/6382/g</code><code>” </code><code>/date/redis/conf/6383</code><code>.conf</code>
<code>cp</code> <code>/redis-3</code><code>.2.8</code><code>/redis</code><code>.conf </code><code>/data/redis/conf/6384</code><code>.conf</code>
<code>sed</code> <code>-i “s</code><code>/6379/6382/g</code><code>” </code><code>/date/redis/conf/6384</code><code>.conf</code>
<code>redis-server </code><code>/data/redis/conf/6382</code><code>.conf</code>
<code>redis-server </code><code>/data/redis/conf/6383</code><code>.conf</code>
<code>redis-server </code><code>/data/redis/conf/6384</code><code>.conf</code>
啟動叢集
<code>/redis-3</code><code>.2.8</code><code>/src/redis-trib</code><code>.rb create –replicas 1 10.0.0.5:6379 10.0.0.5:6380 10.0.0.5:6381 10.0.0.6:6382 10.0.0.6:6383 10.0.0.6:6384</code>
#出現如下内容為成功
<code>[root@lb01 etc]</code><code># /redis-3.2.8/src/redis-trib.rb create –replicas 1 10.0.0.5:6379 10.0.0.5:6380 10.0.0.5:6381 10.0.0.6:6382 10.0.0.6:6383 10.0.0.6:6384</code>
<code>>>> Creating cluster</code>
<code>>>> Performing </code><code>hash</code> <code>slots allocation on 6 nodes…</code>
<code>Using 3 masters:</code>
<code>10.0.0.5:6379</code>
<code>10.0.0.6:6382</code>
<code>10.0.0.5:6380</code>
<code>Adding replica 10.0.0.6:6383 to 10.0.0.5:6379</code>
<code>Adding replica 10.0.0.5:6381 to 10.0.0.6:6382</code>
<code>Adding replica 10.0.0.6:6384 to 10.0.0.5:6380</code>
<code>M: d0b49faff3332cdf7389948593d4fb59caca1613 10.0.0.5:6379</code>
<code>slots:0-5460 (5461 slots) master</code>
<code>M: 8c8a578c750b820ce074026e59d4df059eeefd9b 10.0.0.5:6380</code>
<code>slots:10923-16383 (5461 slots) master</code>
<code>S: 731a69f9df773823be182e27e5001b95766b5528 10.0.0.5:6381</code>
<code>replicates b73a3a4528920064cba668aa9452f32387292ab6</code>
<code>M: b73a3a4528920064cba668aa9452f32387292ab6 10.0.0.6:6382</code>
<code>slots:5461-10922 (5462 slots) master</code>
<code>S: 139c02ceb5a2afe9eb0e350ed3170bceb3aa4c4b 10.0.0.6:6383</code>
<code>replicates d0b49faff3332cdf7389948593d4fb59caca1613</code>
<code>S: af498152476cd4732c47292aff44a57bcd57bb63 10.0.0.6:6384</code>
<code>replicates 8c8a578c750b820ce074026e59d4df059eeefd9b</code>
<code>Can I </code><code>set</code> <code>the above configuration? (</code><code>type</code> <code>‘</code><code>yes</code><code>’ to accept): </code><code>yes</code> <code>#輸入yes即可</code>
<code>[root@lb01 redis-3.2.8]</code><code># redis-cli -h 10.0.0.5 -c -p 6379</code>
<code>10.0.0.5:6379> </code><code>set</code> <code>tank tank1</code>
<code>OK</code>
<code>10.0.0.5:6379> quit</code>
<code>[root@lb01 redis-3.2.8]</code><code># redis-cli -h 10.0.0.6 -c -p 6382</code>
<code>10.0.0.6:6382> get tank</code>
<code>-> Redirected to slot [4407] located at 10.0.0.5:6379</code>
<code>“tank1”</code>
<code>10.0.0.5:6379></code>
本文轉自 藍葉子Sheep 51CTO部落格,原文連結:http://blog.51cto.com/dellinger/1973780,如需轉載請自行聯系原作者