ubuntu配置redis集群

下载redis

sudo apt-get install redis-server

找到配置文件

进入redis配置文件目录

cd /etc/redis

找不到的话可以这样搜索,找到他的目录

whereis redis

修改配置文件

把redis配置文件复制一份

sudo cp redis.conf 7000.conf

修改

sudo vim 7000.conf

修改以下内容

如果你时阿里云之类服务器,需要把对应端口打开,里面的ip输入内网ip,redis集群不仅需要开通redis客户端连接的端口,而且需要开通集群总线端口,集群总线端口为redis客户端连接的端口 + 10000 。

port 7000
bind 你虚拟的ip
daemonize yes
pidfile 7000.pid
cluster-enabled yes
cluster-config-file 7000_node.conf
cluster-node-timeout 15000
appendonly yes

再把配置文件复制5份,修改以下内容,其他内容不要动

不同配置文件之间的差异

与7000的配置文件只有以下三个字段有差异

port 7001
pidfile 7001.pid
cluster-config-file 7001_node.conf

7001.conf

port 7001
bind 你虚拟的ip
daemonize yes
pidfile 7001.pid
cluster-enabled yes
cluster-config-file 7001_node.conf
cluster-node-timeout 15000
appendonly yes

7002.conf

port 7002
bind 你虚拟的ip
daemonize yes
pidfile 7002.pid
cluster-enabled yes
cluster-config-file 7002_node.conf
cluster-node-timeout 15000
appendonly yes

7003.conf

port 7003
bind 你虚拟的ip
daemonize yes
pidfile 7003.pid
cluster-enabled yes
cluster-config-file 7003_node.conf
cluster-node-timeout 15000
appendonly yes

7004.conf

port 7000
bind 你虚拟的ip
daemonize yes
pidfile 7004.pid
cluster-enabled yes
cluster-config-file 7004_node.conf
cluster-node-timeout 15000
appendonly yes

7005.conf

port 7005
bind 你虚拟的ip
daemonize yes
pidfile 7005.pid
cluster-enabled yes
cluster-config-file 7005_node.conf
cluster-node-timeout 15000
appendonly yes

最后目录为

在这里插入图片描述

启动这6的redis服务

redis-server 7000.conf
redis-server 7001.conf
redis-server 7002.conf
redis-server 7003.conf
redis-server 7004.conf
redis-server 7005.conf

安装ruby环境

因为redis-trib.rb是⽤ruby开发的

sudo apt-get update
sudo apt-get install ruby

redis-trib.rb命令创建集群

找到redis-trip.rb

sudo cp /usr/share/doc/redis-tools/examples/redis-trib.rb /usr/local/bin/

gem 下载redis

sudo gem install redis

创建集群

redis-trib.rb create --replicas 1 你的ip:7000 你的ip:7001 你的ip:7002 你的ip:7003 你的ip:7004 你的ip:7005
在这里插入图片描述

查看是否启动成功

在这里插入图片描述

进入集群

记住进入集群最后要加-c

redis-client -h 你的IP -p 7000 -c

测试结果

可以看到,我们在7000里面设置了个name=dxd,可以在7001里面通过get name获取值
退出集群,通过redis-client -h 你的IP -p 7005 -c 进去,也能获取到name的值
在这里插入图片描述

与python交互

https://mp.youkuaiyun.com/mdeditor/102655654#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值