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