| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx

# redis主从结构集群部署

0
Redis C/C++ 4391 次浏览

## 前期准备

### 安装redis(可以跳过)

参考[oneinstack安装](https://oneinstack.com/install/),只安装redis即可,选择性安装.将所有需要部署redis的服务器都装上redis

 

## 主服务器部署

编辑 `/usr/local/redis/etc/redis.conf`,根据实际情况修改以下项

```

daemonize yes //守护进程

pidfile "/var/run/redis.conf.pid" //pid路径

port 6379 //监听端口

bind 0.0.0.0 //绑定地址

timeout 300 //超时时间

loglevel notice //日志级别

logfile "/data/redis/redis-server.log" //日志路径

databases 16 //实例个数

save 900 1 //900秒有1个变化写磁盘

save 300 10 //300秒有10个变化写磁盘

save 60 10000 //60秒有10000个变化写磁盘

rdbcompression yes //支持RDB压缩

dbfilename "dump.rdb" //DB文件名

dir "/data/redis/lib" //RDB路径

slave-serve-stale-data yes //如果 slave-serve-stale-data 设置成 'yes' (the default) slave会仍然响应客户端请求,此时可能会有问题。

appendonly no //AOF关闭

appendfsync everysec //每秒进行一次写磁盘

no-appendfsync-on-rewrite no //append only 文件的自动重写, 当AOF 日志文件即将增长到指定百分比时,Redis可以通过调用BGREWRITEAOF 来自动重写append only文件。

list-max-ziplist-entries 512

list-max-ziplist-value 64 //如果set中整型元素的数量不超过512时,Redis将会采用该特殊编码

set-max-intset-entries 512

activerehashing yes //指定是否激活重置哈希,默认为开启

masterauth tieweishivps //认证密码

requirepass tieweishivps

```

## 从服务器部署

编辑 `/usr/local/redis/etc/redis.conf`,根据实际情况修改以下项

```

daemonize yes //守护进程

pidfile "/var/run/redis.conf.pid" //pid路径

port 6379 //监听端口

bind 0.0.0.0 //绑定地址

timeout 300 //超时时间

loglevel notice //日志级别

logfile "/data/redis/redis-server.log" //日志路径

databases 16 //实例个数

save 900 1 //900秒有1个变化写磁盘

save 300 10 //300秒有10个变化写磁盘

save 60 10000 //60秒有10000个变化写磁盘

rdbcompression yes //支持RDB压缩

dbfilename "dump.rdb" //DB文件名

dir "/data/redis/lib" //RDB路径

slave-serve-stale-data yes //如果 slave-serve-stale-data 设置成 'yes' (the default) slave会仍然响应客户端请求,此时可能会有问题。

appendonly no //AOF关闭

appendfsync everysec //每秒进行一次写磁盘

no-appendfsync-on-rewrite no //append only 文件的自动重写, 当AOF 日志文件即将增长到指定百分比时,Redis可以通过调用BGREWRITEAOF 来自动重写append only文件。

list-max-ziplist-entries 512

list-max-ziplist-value 64 //如果set中整型元素的数量不超过512时,Redis将会采用该特殊编码

set-max-intset-entries 512

activerehashing yes //指定是否激活重置哈希,默认为开启

masterauth tieweishivps //认证密码

requirepass tieweishivps

```

最后再redis.conf文件最下面添加一行配置

```

slaveof 主服务器ip地址 主服务器端口

```

## 测试

 

配置完成后,启动主服务器,然后再启动从服务器.然后在主服务器执行写入语句.

```

set name "123"

```

主服务器查看写入情况

```

get name

```

然后再从服务器查看写入情况

```

get name

```

二者的返回值都应该是123.如果返回值没有问题,说明配置成功.

 

81个答案

0

There is no set legal standard for this type of driveway, but you can consult an expert for advice on which products to use and how to properly care for them. you could look herego to this web-site

0

There is no set legal standard for this type of driveway, but you can consult an expert for advice on which products to use and how to properly care for them. you could look herego to this web-site

0

smm panel

This is really a nice and informative, containing all information and also has a great impact on the new technology. Thanks for sharing it

smm bear

0

SLOTXO

Online slots game, the number 1 popular in Thailand, apply again today, get slotxo auto bonus 100% immediately, first deposit 50% bonus.

0

pg 168

The latest with a game system designed for direct pg slot players because the game format is very advanced, can play pg slot auto via ios and android systems, supports playing pg slots via mobile Deposit-withdraw automatically in just 8 seconds

0

เกม250

Play online games, including many fun games for free, 250 free games, we have compiled 250 interesting games.

0

I am very much pleased with the contents you have mentioned. I wanted to thank you for this great article

indian smartpanel

0

pg Very good writing, I am happy to be able to visit this website 

0

pgslot

 I have express a few of the articles on your website now, and I really like your style of blogging. I added it to my favorite’s blog site list and will be checking back soon

0

เครดิตฟรี  Your article content is being interested by a lot of people, I am very impressed with your post. I hope to receive more good articles. 

0

slot We have included all web slots camps. already here The best new online slots website of the year 2021, the only website to play slots for all game camps. From leading camps across the country, including pg slot, joker game, slotxo, live22 and many others

0

สล็อต789Online slots no minimum deposit-withdrawal with automation As fast as 8 seconds, including online slots from leading slot game camps

0

ฝาก20รับ100New arrivals, latest 2021 with special conditions 20 get 100

0

slot currently has online slot games. Comes in a new format with 3D images as slots online, direct websites and leading game camps such as PG SLOT JOKER GAME, new member registration,

0

เครดิตฟรีcurrently has online slot games. Comes in a new format with 3D images as slots online, direct websites and leading game camps such as PG SLOT JOKER GAME, new member registration, 100% bonus and many more slots

0

PG SLOTThe latest with a game system designed for direct pg slot players because the game format is very advanced, can play pg slot auto via ios and android systems, supports playing pg slots via mobile Deposit-withdraw automatically in just 8 seconds

0

I will really appreciate the writer’s choice for choosing this excellent article.Here is deep description about the article matter which helped me more. smm bear

buy active youtube users in india

0

Very detailed instructions, thank you very much! I will share it! word counter online

0

Slot deposit 19 get the latest 100 2021 is a new pro slot and the strongest of the year Appealing to slot spinners with low budget who want to take money 19 baht to exchange money in the amount of 100 baht, which is considered very worthwhile because the promotion deposit 19 receives 100 unlimited withdrawals 19รับ100

0

A promotion that many people like and think that it is a worthwhile promotion. ฝาก20รับ100

1 2 3 4 5