当前位置:网站首页>Redis03 - network configuration and heartbeat mechanism of redis
Redis03 - network configuration and heartbeat mechanism of redis
2022-07-04 21:36:00 【Half old 518】
front said
Author's brief introduction : Half old 518, Long distance runner , Determined to persist in writing 10 Blog of the year , Focus on java Back end
Column Introduction : thorough 、 comprehensive 、 Introduction of the system redis knowledge
The article brief introduction : Introduce Redis Network configuration and heartbeat mechanism
Redis Network configuration and heartbeat mechanism
Redis Under the installation root directory of redis.conf
The configuration file ,Redis This configuration file will be loaded at startup , Work according to the configuration at run time . Sometimes we take out this document , Store in a separate location , When starting, you must specify which configuration file to use , This document will take effect .Redis The network related configuration of is as follows .
bind
: binding IP Address , Other machines can use this IP visit Redis, The default binding 127.0.0.1, That is, any host ip Address , In order to facilitate safety control , We generally recommend changing it to fixed IP Address .port
: To configure Redis Ports occupied , The default is 6379.tcp-keepalive
:TCP Connect the survival strategy , Can pass tcp-keepalive Configuration item to set , The unit is in seconds , If set to 60 second , be server End meeting every 60 Second to connect idle clients once ACK request , To check if the client has hung up , For unresponsive clients, the connection is closed . If set to 0, No life preservation test will be carried out .
Demo Next , Execute the following command , Modify the bound ip Address .
/opt/redis-5.0.2$ sudo vim redis.conf
start-up redis The server .
redis-server redis.conf &
At this time, if there is no ip Executing client startup cannot start
redis-cli
An error is as follows .
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>
here ctrl
Add C
Back to the command line interface , Appoint ip And port startup .
[email protected]:/opt/redis-5.0.2$ redis-cli -h 192.168.199.213 -p 6379
192.168.199.213:6379>
If you need to close redis The server also needs to specify ip And port number , Because the closing operation is essentially a request sent by the client to the server .
redis-cli -h 192.168.199.213 -p 6379 shutdown
If you execute the above command, the following error message appears .
This is because of your redis-server Is it through root User initiated , and shutdown The operation needs to save the data , You need write permission to the file ( Local users may not ). At this point, we first shut down the server brutally redis-server
$ ps -ef|grep redis
wangzhou 7155 6648 0 16:39 pts/0 00:00:04 redis-server 192.168.199.213:6379
wangzhou 7877 6648 0 17:15 pts/0 00:00:00 grep --color=auto redis
$ kill -9 7155
Bring it with you when you restart the service sudo
sudo redis-server redis.conf &
Connect the client later , You can use the client to shut down the server normally .
TIPS:
Using the server is recommended in root Start or use under the usersudo
Command
Now please think about a question , The number of clients that the server can keep connected is limited , If the client does not actively disconnect after connecting , Is the connection always maintained ? Won't this waste our resources ? therefore ,redis The developers of provide a mechanism to deal with this situation . The server will send requests to the client regularly , If the client is still actually using the server , It will return " Activate " The state of . Parameters in the above configuration tcp-keepalive
It is used to set the time interval for the server to send requests .
In development , We generally recommend setting this time to 60s, Specifically, adjust according to the performance of the server .
边栏推荐
猜你喜欢
Methods of improving machine vision system
Jerry's ad series MIDI function description [chapter]
[public class preview]: basis and practice of video quality evaluation
华为ensp模拟器 DNS服务器的配置
Introduction to pressure measurement of JMeter
UTF encoding and character set in golang
【微信小程序】协同工作与发布
Billions of citizens' information has been leaked! Is there any "rescue" for data security on the public cloud?
Lambdaquerywrapper usage
Maya lamp modeling
随机推荐
数十亿公民信息遭泄漏!公有云上的数据安全还有“救”吗?
redis管道
Day24: file system
Drop down selection of Ehlib database records
输入的查询SQL语句,是如何执行的?
杰理之AD 系列 MIDI 功能说明【篇】
redis事务
Actual combat simulation │ JWT login authentication
[leetcode] 17. Letter combination of telephone number
Jerry's ad series MIDI function description [chapter]
Shutter WebView example
[ 每周译Go ] 《How to Code in Go》系列文章上线了!!
股票开户佣金最低多少,炒股开户佣金最低网上开户安全吗
OMS系统实战的三两事
MP3是如何诞生的?
Jerry's ad series MIDI function description [chapter]
解析steam教育中蕴含的众创空间
Kubeadm初始化报错:[ERROR CRI]: container runtime is not running
华为ensp模拟器 实现多个路由器的设备可以相互访问
华为ensp模拟器 DNS服务器的配置