Brief introduction of Master-slave configuration of Redis database

Source: Internet
Author: User
Tags redis

Copy configuration file

[Root@yum-down ~]# cd/etc/redis/
[Root@yum-down redis]# CP 6379.conf 6380.conf

Modify the port, and the data file name, or save location can be ' dir '

[Root@yum-down redis]# Vim 6380.conf
:%s/6379/6380/g
Appendfilename "Appendonly6380.aof"
[Root@yum-down redis]# diff 6379.conf 6380.conf
46c46
< Pidfile/var/run/redis_6379.pid
---
> Pidfile/var/run/redis_6380.pid
48c48
< # Accept connections on the specified port, default is 6379.
---
> # Accept connections on the specified port, default is 6380.
50c50
< port 6379
---
> Port 6380
182c182
< Dbfilename Dump_6379.rdb
---
> Dbfilename Dump_6380.rdb
645c645
< # Cluster-config-file nodes-6379.conf
---
> # cluster-config-file nodes-6380.conf
[Root@yum-down redis]#

Start:
[

Root@yum-down redis]# cd/etc/redis/
[Root@yum-down ~]#/usr/local/redis/bin/redis-server/etc/redis/6380.conf
[Root@yum-down ~]# redis-cli-h 10.10.0.250-p 6380

After we info, we found that the default two machines are master. 6379 changed from

# Replication
Role:master
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@yum-down redis]# NETSTAT-NTLP |grep 6380
TCP 0 0 0.0.0.0:6380 0.0.0.0:* LISTEN 2315/redis-server
TCP 0 0::: 6380:::* LISTEN 2315/redis-server
[Root@yum-down redis]# NETSTAT-NTLP |grep 6379
TCP 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 2293/redis-server
TCP 0 0::: 6379:::* LISTEN 2293/redis-server
[Root@yum-down redis]#

On the server, that is, 6379, to modify itself from, this command can still be written in the configuration file
Typically,,127.0.0.1:6379> config get * config take * can reset the configuration online

127.0.0.1:6379> slaveof 10.10.0.250 6380
Ok
127.0.0.1:6379> Info
# Replication
Role:slave
master_host:10.10.0.250
master_port:6380
Master_link_status:up
Master_last_io_seconds_ago:1
master_sync_in_progress:0
Slave_repl_offset:1
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

View in the Lord:

10.10.0.250:6380> Info
# Replication
Role:master
Connected_slaves:1
Slave0:ip=10.10.0.250,port=6379,state=online,offset=15,lag=1
Master_repl_offset:15
Repl_backlog_active:1
repl_backlog_size:1048576
Repl_backlog_first_byte_offset:2
Repl_backlog_histlen:14

Insert Test in our Lord:

10.10.0.250:6380> Set Key1 Linuxea
Ok
10.10.0.250:6380> Get Key1
"Linuxea"
10.10.0.250:6380>
To view from:

127.0.0.1:6379> Get Key1
"Linuxea"
127.0.0.1:6379>

Starting from redis2.6, copying is read-only and supports master-slave smoothing upgrades
Because itself Redis single-threaded, support a CPU, in a large number of data, fragmentation may be a good solution

Redis will RDB transfer from the implementation of master-slave copying, copying there are many from, star-like form
When the establishment of a server from the server will send SYN to the main server, the main received SYN after the background to perform bgsave, and then the saved Rdb file sent from the server, received from the server loaded into memory, a synchronous completion.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.