Redis5.0.0安装部署[V1.0]2018年11月19日修订记录日期版本说明作者2018-11-19V1.0新建所有:增加集群模式安装部署配置张腾一、集群模式搭建(三主三从)1.1环境准备新建三台centos服务器,设置IP:192.168.148.100、192.168.148.101、192.168.148.102,安装部署图如下:三台服务器增加配置vi/etc/hosts192.168.148.100node100192.168.148.101node101192.168.148.102node102安装tclrpm-ivhtcl-8.5.13-8.el7.x86_64.rpm1.2服务安装cd/usr/localmkdirredis将redis-5.0.0.tar.gz上传到/usr/local/redistar-zxvfredis-5.0.0.tar.gzcdredis-5.0.0makemakeinstall1.3单机测试cd/usr/local/redis/redis-5.0.0/src./redis-server&redis-cli-h127.0.0.1-p6379setflightid123456getflightid1.4集群配置cd/usr/local/redismkdirredis-cluster-5.0.0cdredis-cluster-5.0.0mkdir7100mkdir7301规则:7ABB,A为主节点号,BB从节点号。BB为00时,ABB代表主节点,100:主节点1;BB不为00时,ABB代表从节点,101:主节点1的从01节点。cd/usr/local/redis/redis-5.0.0cpredis.conf/usr/local/redis/redis-cluster-5.0.0/7100cpredis.conf/usr/local/redis/redis-cluster-5.0.0/7301cd/usr/local/redis/redis-cluster-5.0.0/7100修改配置文件viredis.confdaemonizeyes//设置后台启动port7100//端口设置为文件夹名称bind192.168.148.100//绑定当前机器的IPdir/usr/local/redis/redis-cluster-5.0.0/7100//指定数据文件存放的位置,必须要指定不同的目录位置,不然会丢失数据cluster-enabledyes//启动集群模式cluster-config-filenodes-7100.conf//这里的数字最好和port对应cluster-node-timeout15000//集群超时时间appendonlyyes//开启快照模式保存后将该文件copy到其他节点目录,将黄色背景相关配置进行对应修改。1.5集群启动分别启动6个redis实例,检查是否启动成功/usr/local/redis/redis-5.0.0/src/redis-server/usr/local/redis/redis-cluster-5.0.0/60100/redis.confps-el|grepredisnetstat–tunpl|grepredis/usr/local/redis/redis-5.0.0/src/redis-cli--clustercreate192.168.148.100:7100192.168.148.101:7200192.168.148.102:7300192.168.148.101:7101192.168.148.102:7201192.168.148.100:7301--cluster-replicas1//–replicas1为主节点和从节点的比值;为1:主节点和从节点一致,2:主节点是从节点2倍;0.5主节点为从节点一半。总数为6,所以三主三从,按顺序,前面三个节点为主节点,后面三个为从节点,1和4,2和5,3和6对应查询集群状态/usr/local/redis/redis-5.0.0/src/redis-cli-c-h192.168.148.100-p7100clusternodes//查询集群状态clusterinfo//查看集群信息1.6集群关闭分别关闭三台机器上共计6个节点。/usr/local/redis/redis-5.0.0/src/redis-cli-c-h192.168.148.100-p7100shutdown