参考博客:blog.csdn.net/qq_17040587… blog.csdn.net/promising52… zhuanlan.zhihu.com/p/611698321
1. openEuler上安装redis
1.1 上官网下载安装包 上传服务器
1.2 解压
tar -zxf redis-5.0.10.tar.gz
1.3 进入目录
cd redis-5.0.10
1.4 使用make进行安装
make install
1.5 启动命令
/usr/local/bin/redis-server
如果需要指定文件 redis-server /root/redis/redis-6.2.13/redis.conf
1.6 ps -ef|grep redis 查看启动是否完成
2.redis 设置远程连接
redis 设置远程连接 blog.csdn.net/qq_16525829… 将bind的地址127.0.0.1改成 0.0.0.0
允许远程连接
protected-mode no #设置后台启动
daemonize yes 防火墙开放端口
firewall-cmd --state #检查防火墙状态
systemctl restart firewalld.service #开启防火墙
firewall-cmd --zone=public --add-port=6379/tcp --permanent #开启6379端口
firewall-cmd --reload #重新载入配置
firewall-cmd --list-ports #查看已开放的端口
后台启动redis
切换到redis-server所在的目录下,执行以下命令来启动redis
redis-server /usr/local/redis-6.2.7/redis.conf
3,哨兵模式
3.1、在redis源码包目录下复制出sentinel.conf文件到redis安装的根目录并按如下修改
- sentinel1
# 开启守护线程的(后台)方式启动
daemonize yes
# 关闭保护模式
protected-mode no
# 哨兵服务默认端口是26379
port 26379
# 哨兵模式默认工作目录
dir /tmp
# 监控的redis主节点服务,mymaster是可自定义的服务名
# 2 代表有两个或两个以上的哨兵认为master不可用的时候,才会进行故障转移操作
sentinel monitor mymaster 192.168.31.161 8001 2
# redis.conf中开启了requirepass,所有连接Redis服务的客户端(包括哨兵)都要提供访问密码
sentinel auth-pass mymaster 123456
- sentinel2
daemonize yes
protected-mode no
port 26380
dir /tmp
sentinel monitor mymaster 192.168.31.161 8001 2
sentinel auth-pass mymaster 123456
- sentinel3
daemonize yes
protected-mode no
port 26381
dir /tmp
sentinel monitor mymaster 192.168.31.161 8001 2
sentinel auth-pass mymaster 123456
2、配置好三台机的sentinel.conf文件后,先启动三个Redis服务
./redis-sentinel ../sentinel.conf
再启动三个哨兵
**「启动三个哨兵:」**这里为了方便看日志,在sentinel.conf配置文件中可以先关闭后台启动方式
daemonize no
# 在redis的bin目录下执行
./redis-sentinel ../sentinel.conf
三个哨兵启动后,可在任一个中看到检测出的主从节点,已经另外两个哨兵(互相监控)