首页 > 数据库 >redis-sentinel

redis-sentinel

时间:2024-05-10 10:57:57浏览次数:17  
标签:requirepass redis lzjasdqq Sentinel sentinel password

首先搭建1主两从的redis主从服务
mkdir -pv /etc/redis/
mkdir -pv /redis/db{2,3}
cd /etc/redis/
redis 主配置不变
vim /usr/local/redis-6.2.6/bin/redis.conf
requirepass "lzjasdqq"
appendonly yes
daemonize yes
pidfile "/var/run/redis_6380.pid"
logfile "/var/log/redis/redis6380.log
protected-mode no
port 6380
dir "/var/lib/redis"

masterauth  lzjasdqq

cp -r /usr/local/redis-6.2.6/bin/redis.conf /etc/redis/redis.conf2
vim /etc/redis/redis.conf2
redis2 配置

requirepass "lzjasdqq"
appendonly yes
daemonize yes
pidfile "/var/run/redis_6380.pid"
logfile "/var/log/redis/redis6380.log
protected-mode no
port 6380
dir "/redis/db2"

replicaof 192.168.40.130 6379

masterauth  lzjasdqq

cp -r /usr/local/redis-6.2.6/bin/redis.conf /etc/redis/redis.conf3
vim /etc/redis/redis.conf3
redis3 配置
requirepass "lzjasdqq"
appendonly yes
daemonize yes
pidfile "/var/run/redis_6381.pid"
logfile "/var/log/redis/redis6381.log
protected-mode no
port 6381
dir "/redis/db3"

replicaof 192.168.40.130 6379

masterauth  lzjasdqq
systemctl start redis 
redis-server /etc/redis/redis.conf2
redis-server /etc/redis/redis.conf3
redis-cli 
info replication
到源码里面可以看到 sentinel.conf
cp sentinel.conf  /etc/
redis-sentinel配置

bind 0.0.0.0
sentinel monitor mymaster 192.168.40.130 6379 1
logfile "/var/log/redis/sentinel.log"
daemonize yes
sentinel auth-pass mymaster lzjasdqq
protected-mode no
#user default on nopass sanitize-payload ~* &* +@all
requirepass "lzjasdqq"


vim  /usr/lib/systemd/system/sentinel.service
[Unit]
Description=redis-server
After=network.target

[Service]
Type=forking
# ExecStart需要按照实际情况修改成自己的地址
ExecStart=/usr/local/redis-6.2.6/bin/redis-server /etc/sentinel.conf --sentinel
PrivateTmp=true

[Install]
WantedBy=multi-user.target





# sentinel auth-pass <master-name> <password>
#
# Set the password to use to authenticate with the master and replicas.
# Useful if there is a password set in the Redis instances to monitor.
#
# Note that the master password is also used for replicas, so it is not
# possible to set a different password in masters and replicas instances
# if you want to be able to monitor these instances with Sentinel.
#
# However you can have Redis instances without the authentication enabled
# mixed with Redis instances requiring the authentication (as long as the
# password set is the same for all the instances requiring the password) as
# the AUTH command will have no effect in Redis instances with authentication
# switched off.
#
# Example:
#
# sentinel auth-pass mymaster MySUPER--secret-0123passw0rd

# sentinel auth-user <master-name> <username>

#sentinel auth pass<master name><password>
#
#设置用于与主服务器和副本进行身份验证的密码。
#如果要监视的Redis实例中设置了密码,则会很有用。
#
#请注意,主密码也用于副本,因此不是
#可以在主实例和副本实例中设置不同的密码
#如果您希望能够使用Sentinel监视这些实例。
#
#但是,您可以在不启用身份验证的情况下使用Redis实例
#与需要身份验证的Redis实例混合(只要
#对于所有需要密码的实例,密码集都是相同的)
#AUTH命

requirepass lzjasdqq
# You can configure Sentinel itself to require a password, however when doing
# so Sentinel will try to authenticate with the same password to all the
# group with the same "requirepass" password. Check the following documentation
# IMPORTANT NOTE: starting with Redis 6.2 "requirepass" is a compatibility
# the password for the default user. Clients will still authenticate using
# AUTH <password> as usually, or more explicitly with AUTH default <password>
# sentinel-user and sentinel-pass)
# The requirepass is not compatable with aclfile option and the ACL LOAD
# command, these will cause requirepass to be ignored.
# sentinel sentinel-pass <password>
# The password for Sentinel to authenticate with other Sentinels. If sentinel-user
# is not configured, Sentinel will use 'default' user with sentinel-pass to authenticate.
# The following arguments are passed to the script:

#您可以将Sentinel本身配置为需要密码,但在执行操作时
#因此Sentinel将尝试使用相同的密码对所有
#具有相同“requirepass”密码的组。检查以下文档
#重要提示:从Redis 6.2“requirepass”开始是一种兼容性
#默认用户的密码。客户端仍将使用进行身份验证
#AUTH<password>通常,或者更明确地使用AUTH默认<password>
#sentinel用户和sentinel通行证)
#requirepass与aclfile选项和ACL LOAD不兼容
#命令,这些将导致requirepass被忽略。
#sentinel sentinel pass<password>
#Sentinel与其他Sentinel进行身份验证的密码。如果哨兵用户
#未配置,Sentinel将使用具有Sentinel通行证的“默认”用户进行身份验证。
#将以下参数传递给脚本:



root@host1 ~]# redis-cli -p 26379
127.0.0.1:26379> auth lzjasdqq
OK
127.0.0.1:26379> info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=192.168.40.130:6380,slaves=2,sentinels=1



测试:停止6380的redis
[root@host1 redis]# ss -ntlp|grep 6380
LISTEN     0      511          *:6380                     *:*                   users:(("redis-server",pid=8572,fd=6))
LISTEN     0      511       [::]:6380                  [::]:*                   users:(("redis-server",pid=8572,fd=7))
[root@host1 redis]# kill -9 8572


127.0.0.1:26379> info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=192.168.40.130:6381,slaves=2,sentinels=1


查看到master已经切换到6381

SENTINEL masters     //列出所有监控的主服务器
SENTINEL slaves <master name>         //获取指定redis集群的从节点

SENTINEL get-master-addr-by-name <master name>        //根据指定master的名称获取其IP
SENTINEL reset         //用于重置,包括名称,清除服务器所有运行状态,故障转移、等等
SENTINEL failover <master name>        //手动向某一组redis集群发起执行故障转移


SENTINEL get-master-addr-by-name mymaster 
SENTINEL failover mymaster

127.0.0.1:26379> SENTINEL get-master-addr-by-name mymaster 
1) "192.168.40.130"
2) "6379"

 

   

标签:requirepass,redis,lzjasdqq,Sentinel,sentinel,password
From: https://www.cnblogs.com/lzjloveit/p/18183802

相关文章

  • redis持久化
    redis持久化rdbaofvimredis.confprotected-modeyesport6379tcp-backlog511timeout0tcp-keepalive300daemonizeyespidfile/var/run/redis_6379.pidloglevelnoticelogfile"/var/log/redis/redis.log"databases16always-show-logonoset-p......
  • redis下载和redisUI下载
    Redis安装与RedisUI的安装首先打开这个链接https://www.lanzouw.com/iuPGj1y86lja下载好redis文件看图点击redis-desktop-manager-2019.4.0.exe文件下载redisUI无脑一直next就行了第二步1.解压redis文件得到......
  • .NET 缓存:内存缓存 IMemoryCache、分布式缓存 IDistributedCache(Redis)
    .NET缓存:内存缓存IMemoryCache、分布式缓存IDistributedCache(Redis)  .NET缓存里分了几类,主要学习内存缓存、分布式缓存一、内存缓存IMemoryCache1、Program注入缓存builder.Services.AddMemoryCache();2、相关方法及参数Get、TryGetValue、GetOrCreate、GetOrCrea......
  • Redis随手笔记
    1内存(RAM)和磁盘(如HDD或SSD)的读写速度差异内存(RAM)和磁盘(如HDD或SSD)的读写速度差异很大,这是因为它们基于完全不同的技术和物理原理。内存的访问速度远快于磁盘。内存(RAM):数据是直接在CPU可以快速访问的内存芯片上进行读写的。内存访问的延迟通常在几十纳秒(ns)范围内,数据传输速率......
  • redis三主三从集群快速搭建
    redis集群快速搭建 1本文以redis6.2.6版本为例,快速搭建一套三主三从的redis集群,已经提前将脚本写好,只需要在节点上面进行执行即可安装#!/bin/bashinstall_redis(){#解压Redis源码包tar-zxvfredis-6.2.6.tar.gz......
  • 记一次线上Redis内存占用过高、大Key问题的排查
    问题背景在一个风和日丽的下午,公司某项目现场运维同学反馈,生产环境3个Redis的Sentinel集群节点内存占用都很高,达到了17GB的内存占用量。稍加思索,应该是某些Key的Value数据体量过大,占用了过多的内存空间,我们在使用Redis的过程中,单个Value或者单个集合中的元素应该保证不超过10KB,......
  • redis、LVS、nginx的基本使用方法
    redis、LVS、nginxredis搭建哨兵原理哨兵搭建至少要有3个机器,且必须为奇数个redis搭建哨兵之前要先实现主从复制;master的配置文件中的masterauth和slave都必须相同实现主从复制之所有从节点配置文件[root@slave~]#yuminstall-yredis[root@slave~]#vim/etc/redis.c......
  • Redis热点key大key
    一、热点key问题  1、商品秒杀、热点新闻、热点评论等读多写少的场景,可能会造成一个较大的请求Redis量,这种情况下就会造成热点Key问题。  2、请求分片集中,超过单台Redis服务器的性能极限。    手动分片或者custer分片切分,刚好一致性hash落入同一台redis服务器,数据倾......
  • Redis的监控指标
    一、内存使用情况  redis-cliinfo#memory1、总内存使用量(80%)。used_memory实际使用内存  used_memory_peak峰值,used_memory_rss系统分配给redis的总内存大小,包含内存碎片。2、内存碎片。mem_fragmentation_ratio=used_memory_rss/used_memory    <1表示Redi......
  • 5个.Net版本 Redis 客户端开源库
    Redis作为一个高性能(NOSQL)的key-value数据库,在实际项目开发中运用非常广泛,也适用于很多业务场景。下面介绍5个.Net版本Redis客户端开源库,方便开发和提升效率。1、StackExchange.Redis简介:由StackExchange团队开发。它提供了丰富的功能和选项,如连接池、管道、事务、发布/订阅......