GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 添加 redis7 哨兵搭建教程 · wodeu2/PassJava-Learning@cc7eb30

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs
    • 08.Redis
      • 16.Redis7_sentinel.md
    • _sidebar.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs/08.Redis/16.Redis7_sentinel.md‎

Copy file name to clipboard
+247Lines changed: 247 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
> 作者:十二
2+
>
3+
> 日期:2023-07-19
4+
5+
# Centos7+ Redis7.0.12搭建主从+哨兵模式 超详细教程攻略
6+
7+
## 安装 gcc 依赖
8+
9+
Redis是基于C语言编写的,所有安装Redis之前需要gcc依赖
10+
11+
```shell
12+
yum install -y gcc tcl
13+
```
14+
15+
## 安装 redis
16+
17+
把安装包放入 usr目录,下载好的安装包直接拖入即可
18+
解压
19+
进入redis7.0.12
20+
使用make 命令进行编译将.c文件编译成.o文件
21+
编译成功之后会出现“It's a good idea to run 'make test'”的提示
22+
![img](http://cdn.jayh.club/uPic/image-20230719170524352z0MdFjqAhB7D.png)
23+
使用命令 进行安装
24+
![img](http://cdn.jayh.club/uPic/image-20230719170534030CmDU1k7JtZVz.png)
25+
安装完后,在/usr/local/redis/bin下有几个可执行文件可以查看
26+
![img](http://cdn.jayh.club/uPic/image-20230719170539158yBxBzra1V3dC.png)
27+
28+
## 修改 Redis 配置文件
29+
30+
Redis启动需要一个配置文件,可以修改端口号等信息
31+
32+
安装目录下将redis.conf文件拷贝到/usr/local/redis目录中
33+
34+
```shell
35+
cp redis.conf /usr/local/redis
36+
```
37+
38+
39+
40+
进入 /usr/local/redis
41+
42+
43+
44+
```plain
45+
cd /usr/local/redis
46+
```
47+
48+
49+
50+
修改配置文件redis.conf
51+
52+
53+
54+
```plain
55+
vim redis.conf
56+
```
57+
58+
59+
60+
```xml
61+
将bind 127.0.0.1 -::1 替换为 bind 0.0.0.0
62+
将 daemonize on 替换成 daemonize yes
63+
requirepass xxxx 设置密码
64+
将protected-mode yes 改为no
65+
日志logfile “./redis.log”
66+
masterauth xxxx <设置密码>
67+
```
68+
69+
70+
71+
```xml
72+
注意:从服务器把修改replicaof <主服务器ip 端口> ----------------**主服务器不用配**
73+
```
74+
75+
76+
77+
保存
78+
79+
80+
81+
```plain
82+
:wq
83+
```
84+
85+
86+
87+
加权限
88+
89+
90+
91+
```plain
92+
chmod 777 redis.conf
93+
```
94+
95+
96+
97+
使用bin/redis-server ./redis.conf启动redis服务
98+
99+
100+
101+
```plain
102+
./bin/redis-server ./redis.conf
103+
```
104+
105+
106+
107+
使用命令ps -ef|grep redis查看已经启动的redis服务关闭redis服务 ps -ef|grep redis
108+
109+
110+
111+
![img](http://cdn.jayh.club/uPic/image-202307191706034987EyitmAZ9TRx.png)
112+
113+
114+
115+
使用./bin/redis-cli 命令进入到redis的客户端
116+
117+
```plain
118+
./bin/redis-cli
119+
```
120+
121+
测试安装是否成功
122+
123+
![](http://cdn.jayh.club/uPic/image-20230719170610152gpO2NUrVdTic.png)
124+
125+
126+
127+
128+
129+
## 哨兵配置
130+
131+
修改/usr/redis-7.0.12/sentinel.conf中的配置
132+
133+
```shell
134+
#护模式关闭,这样其他服务起就可以访问此台redis
135+
protected-mode no
136+
137+
#端口
138+
port 26379
139+
140+
# 哨兵模式是否后台启动,默认no,改为yes
141+
daemonize yes
142+
143+
pidfile "/var/run/redis-sentinel.pid"
144+
145+
# log日志保存位置
146+
logfile "/usr/local/redis/sentinel/redis-sentinel.log"
147+
148+
# 工作目录
149+
dir "/usr/redis-7.0.12"
150+
151+
# master主机ip地址
152+
sentinel monitor mymaster <主服务器机ip> 6379 2
153+
154+
# master中redis的密码
155+
156+
sentinel auth-pass mymaster XXXX
157+
158+
# 哨兵从master节点宕机后,等待多少时间(毫秒),认定master不可用。默认30s
159+
sentinel down-after-milliseconds mymaster 30000
160+
161+
#如果报错注释掉 acllog-max-len 128
162+
acllog-max-len 128
163+
164+
165+
# 当替换主节点后,剩余从节点重新和新master做同步的并行数量,默认为 1
166+
sentinel parallel-syncs mymaster 1
167+
168+
169+
# 主备切换的时间,若在3分钟内没有切换成功,换另一个从节点切换
170+
sentinel failover-timeout mymaster 180000
171+
172+
173+
#如果报错注释掉下面内容根据情况注释
174+
sentinel deny-scripts-reconfig yes
175+
176+
SENTINEL resolve-hostnames no
177+
178+
SENTINEL announce-hostnames no
179+
180+
SENTINEL master-reboot-down-after-period mymaster 0
181+
```
182+
183+
创建日志文件夹
184+
185+
```shell
186+
cd /usr/local/redis
187+
188+
mkdir sentinel
189+
```
190+
191+
启动所有哨兵
192+
193+
```shell
194+
cd /usr/local/redis/bin/
195+
196+
./redis-sentinel /usr/redis-7.0.12/sentinel.conf
197+
```
198+
199+
哨兵日志
200+
201+
```shell
202+
cd /usr/local/redis/sentinel/
203+
204+
tail -100f redis-sentinel.log
205+
```
206+
207+
![img](http://cdn.jayh.club/uPic/image-20230719170616509tGq1KFOPv19F.png)
208+
209+
启动命令合集
210+
211+
```shell
212+
#redis启动
213+
cd /usr/local/redis
214+
./bin/redis-server ./redis.conf
215+
216+
#哨兵启动
217+
cd /usr/local/redis/bin/
218+
./redis-sentinel /usr/redis-7.0.12/sentinel.conf
219+
220+
#redis客户端登录
221+
cd /usr/local/redis
222+
./bin/redis-cli
223+
224+
#redis 哨兵日志
225+
cd /usr/local/redis/sentinel/
226+
tail -100f redis-sentinel.log
227+
228+
#redis日志
229+
cd /usr/local/redis
230+
tail -100f redis
231+
```
232+
233+
## 附录
234+
235+
如果以下命令用不了,
236+
237+
```vue
238+
redis-cli -h 127.0.0.1 -p 26379 info Sentinel
239+
```
240+
241+
242+
243+
执行这个命令:
244+
245+
```vue
246+
sudo cp /usr/local/redis/bin/* /usr/local/bin/
247+
```
Collapse file

‎docs/_sidebar.md‎

Copy file name to clipboardExpand all lines: docs/_sidebar.md
+2-1Lines changed: 2 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240
* [05.5000字-24张图带你彻底理解Java中的21种锁](07.并发多线程/05.5000字-24张图带你彻底理解Java中的21种锁.md)
241241
* [06.干货-45张图庖丁解牛18种Queue,你知道几种?](07.并发多线程/06.干货-45张图庖丁解牛18种Queue,你知道几种.md)
242242

243-
* 八、Redis 进阶(14篇)🆕
243+
* 八、Redis 进阶(15篇)🆕
244244
* [00.Redis 源码下载](08.Redis/00.DownloadRedis.md)
245245
* [01.趣谈Redis之SDS](08.Redis/01.趣谈Redis之SDS.md)
246246
* [03.Redis的主从架构原理和部署](08.Redis/03.Redis的主从架构原理和部署.md)
@@ -249,6 +249,7 @@
249249
* [06.真枪实弹:Redis冷备如何做](08.Redis/06.真枪实弹:Redis冷备如何做.md)
250250
* [07.Redis主从架构搭建和压测](08.Redis/07.Redis主从架构搭建和压测.md)
251251
* [08.从单点 Redis 到 1 主 2 从 3 哨兵的架构演进之路](08.Redis/09.Redis开发手册.md)
252+
* [09.Redis7 哨兵搭建教程](08.Redis/16.Redis7_sentinel.md)
252253
* [面试题汇总 Redis 篇 第一季](08.Redis/10.Redis面试.md)
253254
* [11.缓存实战(一)](08.Redis/11.缓存实战(一).md)
254255
* [12.缓存实战(二)Redis分布式锁](08.Redis/12.缓存实战(二)Redis分布式锁.md)

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.