docker部署redis
1、查找redis镜像
docker search redis
2、下载镜像
docker pull redis
3、查看下载的镜像
docker images
4、创建目录结构
mkdir ./redis
mkdir ./redis/data
5、创建redis-create,sh文件
vi redis-create,sh
#/bin/bash
docker run -d --privileged=true -p 9998:6379 \
--name redis --restart always \
--volume /software/redis/redis.conf:/etc/redis/redis.conf \
--volume /software/redis/data:/data \
-m 300m \
--memory-swap=400m \
redis:latest redis-server /etc/redis/redis.conf --appendonly yes
参数说明: --privileged=true:容器内的root拥有真正root权限,否则容器内root只是外部普通用户权限 -v /docker/redis/redis.conf:/etc/redis/redis.conf:映射配置文件 -v /docker/redis/data:/data:映射数据目录 redis-server /etc/redis/redis.conf:指定配置文件启动redis-server进程 --appendonly yes:开启数据持久化 --name redis:容器名称
6、redis配置文件 路径 /software/redis/redis.conf
bind * protected-mode no port 6379 tcp-backlog 511 timeout 0 tcp-keepalive 300 supervised no pidfile /etc/redis/redis.pid 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 repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no slave-priority 100 maxmemory 500mb maxmemory-policy noeviction appendonly no 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 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 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 aof-rewrite-incremental-fsync yes requirepass 123456
7、执行启动
sh redis-create,sh
8、查看结果
9、测试