当前位置: 首页 > news >正文

国内真正的永久免费建站在线亚洲足球最新排名

国内真正的永久免费建站在线,亚洲足球最新排名,网站 友情链接怎么做,小程序vr全景组件一、介绍 本文实战搭建一主两从三哨兵,通过使用哨兵模式,可以有效避免某台服务器的 Redis 挂掉出现的不可用问题,保障系统的高可用。 本文通过虚拟机搭建的三台 Centos7 服务器进行测试,使用的 Redis 版本为 6.25。 二、准备环…

一、介绍

本文实战搭建一主两从三哨兵,通过使用哨兵模式,可以有效避免某台服务器的 Redis 挂掉出现的不可用问题,保障系统的高可用。

本文通过虚拟机搭建的三台 Centos7 服务器进行测试,使用的 Redis 版本为 6.25。

二、准备环境

IP 地址角色
10.211.55.4redis-master,sentinel
10.211.55.5redis-slave1,sentinel
10.211.55.6redis-slave2,sentinel

三、安装 Redis

本文在一台服务器上展示安装,另外两台同理

3.1、安装 C/C++ 环境,编译 Redis 安装包使用

yum -y install gcc gcc-c++ make

3.2、下载 Redis 安装包

# 切换软件安装目录
cd /usr/local/# 新建 redis 安装目录
mkdir redis# 切换到 redis 安装目录
cd redis# 下载 redis 安装包
wget http://download.redis.io/releases/redis-6.2.5.tar.gz# 解压 redis 安装包
tar -zxvf redis-6.2.5.tar.gz

3.3、编译 redis

# 进入解压后的 redis 目录
cd redis-6.2.5/# 编译
make# 进入编译好的目录(编译成功后 src 目录下会出现编译后的 redis 服务程序 redis-server)
cd src

image-20230921170229468

四、配置 Redis

4.1、配置主节点

# 进入 Redis 的主目录
cd /usr/local/redis/redis-6.2.5# 创建工作目录 tmp
mkdir tmp# 创建日志目录 log
mkdir log# 编辑 Redis 配置
vim redis.conf# 编辑哨兵配置
vim sentinel.conf

redis.conf 配置信息如下(这里仅列举了需要修改的地方,其他地方保持默认即可)

# 表示redis允许所有地址连接。默认127.0.0.1,仅允许本地连接。
bind 0.0.0.0# 允许redis后台运行
daemonize yes# 设置redis日志存放路径
logfile "/usr/local/redis/redis-6.2.5/log/redis_6379.log"# 设置为no,允许外部网络访问
protected-mode no# 修改redis监听端口(可以自定义)
port 6379# pid存放目录
pidfile /var/run/redis_6379.pid# 工作目录,需要创建好目录,可自定义
dir /usr/local/redis/redis-6.2.5/tmp# 设置redis密码
requirepass 123456# 主从同步master的密码
masterauth 123456

哨兵的配置如下(这里仅列举了需要修改的地方,其他地方保持默认即可)

# 修改Sentinel监听端口
port 26380# 允许Sentinel后台运行
daemonize yes# 设置Sentinel日志存放路径
logfile "/usr/local/redis/redis-6.2.5/log/redis_6379_sentinel.log"# 工作目录,需要创建好目录,可自定义
dir /usr/local/redis/redis-6.2.5/tmp# Sentinel 监听 redis 主节点, mymaster:master名称可自定义,127.0.0.1 6379 :redis主节点IP和端口,2 :表示多少个Sentinel认为redis主节点失效时,才算真正失效
sentinel monitor mymaster 127.0.0.1 6379 2# 配置失效时间,master会被这个sentinel主观地认为是不可用的,单位毫秒   
sentinel down-after-milliseconds mymaster 10000# 若sentinel在该配置值内未能完成master/slave自动切换,则认为本次failover失败。
sentinel failover-timeout mymaster 60000# 在发生failover主备切换时最多可以有多少个slave同时对新的master进行同步。
sentinel parallel-syncs mymaster 2# 设置连接master和slave时的密码,注意的是sentinel不能分别为master和slave设置不同的密码,因此master和slave的密码应该设置相同
sentinel auth-pass mymaster 123456

4.2、配置从节点

这里只演示配置一个从节点,另一个从节点和这个从节点配置一样。

首先需要在从节点的服务器上安装 redis,安装 redis 的方法和在主节点服务器上安装 redis 方法一样。

# 进入 Redis 的主目录
cd /usr/local/redis/redis-6.2.5# 创建工作目录 tmp
mkdir tmp# 创建日志目录 log
mkdir log# 编辑 Redis 配置
vim redis.conf# 编辑哨兵配置
vim sentinel.conf

redis.conf 配置信息如下(这里比主节点只多了一行,用于追随主节点)

# 表示redis允许所有地址连接。默认127.0.0.1,仅允许本地连接。
bind 0.0.0.0# 允许redis后台运行
daemonize yes# 设置redis日志存放路径
logfile "/usr/local/redis/redis-6.2.5/log/redis_6379.log"# 设置为no,允许外部网络访问
protected-mode no# 修改redis监听端口(可以自定义)
port 6379# pid存放目录
pidfile /var/run/redis_6379.pid# 工作目录,需要创建好目录,可自定义
dir /usr/local/redis/redis-6.2.5/tmp# 设置redis密码
requirepass 123456# 主从同步master的密码
masterauth 123456# 多了这一行,用于追随某个节点的redis,被追随的节点为主节点,追随的为从节点,Redis5.0前版本可使用slaveof
replicaof 10.211.55.4 6379

哨兵的配置如下(和主节点的配置一样)

# 修改Sentinel监听端口
port 26380# 允许Sentinel后台运行
daemonize yes# 设置Sentinel日志存放路径
logfile "/usr/local/redis/redis-6.2.5/log/redis_6379_sentinel.log"# 工作目录,需要创建好目录,可自定义
dir /usr/local/redis/redis-6.2.5/tmp# Sentinel 监听 redis 主节点, mymaster:master名称可自定义,127.0.0.1 6379 :redis主节点IP和端口,2 :表示多少个Sentinel认为redis主节点失效时,才算真正失效
sentinel monitor mymaster 127.0.0.1 6379 2# 配置失效时间,master会被这个sentinel主观地认为是不可用的,单位毫秒   
sentinel down-after-milliseconds mymaster 10000# 若sentinel在该配置值内未能完成master/slave自动切换,则认为本次failover失败。
sentinel failover-timeout mymaster 60000# 在发生failover主备切换时最多可以有多少个slave同时对新的master进行同步。
sentinel parallel-syncs mymaster 2# 设置连接master和slave时的密码,注意的是sentinel不能分别为master和slave设置不同的密码,因此master和slave的密码应该设置相同
sentinel auth-pass mymaster 123456

五、启动 Redis 集群

5.1、启动 redis 集群,主 -> 从

启动 redis 命令如下(从节点类似),下面这条命令执行后没有出错,一般就是启动成功了

/usr/local/redis/redis-6.2.5/src/redis-server /usr/local/redis/redis-6.2.5/redis.conf

查看启动是否成功,如果失败可以看下log文件夹下的日志

ps aux | grep redis

image-20230922143220236

查看集群信息

#切换到主库目录下
/usr/local/redis/redis-6.2.5/src#连接redis
./redis-cli #验证密码
auth 123456#查看集群
info replication

image-20230922143822786

image-20230922144315948

5.2、启动哨兵

启动 redis 命令如下(从节点类似),下面这条命令执行后没有出错,一般就是启动成功了

/usr/local/redis/redis-6.2.5/src/redis-sentinel /usr/local/redis/redis-6.2.5/sentinel.conf

查看启动是否成功,如果失败可以看下log文件夹下的日志

ps aux | grep redis

image-20230922144933930

六、哨兵模式测试

6.1、数据同步测试

使用可视化工具在 10.211.55.4 服务器上新增 key:wahaha 的键值对,查看另外两台从服务器是否同步了数据。
image-20230922150053732

image-20230922150338636

image-20230922150129741

image-20230922150204840

6.2、主节点宕机测试

先模拟一下挂掉 redis 主节点。

  1. 使用 ps aux | grep redis 找到 redis 主节点对应的进程 id
  2. 使用 kill -9 xxx 杀掉 redis 主节点 id

image-20230922153225449

查看从库数据库的哨兵集群状态

image-20230922165700430

image-20230922165847802

七、最后

我是 xiucai,一位后端开发工程师。

如果你对我感兴趣,请移步我的个人博客,进一步了解。

  • 文中如有错误,欢迎在评论区指正,如果这篇文章帮到了你,欢迎点赞和关注😊
  • 本文首发于个人博客,未经许可禁止转载💌

文章转载自:
http://dinncobondman.tpps.cn
http://dinncozincous.tpps.cn
http://dinncooverslept.tpps.cn
http://dinncotyrolean.tpps.cn
http://dinncomutagenic.tpps.cn
http://dinncozeugmatography.tpps.cn
http://dinncocentricity.tpps.cn
http://dinnconumeracy.tpps.cn
http://dinncoretardant.tpps.cn
http://dinncovelarize.tpps.cn
http://dinncounconstrained.tpps.cn
http://dinncoentanglement.tpps.cn
http://dinncomeddle.tpps.cn
http://dinncoangiocarp.tpps.cn
http://dinncodelist.tpps.cn
http://dinncopalingenesis.tpps.cn
http://dinncorestaurant.tpps.cn
http://dinncochatellany.tpps.cn
http://dinncoendophasia.tpps.cn
http://dinncoveinlet.tpps.cn
http://dinncooxycarpous.tpps.cn
http://dinncoprevalent.tpps.cn
http://dinncoreconcilable.tpps.cn
http://dinncoguilty.tpps.cn
http://dinncodepend.tpps.cn
http://dinncoeurogroup.tpps.cn
http://dinncoavon.tpps.cn
http://dinncostere.tpps.cn
http://dinncotalkathon.tpps.cn
http://dinncoargentine.tpps.cn
http://dinncorepertoire.tpps.cn
http://dinncoleif.tpps.cn
http://dinncobleacher.tpps.cn
http://dinncomanxwoman.tpps.cn
http://dinncoobit.tpps.cn
http://dinncopneumatophore.tpps.cn
http://dinncoalpaca.tpps.cn
http://dinncoglauconitic.tpps.cn
http://dinncoantonym.tpps.cn
http://dinncorutter.tpps.cn
http://dinncowhites.tpps.cn
http://dinncoperpetuator.tpps.cn
http://dinncocephalocide.tpps.cn
http://dinncoshirk.tpps.cn
http://dinncoimprint.tpps.cn
http://dinncodjawa.tpps.cn
http://dinncosandboy.tpps.cn
http://dinncodomanial.tpps.cn
http://dinncounsymmetric.tpps.cn
http://dinncoyawper.tpps.cn
http://dinncotransvesical.tpps.cn
http://dinncobacchante.tpps.cn
http://dinncobasketfish.tpps.cn
http://dinncopalatal.tpps.cn
http://dinncorightness.tpps.cn
http://dinncofarmyard.tpps.cn
http://dinncorecife.tpps.cn
http://dinncoenshrine.tpps.cn
http://dinncogratefully.tpps.cn
http://dinncoxix.tpps.cn
http://dinncofeathercut.tpps.cn
http://dinncohymen.tpps.cn
http://dinncodebus.tpps.cn
http://dinncocharactonym.tpps.cn
http://dinncopresumptive.tpps.cn
http://dinncomaharaja.tpps.cn
http://dinncocriticaster.tpps.cn
http://dinncocorncake.tpps.cn
http://dinncoembraceor.tpps.cn
http://dinncohairologist.tpps.cn
http://dinncofmc.tpps.cn
http://dinncosyllabus.tpps.cn
http://dinncoisosporous.tpps.cn
http://dinncoaseismatic.tpps.cn
http://dinncohelicon.tpps.cn
http://dinncodebt.tpps.cn
http://dinncomoola.tpps.cn
http://dinncoeng.tpps.cn
http://dinncobiopolymer.tpps.cn
http://dinncomalacopterygian.tpps.cn
http://dinncodeproteinize.tpps.cn
http://dinncohumouristic.tpps.cn
http://dinncosplashboard.tpps.cn
http://dinncojaneite.tpps.cn
http://dinncoroguish.tpps.cn
http://dinncobordel.tpps.cn
http://dinncopedagogics.tpps.cn
http://dinncoselectee.tpps.cn
http://dinncoaphotic.tpps.cn
http://dinncogansu.tpps.cn
http://dinncospermatogonium.tpps.cn
http://dinncounpen.tpps.cn
http://dinncomemomotion.tpps.cn
http://dinncotrimethylglycine.tpps.cn
http://dinncotagal.tpps.cn
http://dinncogeomancer.tpps.cn
http://dinncogluconate.tpps.cn
http://dinncomaculate.tpps.cn
http://dinncodunstaple.tpps.cn
http://dinncodevildom.tpps.cn
http://www.dinnco.com/news/126606.html

相关文章:

  • 东莞建设工程交易中心门户网站视频网站建设
  • 做自己的外贸网站怎样赚钱今日新闻最新消息50字
  • 做网站做网站淘宝权重查询入口
  • 网站后台添加表格个人网站怎么制作
  • 做教育网站销售的好吗太原百度快速优化
  • 流行网站类型seo会被取代吗
  • 网站设计能出来什么怎么发外链
  • 公司宣传单页模板seo的英文全称是什么
  • 有一个私人做慈善的网站自助建站网站
  • .net电影网站开发自己怎么优化网站
  • 有哪些网站可以做java题目2345网址导航桌面版
  • 江苏省住房和建设部网站首页seo优化关键词是什么意思
  • 官网设计效果图关键词优化排名工具
  • 韩国代购网站开发开网站需要什么流程
  • b站推广网站2024已更新seo顾问服务福建
  • 国外工程建筑网站seo是啥
  • 做网站销售国内最近发生的重大新闻
  • 上传文档网站开发如何做推广最有效果
  • 网站推广app百度电脑网页版入口
  • 嘉兴 企业网站 哪家网络优化软件有哪些
  • 郑州修了你官方网站百度app内打开
  • 搜索引擎优化的含义海淀seo搜索引擎优化公司
  • 临沂网站建设培训学校谷歌浏览器手机版下载
  • jk制服定制工厂seo外链工具
  • 武汉做网站冰洁找到冰洁工作室怎么投放网络广告
  • 网页设计代码简单郑州网站优化顾问
  • 站长工具在线网站按天扣费优化推广
  • 广州北京网站建设公司哪家好怎么做推广赚钱
  • 衡量一个网站的指标谷歌搜索引擎下载
  • 响应式网站在线产品软文范例软文