1、查看可用的 Redis 版本
访问 Redis 镜像库地址: https://hub.docker.com/_/redis?tab=tags。
2、取最新版的 Redis 镜像
docker pull redis:latest
3、查看本地镜像
docker images
4、创建外部挂载目录
mkdir -p /data/redis/redis_single/data
mkdir -p /data/redis/redis_single/conf
5、创建redis.conf文件
touch /data/redis/redis_single/conf/redis.conf
6、默认的redis.conf就是一个垃圾,放那么多的注释吃屎,我把注释都删了,这下世界清静了
bind 127.0.0.1 -::1
protected-mode yes
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
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir ./
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
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
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
jemalloc-bg-thread yes
6、创建并启动一个redis容器
docker run -d --name redis_single -p 6379:6379 -v /data/redis/redis_single/conf/redis.conf:/etc/redis/redis.conf -v /data/redis/redis_single/data:/data redis redis-server /etc/redis/redis.conf
参数说明:
-d 后台运行
-p 端口映射到主机的端口
-v 将主机目录挂载到容器的目录
redis-server /etc/redis/redis.conf 以指定的配置文件启动redis服务
7、查看启动成功的redis
docker ps
8、检查是否能在服务端登陆redis
docker exec -it redis_single redis-cli
成功!!
问题1、目前的redis只能在本机访问,为了能让外网访问,需要修改配置项
#bind 127.0.0.1 -::1
把这个注释掉,然后重启redis,所有的网络都可以访问redis了
docker restart redis_single
问题2、重启之后,外网还是不能访问,还需要修改一个配置项
protected-mode no
再重启,看看行不行。
成功了!!
问题3、总不能任何人都能访问吧,那不成公交车了,所以需要设置个密码
requirepass yourpassword
再重启,客户端再次访问就需要输入密码了!!
网友评论