1、下载Redis安装包
redis-5.0.8.tar.gz
通过ftp上载到/usr/local/package,tar zxvf redis-5.0.8.tar.gz解压
集群不需要编译
redis5.0 编译安装,安装到/package/redis文件夹
2、环境搭建
创建文件夹/usr/local/java/redis_cluster
在redis_cluster mkdir 7000 创建节点文件夹 共6个
拷贝配置 cp ./redis.conf /usr/local/java/redis_cluster/7000
vim redis.conf 按照如下更改配置文件
# 关闭保护模式,用于公网访问
protected-mode no
port 7000
# 开启集群模式
cluster-enabled yes
cluster-config-file nodes-7000.conf
cluster-node-timeout 5000
# 后台启动
daemonize yes
pidfile /var/run/redis_7000.pid
logfile "7000.log"
# dir ./
# bind 127.0.0.1
# 用于连接主节点密码
masterauth 123456
# 设置redis密码,各节点保持一致
requirepass 123456
拷贝src文件
cp -r ./src/ /usr/local/java/redis_cluster/
3、启动
./src/redis-server ./7000/redis.conf
./src/redis-server ./7001/redis.conf
./src/redis-server ./7002/redis.conf
./src/redis-server ./7003/redis.conf
./src/redis-server ./7004/redis.conf
./src/redis-server ./7005/redis.conf
查看状态
ps -ef | grep -i redis
4、创建集群
./src/redis-cli --cluster create -a 123456 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
Can I set the above configuration? (type 'yes' to accept):
yes
[OK] All 16384 slots covered.
5、使用
./src/redis-cli -c -h 127.0.0.1 -p 7000 -a 123456
127.0.0.1:7000> get a1
-> Redirected to slot [7785] located at 127.0.0.1:7001
(nil)
127.0.0.1:7001> set a1 12
OK
127.0.0.1:7001> get a1
"12"
127.0.0.1:7001>
127.0.0.1:7002> get a1
-> Redirected to slot [7785] located at 127.0.0.1:7001
(nil)
127.0.0.1:7001> get b1
-> Redirected to slot [2874] located at 127.0.0.1:7000
(nil)
127.0.0.1:7000> set a1 12
-> Redirected to slot [7785] located at 127.0.0.1:7001
OK
127.0.0.1:7001> get a1
"12"
127.0.0.1:7001>