当前位置:网站首页>【部署】Redis
【部署】Redis
2022-07-16 19:58:00 【Learn Forever】
1.单实例部署
(1).下载安装包
Redis 官方网站 :https://redis.io/
(2).解压编译
tar -zxvf redis-5.0.4.tar.gz
cd redis-5.0.4/
make
运行结果:
(3).安装
make PREFIX=/usr/local/redis install
若redis.conf文件不存在,则从解压目录中复制过去
(4).修改配置-redis.cof
修改redis.conf文件:
- daemonize改为yes,
- 同时也将#bind 127.0.0.1注释,
- 将protected-mode设置为no。
- logfile “/usr/local/redis/logs/redis.log”
- dir “/usr/local/redis/bin”
- requirepass foobared 然后去掉注释,这个foobared改为自己的密码。
(5).启动redis
./bin/redis-server ./redis.conf
2.哨兵模式部署
(1).部署Redis一主两从
在三台机器上安装上述步骤部署redis后。
1).主
redis.conf
#1、redis默认不是以线程守护的方式运行的,如需要调整至线程守护的方式,请把
daemonize no => daemonize yes
#2、bind会限制能够访问redis的地址,默认(127.0.0.1)是指本地才能访问。如果要放开redis,如要搭建redis集群的话,要把bind注释掉;同时要把protected-mode从yes改为no
#bind 127.0.0.1
protected-mode yes => protected-mode no
#3、设定日志文件路径
logfile "/usr/local/redis/logs/redis.log"
#4. 指定本地数据库存放目录
dir ./
#修改dir ./为绝对路径,
#默认的话redis-server启动时会在当前目录生成或读取dump.rdb
#所以如果在根目录下执行redis-server /etc/redis.conf的话,
#读取的是根目录下的dump.rdb,为了使redis-server可在任意目录下执行
#所以此处将dir改为绝对路径
dir "/usr/local/redis/bin"
#5. 修改appendonly为yes
#指定是否在每次更新操作后进行日志记录,
#Redis在默认情况下是异步的把数据写入磁盘,
#如果不开启,可能会在断电时导致一段时间内的数据丢失。
#因为 redis本身同步数据文件是按上面save条件来同步的,
#所以有的数据会在一段时间内只存在于内存中。默认为no
appendonly yes
#6. 设置Redis连接密码,如果配置了连接密码,客户端在连接Redis时需要通过AUTH <password>命令提供密码,默认关闭
requirepass foobared
# 如果设置了密码:主从都要有requirepass 和 masterauth。因为哨兵模式下,主服务器会变成从服务器。
masterauth foobared
2).从
redis.conf
在上述主库基础上,增加下述配置
# 这里请注意,5.0 版本之前是使用 slaveof,5.0 版本之后的配置使用 replicaof,但是因为向下兼容的原则,就算你在 5.0 的版本中使用 slaveof 也不会有问题,但一般建议有新的就用新的吧,否则某天如果突然不支持旧的 slaveof 就 GG 了。
replicaof 192.168.31.168 9500
3).启动redis
./bin/redis-server ./redis.conf
4).查看主从关系是否配置成功
[[email protected] src]# ./redis-cli -h 192.168.31.168 -p 9500
192.168.31.168:9500> info replication
Replication
role:master
connected_slaves:2
slave0:ip=192.168.31.181,port=9501,state=online,offset=2235966,lag=1
slave1:ip=192.168.31.129,port=9502,state=online,offset=2235966,lag=1
master_replid:1df20ecc0df92307ef811e9bd81cc09e131725c7
master_replid2:0000000000000000000000000000000000000000
masterreploffset:2236538
........
[[email protected] src]# ./redis-cli -h 192.168.31.181 -p 9501
192.168.31.181:9501> info replication
Replication
role:slave
master_host:192.168.31.168
master_port:9500
masterlinkstatus:up
masterlastio_seconds_ago:0
mastersyncin_progress:0
slavereploffset:2317523
........
[[email protected] src]# ./redis-cli -h 192.168.31.129 -p 9502
192.168.31.129:9502> info replication
Replication
role:slave
master_host:192.168.31.168
master_port:9500
masterlinkstatus:up
masterlastio_seconds_ago:1
mastersyncin_progress:0
slavereploffset:2336225
........
(2).配置哨兵
修改每个 sentinel.conf
1).主、从
# bind 本机ip 127.0.0.1
bind 10.100.0.178 127.0.0.1
# 是否后台运行 设置成后台运行
daemonize yes
# sentinel日志文件
logfile "/usr/local/redis/logs/sentinel.log"
# 工作目录
dir /tmp
# 这里定义主库的IP和端口,还有最后的2表示要达到2台sentinel认同才认为主库已经挂掉(即客观失效),后面科普
sentinel monitor mymaster 192.168.31.168 9500 2
# 主库在30000毫秒(即30秒)内没有反应就认为主库挂掉(即主观失效)
sentinel down-after-milliseconds mymaster 30000
# 若新主库当选后,允许最大可以同时从新主库同步数据的从库数
sentinel parallel-syncs mymaster 1
# 若在指定时间(即180000毫秒,即180秒)内没有实现故障转移,则会自动再发起一次
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
#如果设置了密码,这块是要写的
sentinel auth-pass mymaster 密码
2).启动哨兵
./bin/redis-sentinel ./sentinel.conf
3).查看哨兵信息
/redis-cli -h 192.168.31.168 -p 26379
info sentinel

边栏推荐
- JS handwritten sort
- 操作dom逆序,面试题
- 博途PLC模糊PID在双容水箱液位控制上的应用(模糊和普通PID切换功能FB)
- JS Huawei od log time sorting
- Vs2017\vs2019\vs2022 project redundant files (intermediate files \ temporary files) one click clean bat
- 华为od js 日志排序
- 今天去 OPPO 面试,被问麻了
- Why is the count () method of MySQL so slow?
- Leetcode 1332. 删除回文子序列(看完题解才恍然大悟!!!!!!!)
- It's time to talk about RPA
猜你喜欢

What kind of wireless Bluetooth headset is good? Bluetooth headset with the best comprehensive performance
![[UCOS III source code analysis] - message queue](/img/e9/04fb629caa78513a1a6e8a4a98f452.png)
[UCOS III source code analysis] - message queue

Publication en niveaux de gris istio: déploiement du projet de microservice bookinfo

降噪蓝牙耳机哪个好?蓝牙耳机降噪推荐

1302_ Analysis of design and implementation of coroutine in FreeRTOS

C language - array

Spark streaming Programming Guide

Omnivore, a non picky AI model, focuses on images, videos and 3D data!

Student 985: why is C language still taught in schools| Send books at the end of the text

Istio灰度发布:部署Bookinfo微服务项目
随机推荐
毕业季--数据库常见面试题
SCI paper submission process
What are the main RPA manufacturers in the current mainstream
js 华为od日志时间排序
关于uni-cli项目管理uniapp编译包版本工具的使用总结
面试官:建造者模式是什么?
1302_ Analysis of design and implementation of coroutine in FreeRTOS
移动端设置小于12px字体,script标签
射击比赛的成绩 华为od js
高性价比模型 TSM,用 2D 的成本达到 3D 的效果
剑指 Offer 10- II. 青蛙跳台阶问题(4种解法)
Istio灰度发布:部署Bookinfo微服务项目
Leetcode 1342. 将数字变成 0 的操作次数
8080端口被占用怎么解决?Win11 8080端口被占用解决方法
Huawei od search for the same substring
Move blog to CSDN
JS handwritten sort
Which brand of Bluetooth headset has good noise reduction? Top 10 active noise reduction headphones
华为 od js 拼接URL
Vs2017\vs2019\vs2022 project redundant files (intermediate files \ temporary files) one click clean bat