验证redis的主从复制



    1.1 修改配置文件
        [root@ractdg3 redis-2.8.4]# cp redis.conf redis_master.conf
        [root@ractdg3 redis-2.8.4]# cp redis.conf redis_slave.conf
        [root@ractdg3 redis-2.8.4]# vi redis_slave.conf

        从属服务器设置端口及主服务器端口:

         port 6380
         slaveof localhost 6379

    1.2 启动主从服务器:
        [root@ractdg3 redis-2.8.4]# src/redis-server redis_master.conf &
        [root@ractdg3 redis-2.8.4]# src/redis-server redis_slave.conf &
        [2] 32729
        [root@ractdg3 redis-2.8.4]# [32729] 23 Jan 10:05:33.496 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now.
                                        _._                                                  
                             _.-``__ ''-._                                             
                    _.-``    `.  `_.  ''-._           Redis 2.8.4 (00000000/0) 32 bit
            .-`` .-```.  ```\/    _.,_ ''-._                                   
         (    '      ,       .-`  | `,    )     Running in stand alone mode
         |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6380
         |    `-._   `._    /     _.-'    |     PID: 32729
            `-._    `-._  `-./  _.-'    _.-'                                   
         |`-._`-._    `-.__.-'    _.-'_.-'|                                  
         |    `-._`-._        _.-'_.-'    |           http://redis.io        
            `-._    `-._`-.__.-'_.-'    _.-'                                   
         |`-._`-._    `-.__.-'    _.-'_.-'|                                  
         |    `-._`-._        _.-'_.-'    |                                  
            `-._    `-._`-.__.-'_.-'    _.-'                                   
                    `-._    `-.__.-'    _.-'                                       
                            `-._        _.-'                                           
                                    `-.__.-'                                               

        [32729] 23 Jan 10:05:33.498 # Server started, Redis version 2.8.4
        [32729] 23 Jan 10:05:33.499 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
        [32729] 23 Jan 10:05:33.500 * DB loaded from disk: 0.001 seconds
        [32729] 23 Jan 10:05:33.500 * The server is now ready to accept connections on port 6380
        [32729] 23 Jan 10:05:34.495 * Connecting to MASTER localhost:6379
        [32729] 23 Jan 10:05:34.498 * MASTER <-> SLAVE sync started
        [32729] 23 Jan 10:05:34.498 * Non blocking connect for SYNC fired the event.
        [32729] 23 Jan 10:05:34.498 * Master replied to PING, replication can continue...
        [32729] 23 Jan 10:05:34.499 * Partial resynchronization not possible (no cached master)
        [32726] 23 Jan 10:05:34.500 * Slave asks for synchronization
        [32726] 23 Jan 10:05:34.500 * Full resync requested by slave.
        [32726] 23 Jan 10:05:34.500 * Starting BGSAVE for SYNC
        [32729] 23 Jan 10:05:34.500 * Full resync from master: 9a6eceefa217f57f5a9c99e6af494a997b871d47:1
        [32726] 23 Jan 10:05:34.503 * Background saving started by pid 32735
        [32735] 23 Jan 10:05:34.511 * DB saved on disk
        [32735] 23 Jan 10:05:34.512 * RDB: 0 MB of memory used by copy-on-write
        [32726] 23 Jan 10:05:34.585 * Background saving terminated with success
        [32726] 23 Jan 10:05:34.586 * Synchronization with slave succeeded
        [32729] 23 Jan 10:05:34.586 * MASTER <-> SLAVE sync: receiving 675 bytes from master
        [32729] 23 Jan 10:05:34.587 * MASTER <-> SLAVE sync: Flushing old data
        [32729] 23 Jan 10:05:34.587 * MASTER <-> SLAVE sync: Loading DB in memory
        [32729] 23 Jan 10:05:34.588 * MASTER <-> SLAVE sync: Finished with success

        [root@ractdg3 redis-2.8.4]# ps aux|grep redis
        root     32726  0.0  0.0  33820  1948 pts/3    Sl   10:05   0:00 src/redis-server *:6379           
        root     32729  0.1  0.0  33868  2004 pts/3    Sl   10:05   0:00 src/redis-server *:6380          
        root     32740  0.0  0.0   4264   696 pts/3    S+   10:05   0:00 grep redis
        [root@ractdg3 redis-2.8.4]#

    1.3 在主服务器赋值
    [oracle@ractdg3 src]$ telnet localhost 6379
    Trying 127.0.0.1...
    Connected to localhost.localdomain (127.0.0.1).
    Escape character is '^]'.
    rpush data 1
    :1
    lrange data 0 -1
    *1
    $1
    1

    set name tang
    +OK
    get name
    $4
    tang


    1.4 在从服务器测试数据


        [root@ractdg3 redis-2.8.4]# telnet localhost 6380
    Trying 127.0.0.1...
    Connected to localhost.localdomain (127.0.0.1).
    Escape character is '^]'.
    [32726] 23 Jan 10:49:56.273 * 1 changes in 900 seconds. Saving...
    [32729] 23 Jan 10:49:56.273 * 1 changes in 900 seconds. Saving...
    [32729] 23 Jan 10:49:56.327 * Background saving started by pid 1185
    [32726] 23 Jan 10:49:56.333 * Background saving started by pid 1184
    [1184] 23 Jan 10:49:56.344 * DB saved on disk
    [1185] 23 Jan 10:49:56.344 * DB saved on disk
    [1184] 23 Jan 10:49:56.346 * RDB: 0 MB of memory used by copy-on-write
    [1185] 23 Jan 10:49:56.347 * RDB: 0 MB of memory used by copy-on-write
    [32729] 23 Jan 10:49:56.429 * Background saving terminated with success
    [32726] 23 Jan 10:49:56.433 * Background saving terminated with success
    lrange data 0 -1
    *1
    $1
    1

    get name
    $4
    tang

    可以看到,数据已在从服务器中访问成功。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值