Centos7 Redis主从搭建配置的实现
一、环境介绍
Redis—master 172.18.8.19
Redis—slave 172.18.8.20
二、redis主的配置
#创建redis数据目录 mkdir-p/data0/redis_trade #redis主配置文件 root>#catredis_6379.conf|grep-Ev"^$|^#" bind172.18.8.19 protected-modeyes port6379 tcp-backlog511 timeout0 tcp-keepalive300 daemonizeyes supervisedno pidfile/var/run/redis_6379.pid loglevelnotice logfile"/var/log/redis_6379.log" databases16 save9001 save30010 save6010000 stop-writes-on-bgsave-erroryes rdbcompressionyes rdbchecksumyes dbfilenamedump_6379.rdb dir/data0/redis_trade slave-serve-stale-datayes slave-read-onlyyes repl-diskless-syncno repl-diskless-sync-delay5 repl-disable-tcp-nodelayno slave-priority100 requirepassAllwelltokok appendonlyyes appendfilename"appendonly_6379.aof" appendfsynceverysec no-appendfsync-on-rewriteno auto-aof-rewrite-percentage100 auto-aof-rewrite-min-size64mb aof-load-truncatedyes lua-time-limit5000 slowlog-log-slower-than10000 slowlog-max-len128 latency-monitor-threshold0 notify-keyspace-events"" hash-max-ziplist-entries512 hash-max-ziplist-value64 list-max-ziplist-size-2 list-compress-depth0 set-max-intset-entries512 zset-max-ziplist-entries128 zset-max-ziplist-value64 hll-sparse-max-bytes3000 activerehashingyes rename-commandFLUSHALLZYzv6FOBdwflW2nX rename-commandEVALS9UHPKEpSvUJMM rename-commandFLUSHDBD60FPVDJuip7gy6l client-output-buffer-limitnormal000 client-output-buffer-limitslave256mb64mb60 client-output-buffer-limitpubsub32mb8mb60 hz10 aof-rewrite-incremental-fsyncyes
三、redis从配置
root>#catredis_6379.conf|grep-Ev"^$|^#" bind172.18.8.20 protected-modeyes port6379 tcp-backlog511 timeout0 tcp-keepalive300 daemonizeyes supervisedno pidfile/var/run/redis_6379.pid loglevelnotice logfile"/var/log/redis_6379.log" databases16 save9001 save30010 save6010000 stop-writes-on-bgsave-erroryes rdbcompressionyes rdbchecksumyes dbfilenamedump_6379.rdb dir/data0/redis_trade slaveof172.18.8.196379-----从库比主库多这2行配置参数 masterauthAllwelltokok-----从库比主库多这2行配置参数 slave-serve-stale-datayes slave-read-onlyyes repl-diskless-syncno repl-diskless-sync-delay5 repl-disable-tcp-nodelayno slave-priority100 requirepassAllwelltokok appendonlyyes appendfilename"appendonly_6379.aof" appendfsynceverysec no-appendfsync-on-rewriteno auto-aof-rewrite-percentage100 auto-aof-rewrite-min-size64mb aof-load-truncatedyes lua-time-limit5000 slowlog-log-slower-than10000 slowlog-max-len128 latency-monitor-threshold0 notify-keyspace-events"" hash-max-ziplist-entries512 hash-max-ziplist-value64 list-max-ziplist-size-2 list-compress-depth0 set-max-intset-entries512 zset-max-ziplist-entries128 zset-max-ziplist-value64 hll-sparse-max-bytes3000 activerehashingyes rename-commandFLUSHALLZYzv6FOBdwflW2nX rename-commandEVALS9UHPKEpSvUJMM rename-commandFLUSHDBD60FPVDJuip7gy6l client-output-buffer-limitnormal000 client-output-buffer-limitslave256mb64mb60 client-output-buffer-limitpubsub32mb8mb60 hz10 aof-rewrite-incremental-fsyncyes
四、redis启动脚本
root>#cat/etc/init.d/redis_6379
#!/bin/sh
#
#SimpleRedisinit.dscriptconceivedtoworkonLinuxsystems
#asitdoesuseofthe/procfilesystem.
#chkconfig:23459010
source/etc/init.d/functions
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis/etc/redis_${REDISPORT}.conf"
AUTH="Allwelltokok"
BIND_IP='172.18.8.19'
start(){
if[-f$PIDFILE]
then
echo"$PIDFILEexists,processisalreadyrunningorcrashed"
else
echo"StartingRedisserver..."
$EXEC$CONF
fi
if["$?"="0"]
then
echo"Redisisrunning..."
fi
}
stop(){
if[!-f$PIDFILE]
then
echo"$PIDFILEdoesnotexist,processisnotrunning"
else
PID=$(cat$PIDFILE)
echo"Stopping..."
$CLIEXEC-h$BIND_IP-a$AUTH-p$REDISPORTSHUTDOWN
sleep1
while[-x/proc/${PID}]
do
echo"WaitingforRedistoshutdown..."
sleep1
done
echo"Redisstopped"
fi
}
restart(){
stop
start
}
status(){
ps-ef|grepredis-server|grep-vgrep>/dev/null2>&1
if[$?-eq0];then
echo"redisserverisrunning"
else
echo"redisserverisstopped"
fi
}
case"$1"in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo"Usage:/etc/init.d/redis{start|stop|status|start}">&2
exit1
esac
五、启动服务
root>#/etc/init.d/redis_6379start
查看日志
root>#tail-100f/var/log/redis_6379.log
5563:S29Jun22:14:23.236*Increasedmaximumnumberofopenfilesto10032(itwasoriginallysetto1024).
_._
_.-``__''-._
_.-```.`_.''-._Redis3.2.12(00000000/0)64bit
.-``.-```.```\/_.,_''-._
(',.-`|`,)Runninginstandalonemode
|`-._`-...-`__...-.``-._|'`_.-'|Port:6379
|`-._`._/_.-'|PID:5563
`-._`-._`-./_.-'_.-'
|`-._`-._`-.__.-'_.-'_.-'|
|`-._`-.__.-'_.-'|http://redis.io
`-._`-._`-.__.-'_.-'_.-'
|`-._`-._`-.__.-'_.-'_.-'|
|`-._`-.__.-'_.-'|
`-._`-._`-.__.-'_.-'_.-'
`-._`-.__.-'_.-'
`-.__.-'
`-.__.-'
5563:S29Jun22:14:23.237#Serverstarted,Redisversion3.2.12
5563:S29Jun22:14:23.237*Theserverisnowreadytoacceptconnectionsonport6379
5563:S29Jun22:14:23.237*ConnectingtoMASTER172.18.8.19:6379
5563:S29Jun22:14:23.237*MASTER<->SLAVEsyncstarted
5563:S29Jun22:14:23.237*NonblockingconnectforSYNCfiredtheevent.
5563:S29Jun22:14:23.238*MasterrepliedtoPING,replicationcancontinue...
5563:S29Jun22:14:23.238*Partialresynchronizationnotpossible(nocachedmaster)
5563:S29Jun22:14:23.239*Fullresyncfrommaster:c9f303069f87253011bf39369366732a2e88b389:1
5563:S29Jun22:14:23.304*MASTER<->SLAVEsync:receiving77bytesfrommaster
5563:S29Jun22:14:23.305*MASTER<->SLAVEsync:Flushingolddata
5563:S29Jun22:14:23.305*MASTER<->SLAVEsync:LoadingDBinmemory
5563:S29Jun22:14:23.305*MASTER<->SLAVEsync:Finishedwithsuccess
5563:S29Jun22:14:23.305*Backgroundappendonlyfilerewritingstartedbypid5567
5563:S29Jun22:14:23.329*AOFrewritechildaskstostopsendingdiffs.
5567:C29Jun22:14:23.329*Parentagreedtostopsendingdiffs.FinalizingAOF...
5567:C29Jun22:14:23.329*Concatenating0.00MBofAOFdiffreceivedfromparent.
5567:C29Jun22:14:23.329*SYNCappendonlyfilerewriteperformed
5567:C29Jun22:14:23.330*AOFrewrite:0MBofmemoryusedbycopy-on-write
5563:S29Jun22:14:23.337*BackgroundAOFrewriteterminatedwithsuccess
5563:S29Jun22:14:23.337*ResidualparentdiffsuccessfullyflushedtotherewrittenAOF(0.00MB)
5563:S29Jun22:14:23.337*BackgroundAOFrewritefinishedsuccessfully
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。