Redis Master-Slave configuration

Source: Internet
Author: User

One, Redis installation

$ wget http://download.redis.io/releases/redis-2.8.17.tar.gz

$ tar xzf redis-2.8.17.tar.gz

$ CD redis-2.8.17

$ make

Second, Redis boot

$CD redis-2.8.17

$src/redis-server./redis.conf #启动redis

Or

$src/redis-server./redis.conf & #后台启动

Third, master-slave configuration

1. Copy redis-2.8.17 folder

$CP-R redis-2.8.17./redis-slave

2, set two folder directory for Redis-master and Redis-slave

3, Configuration Redis-master

Daemonize Yes #是否以后台进程运行, default to No

Requirepass Master-password #连接密码

Pidfile/var/run/redis.pid #如以后台进程运行, you need to specify a PID, which defaults to/var/run/redis.pid

Port 6379 #主服务器端口, default value

Dbfilename Dumpmaster.rdb #本地数据库文件名, default value is Dump.rdb

Dir./#本地数据库存放路径, the default value is./

4, Configuration Redis-slave

Daemonize Yes

Requirepass Slave-password

Pidfile/var/run/redis.pid

slaveof 127.0.0.1 6379 #当本机为从服务时, set the IP and port of the primary service

Masterauth Master-password #当本机为从服务时, set the connection password for the primary service

Port 7000 #设定从服务器端口

Dbfilename Dumpslave.rdb

Dir./

5. Start the master-slave service separately

$CD Redis-master

$src/redis-server./redis.conf

$CD Redis-slave

$src/redis-server./redis.conf

6. Connect two Redis servers to add a delete key to the primary database to see if any changes have been made in the slave database

7. Recovering from database data to the master database

Suppose Redis-master and Redis-slave are in the same directory as the same server

$redis-cli #查看主服务器是否能连上

$auth Master-password #登入

$shutdown #关掉服务

$CD Redis-master

$MV Dump.rdb Dump_bak.rdb #备份主数据库

$CP: /redis-slave/dumpslave.rdb./dumpmaster.rdb

$src/redis-server./redis.conf #重启master服务

Attention:

When the primary database is hung, do not start the primary server again, you should restore the data from the server to the master database before booting.

Since the main server hangs, such as the data is not, if started immediately, then the data from the server will be emptied,

The master-slave relationship backup does not make sense.

Redis Master-Slave configuration

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.