Docker下安装Redis超详细步骤
-
查看需要安装的镜像版本
- 搜索reids 2.点击标签 3.查看需要的版本
-
在安装好docker的linux中执行命令
拉取镜像
//拉取最新版本 docker pull redis //拉取指定版本 docker pull redis:6.0.8
查看是否拉取成功
docker images
去redis官网下载redis,然后在redis-7.0.0 edis-7.0.0找到redis.conf文件
修改文件中以下配置项:
1.将bind 127.0.0.1 -::1注释掉 # bind 127.0.0.1 -::1 2.将 appendonly no 设置成yes,开启redis数据持久化 appendonly yes 3.将 requirepass foobared 解开注释,设置密码 requirepass root 4.以下两项配置可选(如果不需要从外部连接,可不进行配置,以下配置有风险,请谨慎配置) 保护模式:如果设置为yes,那么只允许我们在本机的回环连接,其他机器无法连接,即外部无法连接,此处关闭 protected-mode no 将bind 127.0.0.1注释掉,此项配置的作用是服务绑定监听本机的哪个ip # bind 127.0.0.1
修改完毕后的完整redis.conf文件如下:
# bind 192.168.1.100 10.0.0.1 # bind 127.0.0.1 ::1 #bind 127.0.0.1 protected-mode no port 6379 tcp-backlog 511 requirepass root timeout 0 tcp-keepalive 300 daemonize no supervised no pidfile /var/run/redis_6379.pid loglevel notice logfile "" databases 30 always-show-logo yes save 900 1 save 300 10 save 60 10000 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-disable-tcp-nodelay no replica-priority 100 lazyfree-lazy-eviction no lazyfree-lazy-expire no lazyfree-lazy-server-del no replica-lazy-flush no appendonly yes appendfilename "appendonly.aof" 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-max-len 128 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 hz 10 dynamic-hz yes aof-rewrite-incremental-fsync yes rdb-save-incremental-fsync yes
在linux服务器中新建/home/redis/目录,将redis.conf文件上传至该目录
使用如下命令运行redis容器
docker run -p 6379:6379 --name myredis -v /home/redis/redis.conf:/etc/redis/redis.conf -v /home/redis/data:/data -d redis redis-server /etc/redis/redis.conf --requirepass "root"
查看是否运行成功
docker ps
内部连接redis
docker exec -it myredis redis-cli
输入密码
// auth 密码 auth root
存入数据
set name 1
获取数据
get name
至此安装结束
