Use docker to install redis5.0 in win10 and remove the warning

1. Premise

Please upgrade to the latest version of docker, because you need to use docker sysctlcommands, which are not available in older versions of docker.
The docker version used in this article is:Docker version 20.10.13, build a224086


2. Pull the image

powershellExecute in windows :

docker pull redis:5.0

Example of execution result:
insert image description here


3. Prepare the redis.conf configuration file

Prepare the redis.conf configuration file in the hard disk, the path example: E:\software\redis\docker-redis-config\redis.conf
the content of the file is as follows (please change the password on line 24 1234567890to your own password):

bind 0.0.0.0
protected-mode no
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
databases 16
always-show-logo no
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
requirepass 1234567890
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes

4. Add data folder

Create a new database folder on the hard disk E:\software\redis\docker-redis-data, which will be used later


5. Start redis in docker

Start command (also powershellexecuted in):

docker stop redis ; docker rm redis; docker run --privileged=true --sysctl net.core.somaxconn=4096 -p 6379:6379 --name redis -v /e/software/redis/docker-redis-config/redis.conf:/etc/redis/redis.conf -v /e/software/redis/docker-redis-data:/data -d redis:5.0 redis-server /etc/redis/redis.conf --appendonly yes; docker logs redis;

Command explanation:
docker stop redis: If the redis container already exists, stop it first
docker rm redis: If the redis container already exists, delete it first
docker run: Run the redis container
  --privileged=true: Start in privileged mode to facilitate subsequent modification of read-only files
  --sysctl net.core.somaxconn=4096: Modify the maximum listening queue length of the port to 4096 ( The default is 128, which is too low, and a warning will be reported)
  -p 6379:6379: specify that the ports in the host machine and the container are both 6379, :the former is the port of the host machine, :and the latter is the port in the container
  --name redis: the name of the container is redis
  -v /e/software/redis/docker-redis-config/redis.conf:/etc/redis/redis.conf: put the local hard disk The files in the container E:/software/redis/docker-redis-config/redis.confare mounted as files in the container /etc/redis/redis.conf(here /erefers to the E disk on Windows)
  -v /e/software/redis/docker-redis-data:/data: the reason is the same as above, omitted.
  -d: Run the container in the background
  redis:5.0: Name of the running image
  redis-server: Run the redis-server command in the image
  /etc/redis/redis.conf: The configuration file used by the redis-server command is /etc/redis/redis.conf
  --appendonly yes: the parameter of the redis-server command, which means that the persistence of redis is enabled
docker logs redis: display when docker starts redis log


6. Lift the warning

If there is a warning similar to the following after startup:

1:M 28 Mar 2022 09:04:01.744 # 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:M 28 Mar 2022 09:04:01.744 # 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.

Then powershellexecute the following command first:

docker exec -it redis /bin/bash

Command purpose: enter the redis container, use it /bin/bashas a shell
and execute the following commands inside the container:

echo 1 > /proc/sys/vm/overcommit_memory
echo never > /sys/kernel/mm/transparent_hugepagee/enabled

Reference picture:
insert image description here
After exiting, execute the command in the fifth step again, and there should be no warning.


end of text

Guess you like

Origin blog.csdn.net/h837087787/article/details/123799213