您好,登錄后才能下訂單哦!
1、環境說明
在此文章中不對redis做詳細介紹,如果對redis不太了解的朋友可以參考此鏈接 http://www.runoob.com/redis/redis-tutorial.html
要讓redis集群正常工作至少需要3個主節點,在這里我們要創建6個redis節點,其中三個為主節點,三個為從節點,對應的redis節點的ip和端口對應關系如下:
主機和端口 |
192.168.102.51:6379、192.168.102.51:6380 |
192.168.102.52:6379、192.168.102.52:6380 |
192.168.102.53:6379、192.168.102.53:6380 |
說明:3臺服務器部署redis集群環境,如果你只用于測試部署,可在1臺服務器上配置,不過端口別重復就行。
2、準備redis相關依賴包
( 在這3臺服務器都需要安裝)
包名 | 下載地址 |
zlib-1.2.8.tar.gz | http://nchc.dl.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz |
ruby-2.2.4.tar.bz2 | https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.4.tar.bz2 |
rubygems-2.5.1.tgz | https://rubygems.global.ssl.fastly.net/rubygems/rubygems-2.5.1.tgz |
redis-3.2.2.gem | https://rubygems.global.ssl.fastly.net/gems/redis-3.2.2.gem |
redis-3.2.3.tar.gz | http://download.redis.io/releases/redis-3.2.3.tar.gz |
2.1 安裝zlib
# gunzip zlib-1.2.8.tar.gz # tar -xvf zlib-1.2.8.tar # cd zlib-1.2.8 # ./configure # make # make install |
2.2 安裝ruby
# bunzip2 ruby-2.2.4.tar.bz2 # tar -xvf ruby-2.2.4.tar # cd ruby-2.2.4 # ./configure -prefix=/usr/local/ruby # make Generating RDoc documentation Parsing sources... 100% [967/967] vsnprintf.c Generating RI format into /root/ruby-2.2.4/.ext/rdoc... Files: 967 Classes: 1411 ( 581 undocumented) Modules: 280 ( 108 undocumented) Constants: 2160 ( 594 undocumented) Attributes: 1156 ( 255 undocumented) Methods: 10488 (2187 undocumented) Total: 15495 (3725 undocumented) 75.96% documented Elapsed: 744.0s # make install # cp ruby /bin |
2.3 安裝rubygems
# tar -zxvf rubygems-2.5.1.tgz # cd rubygems-2.5.1 # ruby setup.rb # cp bin/gem /bin |
注意:編譯中出現in 'require': cannot load such file -- json/pure (LoadError)的解決方法:
# gem install json_pure
Fetching: json_pure-1.8.3.gem (100%)
Successfully installed json_pure-1.8.3
Parsing documentation for json_pure-1.8.3
Installing ri documentation for json_pure-1.8.3
1 gem installed
2.4 安裝gem-redis
# gem install -l redis-3.2.2.gem Successfully installed redis-3.2.2 Parsing documentation for redis-3.2.2 Installing ri documentation for redis-3.2.2 1 gem installed |
3、安裝redis( 在這3臺服務器都需要安裝)
解壓、編譯
# tar -zxvf redis-3.2.3.tar.gz # cd redis-3.2.3 # make |
創建redis所需目錄
#mkdir -p /usr/local/redis/{bin,conf,data,logs} ##創建redis相關目錄 # cp src/redis-server /usr/local/redis/bin/ ##Redis服務器的daemon啟動程序 # cp src/redis-cli /usr/local/redis/bin/ ##Redis命令行操作工具 # cp src/redis-trib.rb /usr/local/redis/bin/ ##Redis Cluster工具 # cp src/redis-benchmark /usr/local/redis/bin/ ##Redis性能測試工具 # cp src/redis-check-aof /usr/local/redis/bin/ ##修復壞損壞的aof文件 # cp src/redis-check-dump /usr/local/redis/bin/ ##檢查導出工具 # cp src/redis-sentinel /usr/local/redis/bin/ ##Redis集群的管理工具 |
說明:如果你不想跟上面那樣麻煩操作,也可直接復制src目錄下所有的文件至 /usr/local/redis/bin/中
比如:cp src/* /usr/local/redis/bin/
復制redis配置文件
# cp redis.conf /usr/local/redis/conf/redis-6379.conf # cp redis.conf /usr/local/redis/conf/redis-6380.conf |
修改redis配置文件(修改紅色字體部分)
bind 0.0.0.0 #redis服務監聽的地址 protected-mode yes port 6379 #如果是redis-6380.conf配置文件,修改為6380 tcp-backlog 511 timeout 0 tcp-keepalive 300 daemonize yes #修改為yes,讓redis在后臺運行 supervised no pidfile /var/run/redis_6379.pid #如果是redis-6380.conf配置文件,修改為redis_6380.pid loglevel notice logfile /usr/local/redis/logs/redis-6379.log #如果是redis-6380.conf配置文件,修改為redis_6380.pid databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump.rdb dir ./ slave-serve-stale-data yes slave-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no slave-priority 100 appendonly no appendfilename "appendonly.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes lua-time-limit 5000 cluster-enabled yes cluster-config-file nodes-51-6379.conf #如果是redis-6380.conf配置文件,修改為nodes-51-6380.conf cluster-node-timeout 5000 slowlog-log-slower-than 10000 slowlog-max-len 128 latency-monitor-threshold 0 notify-keyspace-events "" hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-size -2 list-compress-depth 0 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 aof-rewrite-incremental-fsync yes |
cluster-config-file nodes-51-6379.conf #這條配置要特別說明一下
一定要注意,這3臺服務器這條配置的名字最好不要取一樣的,建議按下面的方式取名(當然你可以自己規定):
192.168.102.51:nodes-51-6379.conf nodes-51-6380.conf
192.168.102.52:nodes-52-6379.conf nodes-52-6380.conf
192.168.102.53:nodes-53-6379.conf nodes-53-6380.conf
說明:如果需要了解redis更多配置文件的詳細說明,請參考下面的鏈接
http://blog.csdn.net/neubuffer/article/details/17003909
4、redis集群啟動
4.1 redis實例啟動(按順序挨個啟動,先啟動6379、后啟動6380):
#/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis-6379.conf #分別按相順序啟動這3臺服務器的6379實例 #/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis-6380.conf #分別按相順序啟動3臺服務器的6380實例 |
然后檢查實例是否啟動正常:
#ps -ef | grep redis |
4.2 創建集群 (在第1臺redis服務器上創建,并執行以下命令)
#/usr/local/redis/bin//bin/redis-trib.rb create --replicas 1 192.168.102.51:6379 192.168.102.52:6379 192.168.102.53:6379 192.168.102.51:6380 192.168.102.52:6380 192.168.102.53:6380 |
Can I set the above configuration? (type 'yes' to accept): yes #這里要輸入yes
查看集群節點:
檢測集群:
查看集群主節點:
如出現以上這些信息,說明集群安裝成功。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。