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

centos8 redis 6.2.6源码安装+主从哨兵

文章目录

  • centos8 redis 6.2.6源码安装+主从哨兵
    • 下载解压
    • 编译安装
    • 配置
    • 配置systemd
    • 服务启停及开机启动
    • 登录验证
    • 主从同步
    • 配置哨兵
    • 哨兵注册systemd

centos8 redis 6.2.6源码安装+主从哨兵

单机安装

下载解压

cd /data
wget http://download.redis.io/releases/redis-6.2.6.tar.gz
tar xf redis-6.2.6.tar.gz
cd redis-6.2.6/

编译安装

make PREFIX=/usr/local/redis6 install

如果编译提示jemallo文件不存在,清空make缓存重新编译
make distclea
make clean

配置

mkdir /usr/local/redis6/confcp redis.conf /usr/local/redis6/conf/mkdir -p /data/redis6/data
mkdir -p /data/redis6/logsvi /usr/local/redis6/conf/redis.conf#配置参数,其他默认
bind 0.0.0.0
protected-mode no
port 6379
daemonize yes
logfile "/data/redis6/logs/redis.log"
dir /data/redis6/data/
maxmemory 2048MB
io-threads 4
requirepass mh112233

配置systemd

vi /lib/systemd/system/redis6.service
[Unit]
Description=Redis
After=network.target[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis6/bin/redis-server /usr/local/redis6/conf/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true[Install]
WantedBy=multi-user.target

服务启停及开机启动

systemctl daemon-reload 
systemctl start redis6
systemctl enable redis6

登录验证

ln -s /usr/local/redis6/bin/redis-cli /usr/bin/redis-cli
redis-cli -h 127.0.0.1 -p 6379 -a mh112233
set a 11
get a

主从同步

#从节点增加配置,ip指向主节点
replicaof 192.168.122.230 6379
#配置密码
masterauth mh112233#检查主从同步状态
info replication

配置哨兵

cp sentinel.conf /usr/local/redis6/conf/
mkdir -p /data/redis6/data/sentinelvi /usr/local/redis6/conf/sentinel.conf#配置参数,其他默认
bind 0.0.0.0
protected-mode no
port 26379
daemonize yes
logfile "/data/redis6/logs/sentinel.log"
dir /data/redis6/data/sentinel/#指定Redis主节点主机IP地址和端口,ip根据实际情况调整,mymaster这个名称随便取,下面配置时也需要指定这个名称,客户端连接时也会使用
#最后的2是指需要有2个以上sentinel节点认为redis主节点失效,才是真的失效,一般为(sentinel总数/2+1)
sentinel monitor mymaster 192.168.122.230 6379 2#配置连接密码,此处的密码需要与 redis.conf里面配置的连接密码一致
sentinel auth-pass mymaster mh112233

哨兵注册systemd

vi /lib/systemd/system/sentinel.service
[Unit]
Description=Redis-sentinel
After=network.target[Service]
Type=forking
PIDFile=/var/run/redis-sentinel.pid
ExecStart=/usr/local/redis6/bin/redis-sentinel /usr/local/redis6/conf/sentinel.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true[Install]
WantedBy=multi-user.targetsystemctl daemon-reload 
systemctl start sentinel
systemctl enable sentinel#连接哨兵服务,检查状态
redis-cli -h 127.0.0.1 -p 26379
info sentinel
http://www.lryc.cn/news/247610.html

相关文章:

  • 机器学习之危险品车辆目标检测
  • DHCP协议及实验omnipeek抓包工具分析 IPv4协议
  • 考过了PMP,面试的时候应该怎么办?
  • 技巧-PyTorch中num_works的作用和实验测试
  • Android:FragmentTransaction
  • 5.golang字符串的拆解和拼接
  • 配置 Mantis 在 Windows 上的步骤
  • Android 单元测试初体验(二)-断言
  • 通过ros系统中websocket中发送sensor_msgs::Image数据给web端显示
  • 【 Kubernetes 风云录 】- Istio 应用多版本流量控制
  • 比尔盖茨:GPT-5不会比GPT-4好多少,生成式AI已达到极限
  • let const 与var的区别
  • git 把项目托管到码云
  • sCrypt 现已支持各类主流前端框架
  • leetcode:2549. 统计桌面上的不同数字(python3解法)
  • 数据结构 / day03作业
  • 异步爬虫提速实践-在Scrapy中使用Aiohttp/Trio
  • Python与设计模式--访问者模式
  • 为社会做贡献的EasyDarwin 4.0.1发布了,支持视频点播、文件直播、摄像机直播、直播录像、直播回放、录像MP4合成下载
  • CG向量和矩阵元素的获取
  • 牛客 算法题 golang语言实现
  • 鸿蒙开发报错:agconnect sdk not initialized. please call initialize()【BUG已解决】
  • 极智芯 | 解读国产AI算力算能产品矩阵
  • docker介绍、部署与常用命令
  • windows定时任务命令工具schtasks
  • 多个nginx共享值、缓存问题
  • 【2023传智杯】第六届传智杯程序设计挑战赛AB组-DEF题解题分析详解【JavaPythonC++解题笔记】
  • Spark---SparkCore(五)
  • k8s中pod的hostport端口突然无法访问故障处理
  • 高德开始“跑腿”