Redisマスタスレーブ構成の詳細手順
7106 ワード
-----------------------------------------------------------------------------------------------------------------------------------------------
関連ディレクトリ#mkdir-p/usr/local/redis/{etc,bin,var}#mkdir-p/data/logs/redis/data/dbcacheの作成
-----------------------------------------------------------------------------------------------------------------------------------------------
コンパイルインストール#tar-xvzf redis-2.4.13.tar.gz# cd redis-2.4.13# make# cd src && cp redis-server redis-cli redis-benchmark/usr/local/redis/bin# echo "vm.overcommit_memory=1">>/etc/sysctl.conf#/sbin/sysctl -p
-----------------------------------------------------------------------------------------------------------------------------------------------
プライマリサーバ設定【192.168.1.1100】#vim/usr/local/redis/etc/redis.confdaemonize yespidfile/usr/local/redis/var/redis.pidport 6379bind 192.168.1.100
unixsocket/usr/local/redis/var/redis.sockunixsocketperm 755
timeout 300
loglevel verboselogfile/data/logs/redis/redis.log
# syslog-enabled no# syslog-ident redis# syslog-facility local0
databases 16
save 900 1save 300 10save 60 10000
rdbcompression yesdbfilename dump.rdb
dir/data/dbcache
# slaveof # masterauth
# repl-ping-slave-period 10# repl-timeout 60requirepass redis123# rename-command CONFIG ""
maxclients 0
# maxmemory# maxmemory-policy volatile-lru# maxmemory-samples 3
appendonly noappendfilename appendonly.aofappendfsync alwaysno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mb
slowlog-log-slower-than 10000slowlog-max-len 128
vm-enabled novm-swap-file/data/dbcache/redis.swapvm-max-memory 0vm-page-size 32vm-pages 134217728vm-max-threads 4
glueoutputbuf yes
hash-max-zipmap-entries 512hash-max-zipmap-value 64
list-max-ziplist-entries 512list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128zset-max-ziplist-value 64
activerehashing yes
-----------------------------------------------------------------------------------------------------------------------------------------------
サーバから[192.168.1.200]daemonize yespidfile/usr/local/redis/var/redisを設定.pidport 6379bind 192.168.1.200
unixsocket/usr/local/redis/var/redis.sockunixsocketperm 755
timeout 300
loglevel verboselogfile/data/logs/redis/redis.log
# syslog-enabled no# syslog-ident redis# syslog-facility local0
databases 16
save 900 1save 300 10save 60 10000
rdbcompression yesdbfilename dump.rdb
dir/data/dbcache
# slaveof # masterauth
# repl-ping-slave-period 10# repl-timeout 60# rename-command CONFIG ""
maxclients 0
# maxmemory# maxmemory-policy volatile-lru# maxmemory-samples 3
appendonly noappendfilename appendonly.aofappendfsync alwaysno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mb
slowlog-log-slower-than 10000slowlog-max-len 128
vm-enabled novm-swap-file/data/dbcache/redis.swapvm-max-memory 0vm-page-size 32vm-pages 134217728vm-max-threads 4
glueoutputbuf yes
hash-max-zipmap-entries 512hash-max-zipmap-value 64
list-max-ziplist-entries 512list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128zset-max-ziplist-value 64
activerehashing yes
slave-serve-stale-data yesslaveof 192.168.1.100 6379masterauth redis123
サービス開始:#/usr/local/redis/bin/redis-server/usr/local/redis/etc/redis.conf
メインサーバで実行:#/usr/local/redis/bin/redis-cli-h 192.168.1100-a redis 123 set test 123456
サーバから実行:#/usr/local/redis/bin/redis-cli-h 192.168.1.200 get test
-----------------------------------------------------------------------------------------------------------------------------------------------
スクリプトvim/etc/initを起動します.d/redis
-----------------------------------------------------------------------------------------------------------------------------------------------
サービス#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-p 6379 save
-----------------------------------------------------------------------------------------------------------------------------------------------
phpredis拡張インストール#svn checkouthttp://phpredis.googlecode.com/svn/trunk/phpredis-read-only#/usr/local/php/bin/phpize# ./configure --with-php-config=/usr/local/php/bin/php-config# make && make install
関連ディレクトリ#mkdir-p/usr/local/redis/{etc,bin,var}#mkdir-p/data/logs/redis/data/dbcacheの作成
-----------------------------------------------------------------------------------------------------------------------------------------------
コンパイルインストール#tar-xvzf redis-2.4.13.tar.gz# cd redis-2.4.13# make# cd src && cp redis-server redis-cli redis-benchmark/usr/local/redis/bin# echo "vm.overcommit_memory=1">>/etc/sysctl.conf#/sbin/sysctl -p
-----------------------------------------------------------------------------------------------------------------------------------------------
プライマリサーバ設定【192.168.1.1100】#vim/usr/local/redis/etc/redis.confdaemonize yespidfile/usr/local/redis/var/redis.pidport 6379bind 192.168.1.100
unixsocket/usr/local/redis/var/redis.sockunixsocketperm 755
timeout 300
loglevel verboselogfile/data/logs/redis/redis.log
# syslog-enabled no# syslog-ident redis# syslog-facility local0
databases 16
save 900 1save 300 10save 60 10000
rdbcompression yesdbfilename dump.rdb
dir/data/dbcache
# slaveof
# repl-ping-slave-period 10# repl-timeout 60requirepass redis123# rename-command CONFIG ""
maxclients 0
# maxmemory
appendonly noappendfilename appendonly.aofappendfsync alwaysno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mb
slowlog-log-slower-than 10000slowlog-max-len 128
vm-enabled novm-swap-file/data/dbcache/redis.swapvm-max-memory 0vm-page-size 32vm-pages 134217728vm-max-threads 4
glueoutputbuf yes
hash-max-zipmap-entries 512hash-max-zipmap-value 64
list-max-ziplist-entries 512list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128zset-max-ziplist-value 64
activerehashing yes
-----------------------------------------------------------------------------------------------------------------------------------------------
サーバから[192.168.1.200]daemonize yespidfile/usr/local/redis/var/redisを設定.pidport 6379bind 192.168.1.200
unixsocket/usr/local/redis/var/redis.sockunixsocketperm 755
timeout 300
loglevel verboselogfile/data/logs/redis/redis.log
# syslog-enabled no# syslog-ident redis# syslog-facility local0
databases 16
save 900 1save 300 10save 60 10000
rdbcompression yesdbfilename dump.rdb
dir/data/dbcache
# slaveof
# repl-ping-slave-period 10# repl-timeout 60# rename-command CONFIG ""
maxclients 0
# maxmemory
appendonly noappendfilename appendonly.aofappendfsync alwaysno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mb
slowlog-log-slower-than 10000slowlog-max-len 128
vm-enabled novm-swap-file/data/dbcache/redis.swapvm-max-memory 0vm-page-size 32vm-pages 134217728vm-max-threads 4
glueoutputbuf yes
hash-max-zipmap-entries 512hash-max-zipmap-value 64
list-max-ziplist-entries 512list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128zset-max-ziplist-value 64
activerehashing yes
slave-serve-stale-data yesslaveof 192.168.1.100 6379masterauth redis123
サービス開始:#/usr/local/redis/bin/redis-server/usr/local/redis/etc/redis.conf
メインサーバで実行:#/usr/local/redis/bin/redis-cli-h 192.168.1100-a redis 123 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
sleep 1
start
}
reload() {
echo -n $"Reloading $prog: "
/sbin/killproc $redis -HUP
RETVAL=$?
echo
return $retval
}
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-p 6379 save
-----------------------------------------------------------------------------------------------------------------------------------------------
phpredis拡張インストール#svn checkouthttp://phpredis.googlecode.com/svn/trunk/phpredis-read-only#/usr/local/php/bin/phpize# ./configure --with-php-config=/usr/local/php/bin/php-config# make && make install