zoukankan      html  css  js  c++  java
  • linux环境下Redis主从复制和集群环境搭建

    Redis主从复制环境搭建

    主服务器为:6380
    从服务器分别为 6382 和6384
    先将redis进程关掉
    进入redis-5.0.2目录下,
    输入# cp.redis.conf redis6380.conf(复制文件)
    #> redis6380.conf(清空文件)
    #cat redis6380.conf(查看文件信息)
    #cp redis6380.conf redis6382.conf()
    #cp redis6380.conf redis6384.conf
    然后输入#ll(查看详情列表)
    在redis下查看信息是否存在#ll /usr/local/redis-5.0.2/redis.conf

    #vim redis6380.conf(修改信息)
    master的配置文件如下:
    include /usr/local/redis-5.0.2/redis.conf
    daemonize yes
    port 6380
    pidfile /var/run/redis_6380.pid
    logfile 6380.log
    dbfilename dump6380.rdb

    #vim redis6382.conf
    从服务器配置如下:
    include /usr/local/redis-5.0.2/redis.conf
    daemonize yes
    port 6382
    pidfile /var/run/redis_6382.pid
    logfile 6382.log
    dbfilename dump6382.rdb
    slaveof 127.0.0.1 6380

    #vim redis6384.conf

    从服务器配置如下:

    include /usr/local/redis-5.0.2/redis.conf
    daemonize yes
    port 6384
    pidfile /var/run/redis_6384.pid
    logfile 6384.log
    dbfilename dump6384.rdb
    slaveof 127.0.0.1 6380
    配置完了之后
    进入#cd src/
    #ls
    开始启动redis服务器
    # ./redis-server ../redis6380.conf (chmod a+x ./redis-server ../redis6380.conf)
    # ./redis-server ../redis6382.conf
    # ./redis-server ../redis6384.conf
    # ps -ef |grep redis(查看redis三个进程是否启动成功)
    #ls
    # ./redis-cli -p 6380(连接到6380)
    # info replication(查看redis服务器端的关系信息的)
    #flushdb(清空数据)
    (此时从服务器只能读 不能写入)
    当主服务出现故障时
    将其中一台从服务
    127.0.0.1:6382> salveof no one将其设置为主
    将另一台从服务 挂到新的主服务上
    127.0.0.1:6384> slaveof 127.0.0.1 6382

     哨兵环境搭建

     在主从复制环境的基础上 继续完成哨兵模式的搭建

    [root@localhost redis]# vim sentinel.conf(查看配置信息)
    cp sentinel.conf sentinel26380.conf 共复制三份
    cp sentinel.conf sentinel26382.conf
    cp sentinel.conf sentinel26384.conf

    然后再改端口号和主redis运行的端口
    改第一个哨兵
    [root@localhost redis]# vim sentinel26380.conf(修改配置文件)
    将port改为26380
    sentinel monitor mymaster 127.0.0.1 6382 2 (改成要监控的主redis)
    改第二个哨兵
    [root@localhost redis]# vim sentinel26382.conf
    将port改成26382
    sentinel monitor mymaster 127.0.0.1 6382 2
    改第三个哨兵
    [root@localhost redis]# vim sentinel26384.conf
    将port改成26384
    sentinel monitor mymaster 127.0.0.1 6382 2

    [root@localhost redis]# cd src
    [root@localhost src]# ./redis-sentinel ../sentinel26380.conf
    再重新开两个窗口分别开启另外两个哨兵
    将主redis shutdown掉
    哨兵会自动会选择一个性能较好的从服务做为主服务器
    能实现自动处理故障功能

  • 相关阅读:
    Linux写时拷贝技术(copy-on-write)
    crontab使用进程锁解决冲突
    Better Linux Disk Caching & Performance with vm.dirty_ratio & vm.dirty_background_ratio
    精确度量Linux下进程占用多少内存的方法
    在Linux系统的服务器上使用Memtester进行内存压力测试
    How to speed up insertion performance in PostgreSQL
    Mongo的备份和恢复(mongodump 和mongorestore )
    MongoDB:删除操作
    MongoDB插入数据的3种方法
    Centos 软连接和硬链接
  • 原文地址:https://www.cnblogs.com/belongszhouli/p/11288161.html
Copyright © 2011-2022 走看看