Redis master-slave collocation

Master-slave concept

  • A master can have multiple slaves, and a slave can have multiple slaves. In this way, a strong multi-level server cluster architecture is formed
  • The master is used to write data, and the slave is used to read data. According to statistics, the read-write ratio of the website is 10: 1
  • Through the master-slave configuration can achieve read and write separation

       

  • master and slave are both a redis instance (redis service)

Master-slave configuration

Assignee

View the IP address of the current host

ifconfig

Modify /etc/redis.conffile

sudo came redis.conf 
bind 192.168 . 195,128

Restart the redis service

sudo service redis stop
redis-server redis.conf

Configuration from

Copy /etc/redis.conffile

sudo  cp redis.conf ./slave.conf

Modify redis/slave.conffile

sudo vim slave.conf

Edit content

bind 192.168.195.128
slaveof 192.168.195.128 6379
port 6378

redis service

sudo redis-server slave.conf

View master-slave relationship

redis-cli -h 192.168.195.128 info Replication

Data manipulation

Run the info command on the master and slave respectively to view the output information and enter the master client

redis-cli -h 192.168.195 . 128 -p 6379

Enter the client from

redis-cli -h 192.168 . 195.128 -p 6378

Write data on master

set aa aa

Read data on slave

get aa

 

Guess you like

Origin www.cnblogs.com/tracydzf/p/12678132.html
Recommended