环境配置
yum -y install gcc-c++
单机版安装
修改配置
redis.conf
#yes:后台运行
daemonize no ->yes
# 安全模式
protected-mode yes ->no
# bind 127.0.0.1 注释,不限制连接ip
#配置密码
requirepass foobared
安装
进入源码 src文件夹下执行,并且指定安装路径
make install PREFIX=/data/redis/7001
启动
redis-server /yourpath/redis.conf
登录
redis-cli -a password
测试
ping -->pong
停止
redis-cli -p 6379 shutdown
查看redis 版本
redis-server -v
集群模式安装
需要删除旧的数据,最好是重新来一遍
本次测试在一台机器上安装6个节点,副本数为1,生产副本数按实际需求配置
配置
# 修改配置,改为集群配置
cluster-enabled no -> yes
#修改日志路径
logfile "redis.log"
#节点认证
masterauth foobared
先启动单个实例
start.sh
cd 7001/bin
./redis-server redis.conf
cd ..
cd ..
cd 7002/bin
./redis-server redis.conf
cd ..
cd ..
端口依次累加...
启动集群
启动集群
./redis-cli --cluster create 192.168.30.3:7001 192.168.30.3:7002 192.168.30.3:7003 192.168.30.3:7004 192.168.30.3:7005 192.168.30.3:7006 --cluster-replicas 1 -a foobared
进入某一个节点,连接集群
redis-cli -p 7001 -c -a foobared
redis-cli -c -h ip地址 -p 5379 -a foobared
查看集群状态
cluster info
cluster nodes
验证集群分配卡槽
set name xm
需要修改的配置
# 开启集群模式
cluster-enabled yes
#yes:后台运行
daemonize no ->yes
# 安全模式
protected-mode yes ->no
# bind 127.0.0.1 注释,不限制连接ip
#配置密码
requirepass <password>
#修改日志路径
logfile "redis.log"
#节点认证
masterauth <password>
# redis 的持久化,开启 AOF,记录历史操作
# 是否开启AOF功能,默认是no
appendonly no -> yes
# AOF文件的名称
appendfilename "appendonly.aof"
# 写命令执行完先放入AOF缓冲区,然后表示每隔1秒将缓冲区数据写到AOF文件,是默认方案
appendfsync everysec