Redis主從複製簡單配置教程詳解

來源:互聯網
上載者:User

主從複製

192.168.1.106 master機器
mkdir -p /data/redis
cp /etc/redis/redis.conf /etc/redis/redis-6379.conf
vim /etc/redis/redis-6379.conf


daemonize yes
pidfile /var/run/redis-6379.pid
port 6379
logfile "6379.log"
dbfilename "dump-6379.rdb"
dir "/data/redis"
appendonly yes
appendfilename "appendonly-6379.aof"
 
192.168.1.107 slave機器
mkdir -p /data/redis
cp /etc/redis/redis.conf /etc/redis/redis-6381.conf
vim /etc/redis/redis-6381.conf


daemonize yes
pidfile /var/run/redis-6381.pid
port 6381
logfile "6381.log"
dbfilename "dump-6381.rdb"
dir "/data/redis"
appendonly yes
appendfilename "appendonly-6381.aof"
 
連從伺服器


[root@Slave redis]# redis-cli -p 6381
127.0.0.1:6381>
127.0.0.1:6381> dbsize
(integer) 0
127.0.0.1:6381> slaveof 192.168.1.106 6379
127.0.0.1:6381> get hello
"world"
127.0.0.1:6381> info replication
# Replication
role:slave
master_host:192.168.1.106
master_port:6379
master_link_status:up
master_last_io_seconds_ago:9
master_sync_in_progress:0
slave_repl_offset:773
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
 
[root@Slave redis]# redis-cli -p 6381
127.0.0.1:6381> slaveof 192.168.1.106 6379
127.0.0.1:6381> config rewrite

再配置一個從伺服器


[root@Slave redis]# cd /etc/redis/
[root@Slave redis]# ls
redis-6379.conf  redis-6381.conf
[root@Slave redis]# sed 's/6381/6382/g' redis-6381.conf > redis-6382.conf
[root@Slave redis]# redis-server /etc/redis/redis-6382.conf
[root@Slave redis]# redis-cli -p 6382
127.0.0.1:6382> get hello
"world"
127.0.0.1:6382> info replication
# Replication
role:slave
master_host:192.168.1.106
master_port:6379
master_link_status:up
master_last_io_seconds_ago:6
master_sync_in_progress:0
slave_repl_offset:3026
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
127.0.0.1:6382>
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.