Redis主从配置详细过程
----------------------------------------------------------------------------------------------------
主服务器设置【192.168.1.100】:
# vim /usr/local/redis/etc/redis.conf
daemonize yes
pidfile /usr/local/redis/var/redis.pid
port 6379
bind 192.168.1.100
unixsocket /usr/local/redis/var/redis.sock
unixsocketperm 755
timeout 300
loglevel verbose
logfile /data/logs/redis/redis.log
# syslog-enabled no
# syslog-ident redis
# syslog-facility local0
databases 16
save 900 1
save 300 10
save 60 10000
rdbcompression yes
dbfilename dump.rdb
dir /data/dbcache
# slaveof <masterip> <masterport>
# masterauth <master-password>
# repl-ping-slave-period 10
# repl-timeout 60
requirepass redis123
# rename-command CONFIG ""
maxclients 0
# maxmemory <bytes>
# maxmemory-policy volatile-lru
# maxmemory-samples 3
appendonly no
appendfilename appendonly.aof
appendfsync always
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
slowlog-log-slower-than 10000
slowlog-max-len 128
vm-enabled no
vm-swap-file /data/dbcache/redis.swap
vm-max-memory 0
vm-page-size 32
vm-pages 134217728
vm-max-threads 4
glueoutputbuf yes
hash-max-zipmap-entries 512
hash-max-zipmap-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
activerehashing yes
----------------------------------------------------------------------------------------------------
从服务器设置【192.168.1.200】:
daemonize yes
pidfile /usr/local/redis/var/redis.pid
port 6379
bind 192.168.1.200
unixsocket /usr/local/redis/var/redis.sock
unixsocketperm 755
timeout 300
loglevel verbose
logfile /data/logs/redis/redis.log
# syslog-enabled no
# syslog-ident redis
# syslog-facility local0
databases 16
save 900 1
save 300 10
save 60 10000
rdbcompression yes
dbfilename dump.rdb
dir /data/dbcache
# slaveof <masterip> <masterport>
# masterauth <master-password>
# repl-ping-slave-period 10
# repl-timeout 60
# rename-command CONFIG ""
maxclients 0
# maxmemory <bytes>
# maxmemory-policy volatile-lru
# maxmemory-samples 3
appendonly no
appendfilename appendonly.aof
appendfsync always
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
slowlog-log-slower-than 10000
slowlog-max-len 128
vm-enabled no
vm-swap-file /data/dbcache/redis.swap
vm-max-memory 0
vm-page-size 32
vm-pages 134217728
vm-max-threads 4
glueoutputbuf yes
hash-max-zipmap-entries 512
hash-max-zipmap-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
activerehashing yes
slave-serve-stale-data yes
slaveof 192.168.1.100 6379
masterauth redis123
测试:
启动服务:
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
主服务器上执行:
/usr/local/redis/bin/redis-cli -h 192.168.1.100 -a redis123 set test 123456
从服务器上执行:
/usr/local/redis/bin/redis-cli -h 192.168.1.200 get test
----------------------------------------------------------------------------------------------------
启动脚本
# vim /etc/init.d/redis
#!/bin/sh
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis-server
# config: /usr/local/redis/etc/redis.conf
# pidfile: /usr/local/redis/var/redis.pid
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
redis="/usr/local/redis/bin/redis-server"
prog=$(basename $redis)
REDIS_CONF_FILE="/usr/local/redis/etc/redis.conf"
lockfile="/var/lock/subsys/redis"
start()
{
[ -x $redis ] || exit 5
[ -f $REDIS_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
$redis $REDIS_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop()
{
echo -n $"Stopping $prog: "
/sbin/killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart()
{
stop
start
}
reload()
{
echo -n $"Reloading $prog: "
/sbin/killproc $redis -HUP
RETVAL=$?
echo
}
case "$1" in
start)
$1
;;
stop)
$1
;;
restart)
$1
;;
reload)
$1
;;
*)
echo $"Usage: $0 {start|stop|restart|reload}"
exit 2
esac
----------------------------------------------------------------------------------------------------
启动服务
# chmod 700 /etc/init.d/redis
# chkconfig --add redis
# service redis start
测试是否已启动
# /usr/local/redis/bin/redis-cli ping
性能测试
# /usr/local/redis/bin/redis-benchmark
关闭服务
# /usr/local/redis/bin/redis-cli -p 6379 shutdown
强制刷新数据到磁盘【Redis默认是异步写入磁盘的】
# /usr/local/redis/bin/redis-cli -p6379 save
---------------------------------------------------------------------------------------
不支持主主同步,也就是只能读写分离
posted on 2012-06-04 14:23 kudosharry 阅读(383) 评论(0) 编辑 收藏 举报