在conf?录下创建?件7000.conf,编辑内容如下
port 7000 bind 172.16.179.130 daemonize yes pidfile 7000.pid cluster-enabled yes cluster-config-file 7000_node.conf cluster-node-timeout 15000 appendonly yes
在conf?录下创建?件7001.conf,编辑内容如下
port 7001 bind 172.16.179.130 daemonize yes pidfile 7001.pid cluster-enabled yes cluster-config-file 7001_node.conf cluster-node-timeout 15000 appendonly yes
在conf?录下创建?件7002.conf,编辑内容如下
port 7002 bind 172.16.179.130 daemonize yes pidfile 7002.pid cluster-enabled yes cluster-config-file 7002_node.conf cluster-node-timeout 15000 appendonly yes
总结:三个?件的配置区别在port、pidfile、cluster-config-file三项
使?配置?件启动redis服务
redis-server 7000.conf redis-server 7001.conf redis-server 7002.conf
查看进程如下图
在conf?录下创建?件7003.conf,编辑内容如下
port 7003 bind 172.16.179.131 daemonize yes pidfile 7003.pid cluster-enabled yes cluster-config-file 7003_node.conf cluster-node-timeout 15000 appendonly yes
在conf?录下创建?件7004.conf,编辑内容如下
port 7004 bind 172.16.179.131 daemonize yes pidfile 7004.pid cluster-enabled yes cluster-config-file 7004_node.conf cluster-node-timeout 15000 appendonly yes
在conf?录下创建?件7005.conf,编辑内容如下
port 7005 bind 172.16.179.131 daemonize yes pidfile 7005.pid cluster-enabled yes cluster-config-file 7005_node.conf cluster-node-timeout 15000 appendonly yes
总结:三个?件的配置区别在port、pidfile、cluster-config-file三项
使?配置?件启动redis服务
redis-server 7003.conf redis-server 7004.conf redis-server 7005.conf
查看进程如下图
文档连接 http://doc.redisfans.com/topic/cluster-tutorial.html
将命令复制,这样可以在任何?录下调?此命令
sudo cp /usr/share/doc/redis-tools/examples/redis-trib.rb /usr/local/bin/
安装ruby环境,因为redis-trib.rb是?ruby开发的
sudo apt-get install ruby
在提示信息处输?y,然后回?继续安装
运?如下命令创建集群
redis-trib.rb create --replicas 1 172.16.179.130:7000 172.16.179.130:7001 172.16.179.130:7002 172.16.179.131:7003 172.16.179.131:7004 172.16.179.131:7005
执?上?这个指令在某些机器上可能会报错,主要原因是由于安装的 ruby 不是最 新版本!
天朝的防?墙导致?法下载最新版本,所以需要设置 gem 的源
解决办法如下
-- 先查看??的 gem 源是什么地址
gem source -l -- 如果是https://rubygems.org/ 就需要更换
-- 更换指令为
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
-- 通过 gem 安装 redis 的相关依赖
sudo gem install redis
-- 然后重新执?指令

redis-trib.rb create --replicas 1 172.16.179.130:7000 172.16.179.130:7001 172.16.179.130:7002 172.16.179.131:7003 172.16.179.131:7004 172.16.179.131:7005
提示如下主从信息,输?yes后回?
提示完成,集群搭建成功
在172.16.179.131机器上连接7002,加参数-c表示连接到集群
redis-cli -h 172.16.179.131 -c -p 7002
写?数据
set name itheima
?动跳到了7003服务器,并写?数据成功
在7003可以获取数据,如果写入数据又重定向到7000(负载均衡)
原文:https://www.cnblogs.com/1164xiepei-qi/p/14178273.html