Get the App
SLTechnology News&Howtos  ›  Database  › 

Simple installation and use of redis for nosql

Shulou Source: shulou.com Published: 2022-06-01 21:29:17 10月12日 Update

Redis basic application scenarios:

Session sharing among web, that is, multiple war projects share a single session

Distributed cache, because redis stores key-value pairs and provides rich adapter to support C,. Net and java clients, so data exchange between platforms plays a role.

Therefore, it can be used as a distributed cache for large systems, and its setnx lock is often used in e-commerce scenarios such as killing seconds and grabbing red packets.

Download: redis: http://download.redis.io/releases/

Redis compilation and installation

Tar xf redis-3.0.7.tar.gz

Cd redis-3.0.7

Make

Make PREFIX=/usr/local/redis install

Mkdir-p / usr/local/redis/ {data,etc,var}

Modify the configuration file:

Daemonize yes: running as background daemon

Logfile / usr/local/redis/var/redis.log: put the log in the var directory you just created

Dir "/ usr/local/redis/data": the location of the data directory

Save 900 1

# save 300 10

# save 60 10000

# redis writes once every 900 seconds, 10 times in 300 seconds, and 10,000 times in 60 seconds. This strategy places the cache in a disk file called .rdb.

# if by default, these three strategies will take turns to take effect in a large concurrency environment

# such a write policy will have a huge impact on our performance, so we only keep this policy once in 900 seconds

Appendonly no: the AOF function of Redis is turned off.

Vim / etc/profile.d/redis.sh

Export PATH=$PATH:/usr/locl/redis/bin

. / etc/profile.d/redis.sh

Redis.conf cp to the / usr/local/redis/etc directory

Start the redis service

Redis-server / usr/local/redis/etc/redis.conf

Log in to the client:

Redis-cli command

Redis-cli-p port-h ip

Redis-cli-p 6379-h 127.0.0.1

Shut down the redis service command:

Redis-cli shutdown (- p can also specify a port)

Observe the log and find the error as follows:

WARNING: The TCP backlog setting of 511 cannot be enforced because / proc/sys/net/core/somaxconn is set to the lower value of 128.

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.

1. Echo 511 > / proc/sys/net/core/somaxconn

Or sysctl-w / proc/sys/net/core/somaxconn=511

2. Echo 1 > / proc/sys/vm.overcommit_memory

Sysctl-p

Overcommit_memory parameter description: http://skly-java.iteye.com/blog/2167400

Optional values: 0, 1, 2.

0, which means that the kernel will check whether there is enough memory available for the application process; if there is enough memory available, the memory request is allowed; otherwise, the memory request fails and the error is returned to the application process.

1, which means that the kernel allows all physical memory to be allocated, regardless of the current memory state.

2, indicating that the kernel allows more than the sum of all physical memory and swap space to be allocated

Note: note: when redis dump data, it will fork a child process. Theoretically, the memory occupied by the child process is the same as that of parent. For example, the memory occupied by parent is 8 GB.

At this time, it is also necessary to allocate 8 gigabytes of memory to child. If the memory is not affordable, it will often result in excessive download or IO load on the redis server, resulting in a decline in efficiency.

So the optimized memory allocation policy here should be set to 1 (meaning that the kernel allows all physical memory to be allocated, regardless of the current memory state).

Tags: Memory policy allocation kernel process data physics directory cache service distribution command scenario client client file log time status error Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Huawei Xiaomi MySQL Microsoft