在项目中部署redis的读写分离架构(包含节点间认证口令)

#### 在项目中部署redis的读写分离架构(包含节点间认证口令) ##### 1、配置过程 ---  1、此前就是已经将redis在系统中已经安装好了,redis utils目录下,有个redis_init_script脚本,将redis_init_script脚本拷贝到linux的/etc/init.d目录中,将redis_init_script重命名为redis_6379,6379是我们希望这个redis实例监听的端口号
 2、创建两个目录:/etc/redis(存放redis的配置文件),/var/redis/6379(存放redis的持久化文件)
 3、修改redis配置文件(默认在根目录下,redis.conf),拷贝到/etc/redis目录中,修改名称为6379.conf
![image](https://img2018.cnblogs.com/blog/1334966/201910/1334966-20191013202746574-928757649.jpg)  4、此时修改redis中的redis.conf也就是
![image](https://img2018.cnblogs.com/blog/1334966/201910/1334966-20191013202746800-26558432.png)  5、修改redis.conf中的部分配置为生产环境
  (1)、daemonize yes 让redis以daemon进程运行
![image](https://img2018.cnblogs.com/blog/1334966/201910/1334966-20191013202746974-13745215.png)   (2)、pidfile /var/run/redis_6379.pid 设置redis的pid文件位置
![image](https://img2018.cnblogs.com/blog/1334966/201910/1334966-20191013202747175-403089801.png)   (3)、port 6379 设置redis的监听端口号
![image](https://img2018.cnblogs.com/blog/1334966/201910/1334966-20191013202747391-1577967999.png)   (4)、dir /var/redis/6379 设置持久化文件的存储位置
![image](https://img2018.cnblogs.com/blog/1334966/201910/1334966-20191013202747567-608090087.png) 6、在redis_6379脚本中,最上面,加入两行注释 ``` # chkconfig: 2345 90 10 # description: Redis is a persistent key-value database ``` ![image](https://img2018.cnblogs.com/blog/1334966/201910/1334966-20191013202747742-678423174.png) 7、chkconfig redis_6379 on
8、配置主从
(1)、在从机上进行配置 在slave node上配置:slaveof 192.168.1.1 6379,即可
######   replicaof <主机IP> <主机端口> ![image](https://img2018.cnblogs.com/blog/1334966/201910/1334966-20191013202748220-775105999.png) (2)、开启只读模式
######   replica-read-only yes ![image](https://img2018.cnblogs.com/blog/1334966/201910/1334966-20191013202748454-2135785897.png) (3)、配置从机链接主机的口令 ######   masterauth redis ![image](https://img2018.cnblogs.com/blog/1334966/201910/1334966-20191013202748615-1803917487.png) (4)、配置主从机的bind地址 ######   bind 192.168.1.124 (主机) ######   bind 192.168.1.125 (从机) ![image](https://img2018.cnblogs.com/blog/1334966/201910/1334966-20191013202748776-513750171.png) (5)、配置主机的连接口令 ######   requirepass redis ![image](https://img2018.cnblogs.com/blog/1334966/201910/1334966-20191013202749212-1774686242.png) (6)、启动主机与从机的redis ![image](https://img2018.cnblogs.com/blog/1334966/201910/1334966-20191013202749447-1449710327.png) ![image](https://img2018.cnblogs.com/blog/1334966/201910/1334966-20191013202749623-292690922.png) (7)、连接主机与从机的redis
######  主机 ![image](https://img2018.cnblogs.com/blog/1334966/201910/1334966-20191013202749787-635850359.png) ######  从机 ![image](https://img2018.cnblogs.com/blog/1334966/201910/1334966-20191013202749987-1840323202.png) (8)、测试主机加K - V ![image](https://img2018.cnblogs.com/blog/1334966/201910/1334966-20191013202750159-1779035533.png) (9)、在从机查询 ![image](https://img2018.cnblogs.com/blog/1334966/201910/1334966-20191013202750327-1766680225.png) 帮忙关注一下 微信公众号一起学习 :chengxuyuan95(不一样的程序员)
posted @ 2019-10-13 20:28  雪中孤狼  阅读(282)  评论(0编辑  收藏  举报