首页 > 其他 > 详细

Redis 主从配置

时间:2014-07-29 13:37:18      阅读:471      评论:0      收藏:0      [点我收藏+]

redis 主从配置

Master:192.168.209.18

Slave:192.168.209.19

Master:

tar xzvf redis-2.8.12.tar.gz

mv  redis-2.8.12 /usr/local/redis

cd /usr/local/redis

make

cp redis.conf  redis.conf.bak

mkdir /data1/redis_6379

vi redis.conf

 

grep -v "#" redis.conf | tr -s ‘\n‘

配置文件形如:

daemonize yes

# 是否后台运行

pidfile /var/run/redis.pid

#业务端口

port 6379

tcp-backlog 511

timeout 0

tcp-keepalive 0

loglevel notice

logfile ""

databases 16

save 900 1

save 300 10

save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename dump.rdb

dir /data1/redis_6379/

# 数据文件路径

slave-serve-stale-data yes

slave-read-only yes

repl-disable-tcp-nodelay no

slave-priority 100

appendonly no

appendfilename "appendonly.aof"

appendfsync everysec

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100

auto-aof-rewrite-min-size 64mb

lua-time-limit 5000

slowlog-log-slower-than 10000

slowlog-max-len 128

notify-keyspace-events ""

hash-max-ziplist-entries 512

hash-max-ziplist-value 64

list-max-ziplist-entries 512

list-max-ziplist-value 64

set-max-intset-entries 512

zset-max-ziplist-entries 128

zset-max-ziplist-value 64

hll-sparse-max-bytes 3000

activerehashing yes

client-output-buffer-limit normal 0 0 0

client-output-buffer-limit slave 256mb 64mb 60

client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

aof-rewrite-incremental-fsync yes

 

 

 

 

启动redis

/usr/local/redis/src/redis-server /usr/local/redis/redis.conf

关闭redis

/usr/local/redis/src/redis-cli -n 6379 shutdown

 

redis命令测试

先登录shell客户端

/usr/local/redis/src/redis-cli -p 6379

 

set 测试

redis 127.0.0.1:6379> set name abc

OK <---成功

 

get 测试

redis 127.0.0.1:6379> get name

"abc"

 

/usr/local/redis/src/redis-cli -p 6379

/usr/local/redis/src/redi-cli -p 6379

 

 

Slave

tar xzvf redis-2.8.12.tar.gz

mv  redis-2.8.12 /usr/local/redis

cd /usr/local/redis

make

cp redis.conf  redis.conf.bak

mkdir /data1/redis_6379

vi redis.conf

 

grep -v "#" redis.conf | tr -s ‘\n‘

配置文件形如:

daemonize yes

pidfile /var/run/redis.pid

port 6379

tcp-backlog 511

timeout 0

tcp-keepalive 0

loglevel notice

logfile ""

databases 16

save 900 1

save 300 10

save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename dump.rdb

dir /data1/redis_6379/

slaveof 192.168.209.18 6379

#slaveof master的ip master的端口

slave-serve-stale-data yes

slave-read-only yes

repl-disable-tcp-nodelay no

slave-priority 100

appendonly no

appendfilename "appendonly.aof"

appendfsync everysec

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100

auto-aof-rewrite-min-size 64mb

lua-time-limit 5000

slowlog-log-slower-than 10000

slowlog-max-len 128

notify-keyspace-events ""

hash-max-ziplist-entries 512

hash-max-ziplist-value 64

list-max-ziplist-entries 512

list-max-ziplist-value 64

set-max-intset-entries 512

zset-max-ziplist-entries 128

zset-max-ziplist-value 64

hll-sparse-max-bytes 3000

activerehashing yes

client-output-buffer-limit normal 0 0 0

client-output-buffer-limit slave 256mb 64mb 60

client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

aof-rewrite-incremental-fsync yes

 

6.2 主从测试

在master set

redis 192.168.209.18:12002> set testms gogogo

OK

 

在slave get

redis 192.168.209.19:12002> get testms

"gogogo" <---- 获取到的value

 

 

 

 

===================================

以下为一主多从

直接在masterslave上面,复制主的redis目录,并修改配置文件,配置文件只需修改portdirslaveof三项即可。

cp -rp redis redis_6380

mkdir /data1/redis_6380

cd redis_6380/

vi redis.conf

形如:

daemonize yes

pidfile /var/run/redis.pid

port 6380

tcp-backlog 511

timeout 0

tcp-keepalive 0

loglevel notice

logfile ""

databases 16

save 900 1

save 300 10

save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename dump.rdb

dir /data1/redis_6380/

slaveof 192.168.209.18 6379

slave-serve-stale-data yes

slave-read-only yes

repl-disable-tcp-nodelay no

slave-priority 100

appendonly no

appendfilename "appendonly.aof"

appendfsync everysec

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100

auto-aof-rewrite-min-size 64mb

lua-time-limit 5000

slowlog-log-slower-than 10000

slowlog-max-len 128

notify-keyspace-events ""

hash-max-ziplist-entries 512

hash-max-ziplist-value 64

list-max-ziplist-entries 512

list-max-ziplist-value 64

set-max-intset-entries 512

zset-max-ziplist-entries 128

zset-max-ziplist-value 64

hll-sparse-max-bytes 3000

activerehashing yes

client-output-buffer-limit normal 0 0 0

client-output-buffer-limit slave 256mb 64mb 60

client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

aof-rewrite-incremental-fsync yes

==================================

 

Redis 主从配置,布布扣,bubuko.com

Redis 主从配置

原文:http://www.cnblogs.com/krainbow/p/3874977.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!