一、主从架构
yum安装的redis
cd /etc/ cp redis.conf /etc/slave.conf vim slave.conf bind 192.168.42.7 slaveof 192.168.42.7 6379 port 6380 [root@localhost etc]# systemctl restart redis 重启redis [root@localhost etc]# ps -ef | grep 'redis' 查看进程 redis 13055 1 0 06:18 ? 00:00:00 /usr/bin/redis-server 192.168.42.7:6379 root 13059 12945 0 06:18 pts/0 00:00:00 grep --color=auto redis [root@localhost etc]# redis-server slave.conf 启动slave。conf [root@localhost etc]# ps -ef | grep 'redis' redis 13055 1 0 06:18 ? 00:00:00 /usr/bin/redis-server 192.168.42.7:6379 root 13061 1 0 06:19 ? 00:00:00 redis-server 192.168.42.7:6380 root 13067 12945 0 06:19 pts/0 00:00:00 grep --color=auto redis 主节点执行更新操作,从节点会有相应的备份;从节点只可读(readonly),不能添加数据。
二、集群
mkdir conf
#!/bin/bash for i in `seq 6` do touch 700$i.conf done
vim 7001.conf #修改配置文件 port 7001 #绑定端口 bind 192.168.42.7 绑定对外连接提供的ip daemonize yes #开启守护进程 pidfile 7001.pid #进程文件名 cluster-enabled yes #是否是集群 cluster-config-file 7001_node.conf #集群配置文件 cluster-node-timeout 15000 集群连接超时时间 appendonly yes #数据持久化类型
#!/bin/bash for i in `seq 6` do redis-server 700$i.conf done
redis-cli --cluster create 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 127.0.0.1:7007 127.0.0.1:7008 --cluster-replicas 1
[root@localhost ~]# redis-cli -p 7001 -c -h 192.168.42.7 192.168.42.7:7001> keys * (empty list or set) 192.168.42.7:7001> set username jamhsiao -> Redirected to slot [14315] located at 192.168.42.7:7003 成功 OK 192.168.42.7:7003> set name momo -> Redirected to slot [5798] located at 192.168.42.7:7002 OK