今天给大家分享docker安装Redis图文教程,服务器版本为Centos8,希望对大家能有所帮助!
1.官网镜像版本查找https://hub.docker.com/
2、拉取redis镜像docker pullredis:7.0.2拉取redis镜像页面如下:
3、创建redis 服务器挂在目录mkdir /home/redismkdir /home/redis/datamkdir /home/redis/conf
4、下载redis.conf 文件dockers 下载的redis 默认是没有 redis.conf 文件的,需要从官网下载,也可以使用我下载好的redis.conf 文件。对应的版本是7.0.2 。下载后将文件上传到 /home/redis/conf 里面去。redis.conf 文件内容如下 已经去掉注释,如果需要特殊的配置去管网查看即可。
# Redis configuration file example.# bind 127.0.0.1 -::1 #外网访问需要注释掉protected-mode yesport 6379tcp-backlog 511timeout 0tcp-keepalive 300daemonize nopidfile /var/run/redis_6379.pidloglevel noticelogfile ""databases 16always-show-logo noset-proc-title yesproc-title-template "{title} {listen-addr} {server-mode}"stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbrdb-del-sync-files nodir ./replica-serve-stale-data yesreplica-read-only yesrepl-diskless-sync yesrepl-diskless-sync-delay 5repl-diskless-sync-max-replicas 0repl-diskless-load disabledrepl-disable-tcp-nodelay noreplica-priority 100acllog-max-len 128lazyfree-lazy-eviction nolazyfree-lazy-expire nolazyfree-lazy-server-del noreplica-lazy-flush nolazyfree-lazy-user-del nolazyfree-lazy-user-flush nooom-score-adj nooom-score-adj-values 0 200 800disable-thp yesappendonly yesrequirepass 654321appendfilename "appendonly.aof"appenddirname "appendonlydir"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yesaof-use-rdb-preamble yesaof-timestamp-enabled noslowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-listpack-entries 512hash-max-listpack-value 64list-max-listpack-size -2list-compress-depth 0set-max-intset-entries 512zset-max-listpack-entries 128zset-max-listpack-value 64hll-sparse-max-bytes 3000stream-node-max-bytes 4096stream-node-max-entries 100activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit replica 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10dynamic-hz yesaof-rewrite-incremental-fsync yesrdb-save-incremental-fsync yesjemalloc-bg-thread yes
5、启动redisdocker run -p 6379:6379 --name redis -v /home/redis/conf/redis.conf:/etc/redis/redis.conf -v /home/redis/data:/data -d redis:7.0.2 redis-server /etc/redis/redis.conf --appendonly yes参数说明:
- p 6379:6379 端口映射:前表示宿主主机部分:后表示容器部分。--name redis 指定该容器名称,方便后续的查看和操作。-v 挂载目录,规则与端口映射相同。-d redis 表示后台启动redisredis-server /etc/redis/redis.conf 以配置文件启动redis,加载容器内的conf文件,最终找到的是挂载的目录/home/redis/conf/redis.confappendonly yes 开启redis 持久化6、常用命令docker ps |grep redis #查看redis 是否启动成功
docker logs redis # 查看docker容器中的redis日志dockerexec-it redis /bin/bash #进入容器docker exec -it redis redis-server -v #查看redis版本 7.0.2设置防火墙命令systemctl start firewalld #启动防火墙firewall-cmd --zone=public --add-port=6379/tcp --permanent # 设置Redis 6379 端口:firewall-cmd --zone=public --add-port=9000/tcp --permanent 设置Portainer 9000 端口firewall-cmd --reload #刷新防火墙
停止、重启、删除命令
docker stop redis #停止docker start redis #重启docker rm redis #删除容器docker rmi redis #删除镜像