压缩包安装 https://redis.io/download cd /home/wget https://download.redis.io/releases/redis-6.2.5.tar.gz tar -zxf redis-6.2.5.tar.gz cd redis-6.2.5/make && make install --prefix=/usr/local/redis/ mkdir -p /usr/local/redis/confcp redis.conf /usr/local/redis/conf
Docker安装Redis mkdir -p /home/docker/redis/data
将以下内容保存到 /home/docker/redis/docker-compose.yml /home/docker/redis/docker-compose.yml version: "3" services: redis: container_name: redis image: redis:latest environment: redisPwd: 123456 ports: - 6806 :6379 restart: always command: /bin/bash -c "redis-server /etc/redis/redis.conf" volumes: - ./redis.conf:/etc/redis/redis.conf - ./healthcheck.sh:/etc/redis/healthcheck.sh - ./data:/data healthcheck: test: ["CMD" , "/bin/bash" , "/etc/redis/healthcheck.sh" ] interval: 1m30s timeout: 30s retries: 3
将以下内容保存到 /home/docker/redis/healthcheck.sh /home/docker/redis/healthcheck.sh host="$(hostname -i || echo '127.0.0.1')" result="$(redis-cli -h ${host} -a ${redisPwd} ping)" if [ $result = 'PONG' ]; then exit 0; else exit 1 fi
将以下内容保存到 /home/docker/redis/redis.conf /home/docker/redis/redis.conf bind 0.0.0.0 daemonize no pidfile /var/run/redis_6806.pid port 6379 tcp-backlog 511 timeout 0 tcp-keepalive 0 loglevel notice logfile "" databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump.rdb dir ./ slave-serve-stale-data yes slave-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no slave-priority 100 requirepass 123456 maxmemory 1gb 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-rewrite-incremental-fsync yes lua-time-limit 5000 cluster-enabled no cluster-config-file nodes-6379.conf cluster-node-timeout 15000 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-entries 512 list-max-ziplist-value 64 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10
执行命令安装rediscd /home/docker/redis # 确保docker已经启动,若已经启动则忽略这条命令 systemctl restart docker docker-compose up -d
一键安装 mkdir -p /home/docker/redis/dataecho " version: \"3\" services: redis: container_name: redis image: redis:latest environment: redisPwd: 123456 # 这里填redis.conf配置这里填redis配置文件中的密码 ports: - 6806:6379 restart: always command: /bin/bash -c \"redis-server /etc/redis/redis.conf\" volumes: - ./redis.conf:/etc/redis/redis.conf - ./healthcheck.sh:/etc/redis/healthcheck.sh - ./data:/data healthcheck: test: [\"CMD\", \"/bin/bash\", \"/etc/redis/healthcheck.sh\"] interval: 1m30s timeout: 30s retries: 3 " > /home/docker/redis/docker-compose.ymlecho " host=\"$(hostname -i || echo '127.0.0.1') \" result=\"$(redis-cli -h ${host} -a ${redisPwd} ping) \" if [ $result = 'PONG' ]; then exit 0; else exit 1 fi" > /home/docker/redis/healthcheck.shecho " bind 0.0.0.0 daemonize no pidfile /var/run/redis_6806.pid port 6379 tcp-backlog 511 timeout 0 tcp-keepalive 0 loglevel notice logfile \"\" databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump.rdb dir ./ slave-serve-stale-data yes slave-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no slave-priority 100 requirepass 123456 maxmemory 1gb 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-rewrite-incremental-fsync yes lua-time-limit 5000 cluster-enabled no cluster-config-file nodes-6379.conf cluster-node-timeout 15000 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-entries 512 list-max-ziplist-value 64 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10" > /home/docker/redis/redis.confcd /home/docker/redissystemctl restart docker docker-compose up -d