Centos7下Redis主从搭建配置的实现方法
发表于:2025-01-21 作者:千家信息网编辑
千家信息网最后更新 2025年01月21日,这篇文章将为大家详细讲解有关Centos7下Redis主从搭建配置的实现方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。一、环境介绍Redis-master 17
千家信息网最后更新 2025年01月21日Centos7下Redis主从搭建配置的实现方法
这篇文章将为大家详细讲解有关Centos7下Redis主从搭建配置的实现方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
一、环境介绍
Redis-master 172.18.8.19
Redis-slave 172.18.8.20
二、redis主的配置
#创建redis数据目录mkdir -p /data0/redis_trade#redis主配置文件root># cat redis_6379.conf |grep -Ev "^$|^#"bind 172.18.8.19protected-mode yesport 6379tcp-backlog 511timeout 0tcp-keepalive 300daemonize yessupervised nopidfile /var/run/redis_6379.pidloglevel noticelogfile "/var/log/redis_6379.log"databases 16save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump_6379.rdbdir /data0/redis_tradeslave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100requirepass Allwelltokokappendonly yesappendfilename "appendonly_6379.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesrename-command FLUSHALL ZYzv6FOBdwflW2nXrename-command EVAL S9UHPKEpSvUJMMrename-command FLUSHDB D60FPVDJuip7gy6lclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes
三、redis从配置
root># cat redis_6379.conf |grep -Ev "^$|^#"bind 172.18.8.20protected-mode yesport 6379tcp-backlog 511timeout 0tcp-keepalive 300daemonize yessupervised nopidfile /var/run/redis_6379.pidloglevel noticelogfile "/var/log/redis_6379.log"databases 16save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump_6379.rdbdir /data0/redis_tradeslaveof 172.18.8.19 6379 -----从库比主库多这2行配置参数masterauth Allwelltokok -----从库比主库多这2行配置参数slave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100requirepass Allwelltokokappendonly yesappendfilename "appendonly_6379.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesrename-command FLUSHALL ZYzv6FOBdwflW2nXrename-command EVAL S9UHPKEpSvUJMMrename-command FLUSHDB D60FPVDJuip7gy6lclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes
四、redis启动脚本
root># cat /etc/init.d/redis_6379 #!/bin/sh## Simple Redis init.d script conceived to work on Linux systems# as it does use of the /proc filesystem.# chkconfig: 2345 90 10source /etc/init.d/functionsREDISPORT=6379EXEC=/usr/local/bin/redis-serverCLIEXEC=/usr/local/bin/redis-cli PIDFILE=/var/run/redis_${REDISPORT}.pidCONF="/usr/local/redis/etc/redis_${REDISPORT}.conf"AUTH="Allwelltokok"BIND_IP='172.18.8.19' start(){ if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already running or crashed" else echo "Starting Redis server..." $EXEC $CONF fi if [ "$?"="0" ] then echo "Redis is running..." fi } stop(){ if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist, process is not running" else PID=$(cat $PIDFILE) echo "Stopping ..." $CLIEXEC -h $BIND_IP -a $AUTH -p $REDISPORT SHUTDOWN sleep 1 while [ -x /proc/${PID} ] do echo "Waiting for Redis to shutdown ..." sleep 1 done echo "Redis stopped" fi} restart(){ stop start }status(){ ps -ef|grep redis-server|grep -v grep >/dev/null 2>&1 if [ $? -eq 0 ];then echo "redis server is running" else echo "redis server is stopped" fi } case "$1" in start) start ;; stop) stop ;; restart) restart ;; status) status ;; *) echo "Usage: /etc/init.d/redis {start|stop|status|start}" >&2 exit 1 esac
五、启动服务
root># /etc/init.d/redis_6379 start
查看日志
root># tail -100f /var/log/redis_6379.log5563:S 29 Jun 22:14:23.236 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 3.2.12 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 5563 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 5563:S 29 Jun 22:14:23.237 # Server started, Redis version 3.2.125563:S 29 Jun 22:14:23.237 * The server is now ready to accept connections on port 63795563:S 29 Jun 22:14:23.237 * Connecting to MASTER 172.18.8.19:63795563:S 29 Jun 22:14:23.237 * MASTER <-> SLAVE sync started5563:S 29 Jun 22:14:23.237 * Non blocking connect for SYNC fired the event.5563:S 29 Jun 22:14:23.238 * Master replied to PING, replication can continue...5563:S 29 Jun 22:14:23.238 * Partial resynchronization not possible (no cached master)5563:S 29 Jun 22:14:23.239 * Full resync from master: c9f303069f87253011bf39369366732a2e88b389:15563:S 29 Jun 22:14:23.304 * MASTER <-> SLAVE sync: receiving 77 bytes from master5563:S 29 Jun 22:14:23.305 * MASTER <-> SLAVE sync: Flushing old data5563:S 29 Jun 22:14:23.305 * MASTER <-> SLAVE sync: Loading DB in memory5563:S 29 Jun 22:14:23.305 * MASTER <-> SLAVE sync: Finished with success5563:S 29 Jun 22:14:23.305 * Background append only file rewriting started by pid 55675563:S 29 Jun 22:14:23.329 * AOF rewrite child asks to stop sending diffs.5567:C 29 Jun 22:14:23.329 * Parent agreed to stop sending diffs. Finalizing AOF...5567:C 29 Jun 22:14:23.329 * Concatenating 0.00 MB of AOF diff received from parent.5567:C 29 Jun 22:14:23.329 * SYNC append only file rewrite performed5567:C 29 Jun 22:14:23.330 * AOF rewrite: 0 MB of memory used by copy-on-write5563:S 29 Jun 22:14:23.337 * Background AOF rewrite terminated with success5563:S 29 Jun 22:14:23.337 * Residual parent diff successfully flushed to the rewritten AOF (0.00 MB)5563:S 29 Jun 22:14:23.337 * Background AOF rewrite finished successfully
关于"Centos7下Redis主从搭建配置的实现方法"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
配置
篇文章
主从
方法
参数
更多
库比
不错
实用
内容
数据
文件
文章
日志
环境
目录
知识
脚本
参考
帮助
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
纽瑞科技 互联网
吉林数据库安全审计
三级数据库技术有用么
计算机网络技术发源于
网络犯罪影响网络安全
key在服务器能破解吗
网络安全细分领域图
网络安全该写的句子
海口找软件开发公司在哪里找
数据库名称不含有shp
网络安全控制软件
期货资管软件开发
网络安全法定期开展测评
数据库字段有下划线怎么查询
云服务器 做账上属于
乐山软件开发公司推荐
网络技术英语教学
华为云服务器和云电脑区别
mysql数据库做预约表
梦幻限时服务器
装配式网络技术维修
达梦数据库安装镜像挂载失败
数据库运行
无锡ftp服务器找哪家
网络安全与技术杂志版面费
网络安全法七类禁止
数据库服务器报价
网络安全安全工作总结
民航网络技术方向
MYSQL数据库技术学校