CentOS Redis Master-Slave

Source: Internet
Author: User
Tags pkill

Environment Introduction

Master 192.168.1.28 CentOS 6.4 x64-bit system

Slave 192.168.1.80 CentOS 6.4 x64 bit system


##############################################

Redis is installed on 2 servers

Installing the Redis component Tcl

Tar zxvf tcl8.6.0-src.tar.gz-c/usr/src/

Cd/usr/src/tcl8.6.0/unix

./configure

Make && make install


Installing Redis

Tar zxvf redis-2.8.19.tar.gz-c/usr/src/

cd/usr/src/redis-2.8.19/

Make Prefix=/redis Install


Vi/etc/profile


Path= $PATH:/redis/bin


Source/etc/profile


Cd/redis

mkdir Log

mkdir data

mkdir conf

Cp/usr/src/redis-2.8.19/redis.conf conf/redis-6379.conf

VI conf/redis-6379.conf


PID File Location

Pidfile/var/run/redis-6379.pid

Timeout for client connections, in seconds, close connection after timeout

50 timeout

Logging level, 4 selectable values

98 LogLevel Warning

Log file location

103 Logfile/redis/log/redis-6379.log

Comment out the following 3 lines

142 #save 900 1

143 #save 300 10

144 #save 60 10000

Sets the frequency at which Redis makes database mirroring. Save data to disk policy without restricting keys number

145 Save ""

File name for mirrored backup files

177 Dbfilename Dump-6379.rdb

Path of file placement for database mirroring backup

187 dir/redis/data/

Disable disk-based (hard disk-based), use diskless, socket-based, use network transport

272 Repl-diskless-sync No

When the first request is received, wait for multiple slave to come together to request a time between the intervals.

284 Repl-diskless-sync-delay 5

Set the maximum memory that Redis can use to clear expired or expiring keys

449 MaxMemory 300MB


Start Redis

Redis-server/redis/conf/redis-6379.conf &

View ports

NETSTAT-ANPT | grep Redis

######################################################

Slave Server Modify configuration file

Vi/redis/conf/redis-6379.conf

Add a row in the following location

# slaveof <masterip> <masterport>

Slaveof 192.168.1.28 6379


Restart Redis

Pkill Redis-server

Redis-server/redis/conf/redis-6379.conf &

View ports

NETSTAT-ANPT | grep Redis


Write key on Master host

[Email protected] redis]# redis-cli

127.0.0.1:6379> set name AA

Ok

127.0.0.1:6379> Keys *

1) "Name"


View key in Slave host

[Email protected] conf]# redis-cli

127.0.0.1:6379> Keys *

1) "Name"


2-side key, indicating normal.

On the Redis persistence issue, the above configuration is persistent.

If you restart Redis, the data is lost.

Test reboot, enter again, find the data is empty

[Email protected] redis]# redis-cli

127.0.0.1:6379> Keys *

(empty list or set)


Write to keys again, save with Save

[Email protected] redis]# redis-cli

127.0.0.1:6379> Keys *

(empty list or set)

127.0.0.1:6379> Set pass B

Ok

127.0.0.1:6379> Keys *

1) "Pass"

127.0.0.1:6379> Save

Ok

127.0.0.1:6379> Exit

Restart Redis

[Email protected] redis]# pkill redis-server

[Email protected] redis]# redis-server/redis/conf/redis-6379.conf &

[4] 23642

[3] Done redis-server/redis/conf/redis-6379.conf

Re-enter Redis, view key and find key still in.

[Email protected] redis]# redis-cli

127.0.0.1:6379> Keys *

1) "Pass"


This article is from the "Falling Star" blog, make sure to keep this source http://xiao987334176.blog.51cto.com/2202382/1660313

CentOS Redis Master-Slave

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.