Redis Cluster 搭建
Redis About 4,528 words安装 Redis5.0.7
http://download.redis.io/releases/redis-5.0.7.tar.gz
tar xzf redis-5.0.7.tar.gz
cd redis-5.0.7
make
make install
参数配置
port 70xx # 指定端口
bind 127.0.0.1 # 指定物理接口 ip 地址
cluster-enabled yes # 搭建 redis 集群必须开启
daemonize yes # 后台运行
pidfile /var/run/redis_70xx.pid # 节点间配置不可相同
cluster-config-file nodes-70xx.conf # 节点间配置不可相同
cluster-node-timeout 5000 # 节点间通信超时时间
启动 Redis 服务
sudo redis-server conf/redis-7000.conf
sudo redis-server conf/redis-7001.conf
sudo redis-server conf/redis-7002.conf
sudo redis-server conf/redis-7003.conf
sudo redis-server conf/redis-7004.conf
sudo redis-server conf/redis-7005.conf
使用 redis-cli 初始化 Redis Cluster
按照从主到从
的方式从左到右
依次排列6
个Redis
节点。
中途会需要输入yes
redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 --cluster-replicas 1
搭建成功
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
测试
redis-cli -c -h 127.0.0.1 -p 7000
显示节点信息
cluster nodes
各节点信息
7407745d8070e96d7379e699b07f0bca88982be1 127.0.0.1:7001@17001 master - 0 1570968932522 2 connected 5461-10922
ba29160843481925a592c4bb50aec8c394e1f458 127.0.0.1:7000@17000 myself,master - 0 1570968930000 1 connected 0-5460
5b6c91dd6872314cf9e90fdca716e1c65a36674c 127.0.0.1:7004@17004 slave 415273835d288ecc0b40011672a83ee607eceeda 0 1570968931615 5 connected
ae66949b57bb87545d1a03cf4dbfa61cc49ffb87 127.0.0.1:7005@17005 slave ba29160843481925a592c4bb50aec8c394e1f458 0 1570968932623 6 connected
415273835d288ecc0b40011672a83ee607eceeda 127.0.0.1:7002@17002 master - 0 1570968932522 3 connected 10923-16383
e528efbe0459fea7f48eac2e1f5547005f975cc6 127.0.0.1:7003@17003 slave 7407745d8070e96d7379e699b07f0bca88982be1 0 1570968931514 4 connected
安装 Redis4.0.14
wget http://download.redis.io/releases/redis-4.0.14.tar.gz
tar xzf redis-4.0.14.tar.gz
cd redis-4.0.14
make
make install
使用 redis-trib.rb 初始化 Redis Cluster
Redis3
或4
需使用redis-trib.rb
搭建Redis Cluster
,但redis-trib.rb
需安装ruby
才能使用。
安装 rubygems
CentOS
sudo yum -y install ruby rubygems
Ubuntu
sudo apt-get -y install ruby rubygems
安装 redis-trib.rb 的依赖包
gem install redis
若安装出错
[root@root ~]# gem install redis
ERROR: Error installing redis:
redis requires Ruby version >= 2.3.0.
查看Ruby
版本
ruby -v
安装ruby2.4
版本
sudo yum remove ruby
wget https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.2.tar.gz
tar -zxvf ruby-2.4.2.tar.gz
cd ruby-2.4.2
./configure
make && make install
sudo ln -s ruby /usr/bin/ruby
gem
安装后不知道文件在哪个目录
gem environment
用户安装目录:/usr/local/lib/ruby/gems/2.4.0
RubyGems Environment:
- RUBYGEMS VERSION: 2.6.13
- RUBY VERSION: 2.4.2 (2017-09-14 patchlevel 198) [x86_64-linux]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.4.0
- USER INSTALLATION DIRECTORY: /root/.gem/ruby/2.4.0
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- SPEC CACHE DIRECTORY: /root/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /usr/local/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /usr/local/lib/ruby/gems/2.4.0
- /root/.gem/ruby/2.4.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /usr/local/sbin
- /usr/local/bin
- /sbin
- /bin
- /usr/sbin
- /usr/bin
- /root/bin
参数配置
port 70xx # 指定端口
bind 127.0.0.1 # 指定物理接口 ip 地址
cluster-enabled yes # 搭建 redis 集群必须开启
daemonize yes # 后台运行
pidfile /var/run/redis_70xx.pid # 节点间配置不可相同
cluster-config-file nodes-70xx.conf # 节点间配置不可相同
cluster-node-timeout 5000 # 节点间通信超时时间
启动 Redis 服务
sudo redis-server conf/redis-7000.conf
sudo redis-server conf/redis-7001.conf
sudo redis-server conf/redis-7002.conf
sudo redis-server conf/redis-7003.conf
sudo redis-server conf/redis-7004.conf
sudo redis-server conf/redis-7005.conf
配置集群
按照从主到从
的方式从左到右
依次排列6
个Redis
节点。
- 中途会需要输入
yes
--replicas 1
表示给每一个master
配置一个slave
- 成功后的效果如
5.0
以上版本创建的效果以及使用的命令均一致
redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005
参考
Views: 3,970 · Posted: 2020-01-09
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...