Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Redis3.2.3 installation

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

To install the master and slave of redis on centos7, record the installation process below.

Cd / appswget http://download.redis.io/releases/redis-3.2.3.tar.gztar-zxvf redis-3.2.3.tar.gzcd redis-3.2.3make make install

The directory under which redis is placed will be shown during installation: here is part of the installation process

XSLTPROC: / usr/bin/xsltprocXSLROOT: PREFIX: / usr/localBINDIR: / usr/local/binDATADIR: / usr/local/shareINCLUDEDIR: / usr/local/includeLIBDIR: / usr/local/libMANDIR: / usr/local/share/man

Redis is installed in the / usr/local,/usr/local/bin,/usr/local/share,/usr/local/include,/usr/local/lib,/usr/local/share/man directory

The software installation is complete. Here is the initialization data:

Change to the utils directory and execute the redis initialization script install_server.sh

Cd utils./install_server.sh Welcome to the redis service installerThis script will help you easily set up a running redis serverPlease select the redis port for this instance: [6379] Selecting default: 6379Please select the redis config file name [/ etc/redis/6379.conf] Selected default-/ etc/redis/6379.confPlease select the redis log file name [/ var/log/redis_6379.log] Selected default-/ var/log/redis_6379.logPlease select the data directory for this instance [/ var/lib/redis/6379] Selected Default-/ var/lib/redis/6379Please select the redis executable path [/ usr/local/bin/redis-server] Selected config:Port: 6379Config file: / etc/redis/6379.confLog file: / var/log/redis_6379.logData dir: / var/lib/redis/6379Executable: / usr/local/bin/redis-serverCli Executable: / usr/local/bin/redis-cliIs this ok? Then press ENTER to go on or Ctrl-C to abort.Copied / tmp/6379.conf = > / etc/init.d/redis_6379Installing service...Successfully added to CHK configs successful added to runlevels 345 starting Redis server...Installation successful!

After initialization

The configuration file is / etc/redis/6379.conf

The log file is / var/log/redis_6379.log

The data file dump.rdb is stored in the / var/lib/redis/6379 directory

The startup script is / etc/init.d/redis_6379

Check the log and find the following warning

28000:M 09 Sep 13:33:02.917 # WARNING: The TCP backlog setting of 511 cannot be enforced because / proc/sys/net/core/somaxconn is set to the lower value of 128.28000:M 09 Sep 13:33:02.917 # Server started, Redis version 3.2.328000:M 09 Sep 13:33:02.917 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory=1' to / etc/sysctl.conf and then reboot or run the command' sysctl vm.overcommit_memory=1' for this to take effect.28000:M 09 Sep 13 etc/sysctl.conf and then reboot or run the command 33 etc/sysctl.conf and then reboot or run the command 02.917 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > / sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your / etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.28000:M 09 Sep 13 The server is now ready to accept connections on port 33 02.917 * The server is now ready to accept connections on port 6379

The solution is as follows:

1. The first error is probably that the value of somaxconn is set too low. You can also know from the path / proc/sys/net/core/somaxconn that the setting of this value is limited to a certain maximum value in the network connection. This value indicates the queue size of the network connection. The "tcp-backlog 511" in the configuration file redis.conf is configured in the high concurrency environment. This value is limited by the somaxconn and tcp_max_syn_backlog values of the system, so you should increase the values of these two kernel parameters as follows:

$vim / etc/sysctl.conf

$net.core.somaxconn = 20480 # maximum queue length to handle sudden large concurrent connection requests. Default is 128,

$net.ipv4.tcp_max_syn_backlog = 20480 # semi-connection queue length, this value is limited by memory size, default is 1024

$sysctl-p # to make the parameter effective

2, warning: overuse of memory is set to 0! In a low-memory environment, background saving may fail. To fix this, add a 'vm.overcommit_memory=1'' item to / etc/sysctl.conf, and then restart (or run the command 'sysctl vm.overcommit_memory=1') to make it effective.

Different values of vm.overcommit_memory indicate:

0 checks to see if enough memory is available, and if so, allows allocation; if not, rejects the request and returns an error to the application.

1 allows requests to allocate more than physical memory plus swap memory

2 kernel always returns true

There are two kinds of data writeback mechanisms in redis.

Synchronous writeback is the SAVE command. The redis main process writes data directly to disk. When the amount of data is large, this command will block and take a long time to respond.

Asynchronous writeback is the BGSAVE command. The redis main process fork a child process, copying the memory of the main process and writing back data to disk through the child process.

Because fork a child process when the RDB file is written. It is equivalent to copying a memory image. At that time, the memory of the system was 4G, and redis occupied nearly 3G of memory, so it was certain that the memory could not be allocated. If vm.overcommit_memory is set to 0, new memory cannot be allocated if there is not enough available memory. If vm.overcommit_memory is set to 1. Then redis will use swapped memory.

Solution method

$vim / etc/sysctl

$vm.overcommit_memory = 1 # appended at the end

$sysctl-p # parameter takes effect

Note: swapping memory is not a perfect solution. The best way is to expand physical memory.

3Giant transparent Huge Pages (THP) alert, which is a topic about transparent memory giant pages. To put it simply, the smallest unit of manageable memory is page, and a page is usually 4kb, so there are 256 page,CPU in 1m memory to manage page table records through a built-in memory management unit. Huge Pages means that the size of page is larger than that of 4kb, usually 2m to 1G, and it is mainly used to manage super-large memory. Personal understanding of TB memory. THP is an abstract level of management Huge Pages, according to some data shows that THP will cause memory locks to affect performance, so it is generally recommended to turn off this feature.

/ sys/kernel/mm/transparent_hugepage/enabled has three values, as follows:

$cat / sys/kernel/mm/transparent_hugepage/enabled

Always [madvise] never

#

# always try to use transparent memory. Scan memory. 512 4k pages can be integrated into a 2m page.

# never is turned off without transparent memory

# madvise to avoid changing memory footprint

This is the end of the introduction to THP, and now some changes are made according to the warning:

$vim / etc/rc.local

$echo never > / sys/kernel/mm/transparent_hugepage/enabled # append this command to the boot script

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report