Centos7 Redis主从搭建配置的实现
来源:脚本之家
2023-01-09 12:41:40
0浏览
收藏
怎么入门数据库编程?需要学习哪些知识点?这是新手们刚接触编程时常见的问题;下面golang学习网就来给大家整理分享一些知识点,希望能够给初学者一些帮助。本篇文章就来介绍《Centos7 Redis主从搭建配置的实现》,涉及到Centos7Redis、主从搭建,有需要的可以收藏一下
一、环境介绍
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.19 protected-mode yes port 6379 tcp-backlog 511 timeout 0 tcp-keepalive 300 daemonize yes supervised no pidfile /var/run/redis_6379.pid loglevel notice logfile "/var/log/redis_6379.log" databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump_6379.rdb dir /data0/redis_trade slave-serve-stale-data yes slave-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no slave-priority 100 requirepass Allwelltokok appendonly yes appendfilename "appendonly_6379.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes lua-time-limit 5000 slowlog-log-slower-than 10000 slowlog-max-len 128 latency-monitor-threshold 0 notify-keyspace-events "" hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-size -2 list-compress-depth 0 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 activerehashing yes rename-command FLUSHALL ZYzv6FOBdwflW2nX rename-command EVAL S9UHPKEpSvUJMM rename-command FLUSHDB D60FPVDJuip7gy6l client-output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 aof-rewrite-incremental-fsync yes
三、redis从配置
root># cat redis_6379.conf |grep -Ev "^$|^#" bind 172.18.8.20 protected-mode yes port 6379 tcp-backlog 511 timeout 0 tcp-keepalive 300 daemonize yes supervised no pidfile /var/run/redis_6379.pid loglevel notice logfile "/var/log/redis_6379.log" databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump_6379.rdb dir /data0/redis_trade slaveof 172.18.8.19 6379 -----从库比主库多这2行配置参数 masterauth Allwelltokok -----从库比主库多这2行配置参数 slave-serve-stale-data yes slave-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no slave-priority 100 requirepass Allwelltokok appendonly yes appendfilename "appendonly_6379.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes lua-time-limit 5000 slowlog-log-slower-than 10000 slowlog-max-len 128 latency-monitor-threshold 0 notify-keyspace-events "" hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-size -2 list-compress-depth 0 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 activerehashing yes rename-command FLUSHALL ZYzv6FOBdwflW2nX rename-command EVAL S9UHPKEpSvUJMM rename-command FLUSHDB D60FPVDJuip7gy6l client-output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 aof-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 10 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 "$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.log 5563: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.12 5563:S 29 Jun 22:14:23.237 * The server is now ready to accept connections on port 6379 5563:S 29 Jun 22:14:23.237 * Connecting to MASTER 172.18.8.19:6379 5563:S 29 Jun 22:14:23.237 * MASTER SLAVE sync started 5563: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:1 5563:S 29 Jun 22:14:23.304 * MASTER SLAVE sync: receiving 77 bytes from master 5563:S 29 Jun 22:14:23.305 * MASTER SLAVE sync: Flushing old data 5563:S 29 Jun 22:14:23.305 * MASTER SLAVE sync: Loading DB in memory 5563:S 29 Jun 22:14:23.305 * MASTER SLAVE sync: Finished with success 5563:S 29 Jun 22:14:23.305 * Background append only file rewriting started by pid 5567 5563: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 performed 5567:C 29 Jun 22:14:23.330 * AOF rewrite: 0 MB of memory used by copy-on-write 5563:S 29 Jun 22:14:23.337 * Background AOF rewrite terminated with success 5563: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主从搭建配置的实现》的内容就介绍到这里了,是不是学起来一目了然!想要了解更多关于redis的内容请关注golang学习网公众号!
版本声明
本文转载于:脚本之家 如有侵犯,请联系study_golang@163.com删除

- 上一篇
- Windows系统安装Redis的详细图文教程

- 下一篇
- 使用redis管理用户登录会话的方法
评论列表
-
- 喜悦的帽子
- 太详细了,已加入收藏夹了,感谢楼主的这篇文章,我会继续支持!
- 2023-06-10 22:20:04
-
- 默默的荷花
- 很好,一直没懂这个问题,但其实工作中常常有遇到...不过今天到这,帮助很大,总算是懂了,感谢作者分享技术贴!
- 2023-04-16 17:51:41
-
- 坚强的冬日
- 这篇文章真及时,好细啊,写的不错,已收藏,关注楼主了!希望楼主能多写数据库相关的文章。
- 2023-02-23 08:49:46
查看更多
最新文章
-
- 数据库 · Redis | 16小时前 |
- Redis崩溃后重启及数据恢复攻略
- 373浏览 收藏
-
- 数据库 · Redis | 2天前 |
- 检查Redis版本及升级指南
- 342浏览 收藏
-
- 数据库 · Redis | 2天前 | redis Django 缓存 settings.py django-redis
- Django项目如何集成Redis缓存详解
- 450浏览 收藏
-
- 数据库 · Redis | 3天前 | redis 内存淘汰策略 maxmemory-policy allkeys-lru volatile-lru
- Redis内存淘汰策略配置最佳实践指南
- 359浏览 收藏
-
- 数据库 · Redis | 3天前 | redis Django 缓存 settings.py cache模块
- Django项目Redis缓存集成详解
- 150浏览 收藏
-
- 数据库 · Redis | 3天前 |
- Redis启动内存不足解决方案与技巧
- 174浏览 收藏
-
- 数据库 · Redis | 3天前 |
- Redis启动内存不足解决方法
- 297浏览 收藏
-
- 数据库 · Redis | 5天前 |
- Redis崩溃后重启与数据恢复攻略
- 155浏览 收藏
查看更多
课程推荐
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 542次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 508次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 497次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 484次学习
查看更多
AI推荐
-
- PPTFake答辩PPT生成器
- PPTFake答辩PPT生成器,专为答辩准备设计,极致高效生成PPT与自述稿。智能解析内容,提供多样模板,数据可视化,贴心配套服务,灵活自主编辑,降低制作门槛,适用于各类答辩场景。
- 22次使用
-
- Lovart
- SEO摘要探索Lovart AI,这款专注于设计领域的AI智能体,通过多模态模型集成和智能任务拆解,实现全链路设计自动化。无论是品牌全案设计、广告与视频制作,还是文创内容创作,Lovart AI都能满足您的需求,提升设计效率,降低成本。
- 21次使用
-
- 美图AI抠图
- 美图AI抠图,依托CVPR 2024竞赛亚军技术,提供顶尖的图像处理解决方案。适用于证件照、商品、毛发等多场景,支持批量处理,3秒出图,零PS基础也能轻松操作,满足个人与商业需求。
- 34次使用
-
- PetGPT
- SEO摘要PetGPT 是一款基于 Python 和 PyQt 开发的智能桌面宠物程序,集成了 OpenAI 的 GPT 模型,提供上下文感知对话和主动聊天功能。用户可高度自定义宠物的外观和行为,支持插件热更新和二次开发。适用于需要陪伴和效率辅助的办公族、学生及 AI 技术爱好者。
- 34次使用
-
- 可图AI图片生成
- 探索快手旗下可灵AI2.0发布的可图AI2.0图像生成大模型,体验从文本生成图像、图像编辑到风格转绘的全链路创作。了解其技术突破、功能创新及在广告、影视、非遗等领域的应用,领先于Midjourney、DALL-E等竞品。
- 56次使用
查看更多
相关文章
-
- 详解Centos7下配置Redis并开机自启动
- 2023-01-07 440浏览