zoukankan      html  css  js  c++  java
  • redis_cluster搭建

    我这边准备三台机器

    IP:10.0.0.11   port:7000、7001

    IP:10.0.0.12   port:7000、7001

    IP:10.0.0.13   port:7000、7001

    1、关闭三台服务器的防火墙和selinux,三台机器都执行此操作

    [root@localhost ~]# systemctl stop firewalld
    [root@localhost ~]# setenforce 0
    

    2、将redis源码包上传到三台服务器

    [root@localhost ~]# ls
    anaconda-ks.cfg  redis-5.0.6.tar.gz
    

    3、三台服务器都执行此操作,安装依赖包并解压redis安装包,进行编译安装

    [root@localhost ~]# tar -zxvf redis-5.0.6.tar.gz 
    [root@localhost ~]# cd redis-5.0.6
    [root@localhost redis-5.0.6]# make MALLOC=libc
    [root@localhost redis-5.0.6]# make PREFIX=/root/redis/ install
    [root@localhost redis-5.0.6]# cd 
    [root@localhost ~]# ls
    anaconda-ks.cfg  redis  redis-5.0.6  redis-5.0.6.tar.gz
    [root@localhost ~]# cd redis
    [root@localhost redis]# mkdir 7000 7001
    [root@localhost redis]# ls
    7000  7001  bin
    [root@localhost redis]# cd ../redis-5.0.6/
    [root@localhost redis-5.0.6]# cp redis.conf /root/redis/
    root@localhost redis-5.0.6]# cd ../redis/
    [root@localhost redis]# ls
    7000  7001  bin  redis.conf
    [root@localhost redis]# mv redis.conf redis_7000.conf
    [root@localhost redis]# cp redis_7000.conf redis_7001.conf
    [root@localhost redis]# ls
    7000  7001  bin  redis_7000.conf  redis_7001.conf
    

    4、修改redis配置文件,三台服务器上redis文件均要修改

    bind 10.0.0.11    #哪个配置文件就改哪个IP
    port 7000   #哪个配置文件就改哪个端口
    daemonize yes
    pidfile /var/run/redis_7000.pid 
    dir /root/redis/7000/
    logfile "/root/redis/7000/redis_7000.log"
    cluster-enabled yes
    

    5、启动每个节点的redis服务

    [root@localhost redis]# cd bin/
    [root@localhost bin]# ./redis-server /root/redis/redis_7000.conf [root@localhost bin]# ./redis-server /root/redis/redis_7001.conf [root@localhost bin]# ps -ef |grep redis root 19155 1 0 18:25 ? 00:00:00 ./redis-server 10.0.0.11:7000 [cluster] root 19162 1 0 18:26 ? 00:00:00 ./redis-server 10.0.0.11:7001 [cluster] root 19167 7861 0 18:26 pts/0 00:00:00 grep --color=auto redis

    6、在其中一台服务器中安装ruby,然后进入到redis源码存放目录redis/redis-5.0.6/src下./redis-cli 

    [root@localhost ~]# yum -y install ruby
    [root@localhost ~]# cd redis-5.0.6/src/
    [root@localhost src]# ./redis-cli --cluster create 10.0.0.11:7000 10.0.0.11:7001 10.0.0.12:7000 10.0.0.12:7001 10.0.0.13:7000 10.0.0.13:7001
    >>> Performing hash slots allocation on 6 nodes...
    Master[0] -> Slots 0 - 2730
    Master[1] -> Slots 2731 - 5460
    Master[2] -> Slots 5461 - 8191
    Master[3] -> Slots 8192 - 10922
    Master[4] -> Slots 10923 - 13652
    Master[5] -> Slots 13653 - 16383
    M: 299344da6a3cf5dba9a4c42e8541dae1f900ae64 10.0.0.11:7000
       slots:[0-2730] (2731 slots) master
    M: 01ce403147d54cd0e63da073e51318ead5114afd 10.0.0.11:7001
       slots:[8192-10922] (2731 slots) master
    M: a29369f73dcc9e742acf241970e5c6fe6b23869c 10.0.0.12:7000
       slots:[2731-5460] (2730 slots) master
    M: 26d8990e4aa3950b1cefabb004f7cd34503842e1 10.0.0.12:7001
       slots:[10923-13652] (2730 slots) master
    M: 3936a03e33fb9555f98d9465fb7d78668c8d11bd 10.0.0.13:7000
       slots:[5461-8191] (2731 slots) master
    M: 06ac58061b7a08a1f94be06f5c274538c91096cb 10.0.0.13:7001
       slots:[13653-16383] (2731 slots) maste
    Can I set the above configuration? (type 'yes' to accept): yes
    >>> Nodes configuration updated
    >>> Assign a different config epoch to each node
    >>> Sending CLUSTER MEET messages to join the cluster
    Waiting for the cluster to join
    ......
    >>> Performing Cluster Check (using node 10.0.0.11:7000)
    M: 299344da6a3cf5dba9a4c42e8541dae1f900ae64 10.0.0.11:7000
       slots:[0-2730] (2731 slots) master
    M: 26d8990e4aa3950b1cefabb004f7cd34503842e1 10.0.0.12:7001
       slots:[10923-13652] (2730 slots) master
    M: a29369f73dcc9e742acf241970e5c6fe6b23869c 10.0.0.12:7000
       slots:[2731-5460] (2730 slots) master
    M: 01ce403147d54cd0e63da073e51318ead5114afd 10.0.0.11:7001
       slots:[8192-10922] (2731 slots) master
    M: 3936a03e33fb9555f98d9465fb7d78668c8d11bd 10.0.0.13:7000
       slots:[5461-8191] (2731 slots) master
    M: 06ac58061b7a08a1f94be06f5c274538c91096cb 10.0.0.13:7001
       slots:[13653-16383] (2731 slots) master
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
    

    7、查看一下redis_cluster集群是否创建

    [root@localhost src]# netstat -antup|grep redis
    tcp        0      0 10.0.0.11:17000         0.0.0.0:*               LISTEN      19155/./redis-serve 
    tcp        0      0 10.0.0.11:17001         0.0.0.0:*               LISTEN      19162/./redis-serve 
    tcp        0      0 10.0.0.11:7000          0.0.0.0:*               LISTEN      19155/./redis-serve 
    tcp        0      0 10.0.0.11:7001          0.0.0.0:*               LISTEN      19162/./redis-serve 
    tcp        0      0 10.0.0.11:33980         10.0.0.12:17001         ESTABLISHED 19155/./redis-serve 
    tcp        0      0 10.0.0.11:17000         10.0.0.12:35492         ESTABLISHED 19155/./redis-serve 
    tcp        0      0 10.0.0.11:43739         10.0.0.11:17001         ESTABLISHED 19155/./redis-serve 
    tcp        0      0 10.0.0.11:41849         10.0.0.13:17001         ESTABLISHED 19162/./redis-serve 
    tcp        0      0 10.0.0.11:17001         10.0.0.11:43739         ESTABLISHED 19162/./redis-serve 
    tcp        0      0 10.0.0.11:17001         10.0.0.13:39088         ESTABLISHED 19162/./redis-serve 
    tcp        0      0 10.0.0.11:38376         10.0.0.12:17000         ESTABLISHED 19155/./redis-serve 
    tcp        0      0 10.0.0.11:17000         10.0.0.13:35282         ESTABLISHED 19155/./redis-serve 
    tcp        0      0 10.0.0.11:17001         10.0.0.12:43253         ESTABLISHED 19162/./redis-serve 
    tcp        0      0 10.0.0.11:38490         10.0.0.13:17001         ESTABLISHED 19155/./redis-serve 
    tcp        0      0 10.0.0.11:37877         10.0.0.13:17000         ESTABLISHED 19155/./redis-serve 
    tcp        0      0 10.0.0.11:17001         10.0.0.12:35505         ESTABLISHED 19162/./redis-serve 
    tcp        0      0 10.0.0.11:17000         10.0.0.12:42925         ESTABLISHED 19155/./redis-serve 
    tcp        0      0 10.0.0.11:45274         10.0.0.13:17000         ESTABLISHED 19162/./redis-serve 
    tcp        0      0 10.0.0.11:17000         10.0.0.11:39136         ESTABLISHED 19155/./redis-serve 
    tcp        0      0 10.0.0.11:17001         10.0.0.13:36414         ESTABLISHED 19162/./redis-serve 
    tcp        0      0 10.0.0.11:17000         10.0.0.13:42254         ESTABLISHED 19155/./redis-serve 
    tcp        0      0 10.0.0.11:37559         10.0.0.12:17001         ESTABLISHED 19162/./redis-serve 
    tcp        0      0 10.0.0.11:33997         10.0.0.12:17000         ESTABLISHED 19162/./redis-serve 
    tcp        0      0 10.0.0.11:39136         10.0.0.11:17000         ESTABLISHED 19162/./redis-serve 

    整个redis_cluster集群创建完毕

  • 相关阅读:
    良好的三元组(求已排列好的数组中各个元素的排位)
    山理工oj 2556传说中的数据结构
    山理oj 1177 时间间隔
    山理oj1525:字符统计2
    linux常用命令
    多线程并发教程
    合理设置线程数量
    Java多线程处理任务(摘抄)
    解决2013Lost connection to MySQL server during query错误方法
    javaMail邮件发送
  • 原文地址:https://www.cnblogs.com/Zrecret/p/14107469.html
Copyright © 2011-2022 走看看