Redis 集群构建 02主从复制

Last Day, We installed redis, you can make it sure by using the command

/opt/redis/bin/redis-cli -p 6379 info

There’re so many informations listed. Be patient, we’re going to talk about it later.

OK, you can go to the http://redis.io/commands (http://redis.codeplanter.com is faster!!) to check all the data structure supported
and the proper commands for each type. It may takes you a lot of time to get familiar to
these commands, but, don’t worry about that, we can learn when we need,
just remember the web address is fine.

Today, we’re going to build a master-slave structure, which the slave will auto sync the
data that changed of the master.

First, Copy config file and reconfig.

Go to the redis etc path copy the config a new one

cd /opt/redis/etc/
cp redis.conf redis_slave.conf

and reconfig the new one, pay attention to the following params:

daemonize yes
pidfile /data/redis/run/redis_7379.pid
port 7379
logfile “/opt/redis/log/redis-7379.log”
dbfilename dump_7379.rdb
dir /data/redis/data/redis_7379/
slaveof 127.0.0.1 6379  # add a new one to make this redis instance a slave of 127.0.0.1:6379

create a new path

mkdir -p /opt/redis/data/redis_7379

Second, Start the new redis instance.

start this redis instance with the bash command yesterday:

/opt/redis/bin/redis.sh 7379

Third, Check If M-S works.

write something into redis master:

/opt/redis/bin/redis-cli -p 6379 set s_server “new ms server”

read from redis slave:

/opt/redis/bin/redis-cli -p 7379 get s_server

if you get “new ms server” returned, congratulations!

So, do some more test yourself~

Donate - Support to make this site better.
捐助 - 支持我让我做得更好.