不积跬步,无以至千里;不积小流,无以成江海。

redis 主从配置

redis 主从配置

一个redis需要一个配置文件:
	redis.conf 改动:
		端口号
		log名
		
用配置文件redis.conf启动一个redis:
#redis-server kconfig/redis.conf
用配置文件redis1.conf启动一个redis:
#redis-server kconfig/redis1.conf
用配置文件redis2.conf启动一个redis:
#redis-server kconfig/redis2.conf

连接客户端:
在redis-server启动之后
#redis-cli -p 6379
查看主从信息:
#info replication

使用从机:
#redis-cli -p 6380
#info replication
#SLAVEOF 127.0.0.1 6379					//认ip地址为127.0.0.1端口号为6379的redis为老大

再用info replacation 查看 就会发现主机从机配置

!!!命令行配置只是暂时的。永久配置需要在配置文件中配置:搜索replication就能找到。
哨兵模式:redis-sentinel
主机挂了,哨兵投票把其中一个从机变成主机。原来的主机重连,自动变为从机
1.配置哨兵配置文件sentinel.conf
#vim sentinel.conf

配置文件内容:
# sentinel monitor 被监控的名称 host port 1
  sentinel monitor myredis 127.0.0.1 6379 1
  
  后面这个数字1,可以当成票数

如果有哨兵集群,还要配置端口port

posted @ 2021-06-08 16:53  |是吴啊|  阅读(249)  评论(0编辑  收藏  举报