• redis(3)主从与集群


    一、主从架构

    yum安装的redis

    cd /etc/
    cp redis.conf /etc/slave.conf
    vim slave.conf
        bind 192.168.42.7
        slaveof 192.168.42.7 6379
        port 6380
    [root@localhost etc]# systemctl restart redis   重启redis
    [root@localhost etc]# ps -ef | grep 'redis'       查看进程
    redis     13055      1  0 06:18 ?        00:00:00 /usr/bin/redis-server 192.168.42.7:6379
    root      13059  12945  0 06:18 pts/0    00:00:00 grep --color=auto redis
    [root@localhost etc]# redis-server slave.conf    启动slave。conf
    [root@localhost etc]# ps -ef | grep 'redis'
    redis     13055      1  0 06:18 ?        00:00:00 /usr/bin/redis-server 192.168.42.7:6379
    root      13061      1  0 06:19 ?        00:00:00 redis-server 192.168.42.7:6380
    root      13067  12945  0 06:19 pts/0    00:00:00 grep --color=auto redis
    
    主节点执行更新操作,从节点会有相应的备份;从节点只可读(readonly),不能添加数据。

    二、集群

    mkdir conf

    #!/bin/bash
    for i in `seq 6`
    do
            touch 700$i.conf
    done
    创建6个redis配置文件
    vim 7001.conf    #修改配置文件
    port 7001            #绑定端口
    bind 192.168.42.7   绑定对外连接提供的ip
    daemonize yes       #开启守护进程
    pidfile 7001.pid       #进程文件名
    cluster-enabled yes     #是否是集群
    cluster-config-file 7001_node.conf    #集群配置文件
    cluster-node-timeout 15000       集群连接超时时间
    appendonly yes    #数据持久化类型
    #!/bin/bash
    for i in `seq 6`
    do
            redis-server 700$i.conf
    done
    开启配置文件脚本
    redis-cli --cluster create 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 127.0.0.1:7007 127.0.0.1:7008 --cluster-replicas 1
    [root@localhost ~]# redis-cli -p 7001 -c -h 192.168.42.7
    192.168.42.7:7001> keys *
    (empty list or set)
    192.168.42.7:7001> set username jamhsiao
    -> Redirected to slot [14315] located at 192.168.42.7:7003                                              成功
    OK
    192.168.42.7:7003> set name momo
    -> Redirected to slot [5798] located at 192.168.42.7:7002
    OK
  • 相关阅读:
    Uboot命令使用
    git删除某次提交
    chrome随意改变主题
    C++11——处理日期和时间的chrono库
    C++11——多线程异步操作
    C++11——原子变量
    C++11——C++线程同步之条件变量
    C++11——C++线程同步之互斥锁
    C++11——call_once
    C++11——命名空间
  • 原文地址:https://www.cnblogs.com/daisyyang/p/10877572.html
Copyright © 2020-2023  润新知