redis 主:
将主从redis配置文件redis.conf中的aemonize no 改为 yes
jrhrpt01:/etc/redis# grep port redis.conf
# Accept connections on the specified port, default is 6379.
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379
jrhrpt01:/etc/redis# grep slaveof redis.conf
# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# slaveof <masterip> <masterport>
redis 从:
jrhrpt02:/etc/redis# grep slaveof redis.conf
# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# slaveof <masterip> <masterport>
slaveof 11.40.69.216 6379 ---redis 主
# If the master is password protected (using the "requirepass" configuration
# directive below) it is possible to tell the slave to authenticate before
# starting the replication synchronization process, otherwise the master will
# refuse the slave request.
#
#masterauth <master-password>
masterauth xxxxx
启动redis:
redis-server /etc/redis.conf
测试:
主
test-redis:/root# cat a1.pl
use Redis;
my $r = Redis->new( server => "192.168.32.167:6379",reconnect => 1,every=>60);
$r = Redis->new( password => 'xxxxx' );
$r->set('zhoucui','111222333');
$r->save;
$r->quit;
perl a1.pl
从:
test-redis2:/data01/redis# redis-server --/etc/redis.conf^C
test-redis2:/data01/redis# redis-cli
127.0.0.1:6379> auth 'xxx'
OK
127.0.0.1:6379> get zhoucui
"111222333"
127.0.0.1:6379>