当前位置:网站首页>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 usersudoCommand
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 .
边栏推荐
猜你喜欢

Y56. Chapter III kubernetes from entry to proficiency -- business image version upgrade and rollback (29)

Flutter TextField示例

CAD中能显示打印不显示
![[ 每周译Go ] 《How to Code in Go》系列文章上线了!!](/img/bf/77253c87bfa1512f4b8d3d8f7ebe80.png)
[ 每周译Go ] 《How to Code in Go》系列文章上线了!!

Huawei ENSP simulator configures DHCP for router

如何借助自动化工具落地DevOps

Shutter textfield example

Billions of citizens' information has been leaked! Is there any "rescue" for data security on the public cloud?

Render function and virtual DOM

Introduction to pressure measurement of JMeter
随机推荐
Nmap scan
华为ensp模拟器 给路由器配置DHCP
Go语言循环语句(第10课中3)
OMS系统实战的三两事
Jerry's ad series MIDI function description [chapter]
EhLib 数据库记录的下拉选择
改善机器视觉系统的方法
In the release version, the random white screen does not display the content after opening the shutter
开源之夏专访|Apache IoTDB社区 新晋Committer谢其骏
Flutter TextField示例
Y56. Chapter III kubernetes from entry to proficiency -- business image version upgrade and rollback (29)
Kubeadm初始化报错:[ERROR CRI]: container runtime is not running
Arcgis 10.2.2 | arcgis license server无法启动的解决办法
创客思维在高等教育中的启迪作用
Jerry's ad series MIDI function description [chapter]
For MySQL= No data equal to null can be found. Solution
CAD中能显示打印不显示
How to use concurrentlinkedqueue as a cache queue
Shutter WebView example
shp数据制作3DTiles白膜