安装 redis
docker pull redis
安装好之后使用查看镜像
docker images
truedei@truedei:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 987b78fc9e38 10 days ago 104MB
httpd latest a8a9cbaadb0c 2 weeks ago 166MB
fjudith/draw.io latest 7b136fc80d31 3 weeks ago 683MB
mysql 5.7.29 f5829c0eee9e 5 weeks ago 455MB
新建挂载文件
因为 redis 默认配置你会发现只能够本地连接,不能进行远程访问,使用 Redis Desktop Manager 连接都会报错,因此需要手动挂载 redis 配置文件
-
新建配置文件
因为需要 redis 的配置文件,这里最好还是去 redis 的官方去下载一个 redis 使用里面的配置文件即可
redis 中文官方网站:http://www.redis.cn/download.html
下载后解压出来
-
配置 redis.conf 配置文件
bind 127.0.0.1 #注释掉这部分,使 redis 可以外部访问
daemonize no#用守护线程的方式启动
requirepass 你的密码#给 redis 设置密码
appendonly yes#redis 持久化 默认是 no
tcp-keepalive 300 #防止出现远程主机强迫关闭了一个现有的连接的错误 默认是 300
-
创建本地与 docker 映射的目录,即本地存放的位置
truedei@truedei:redis-5.0.5$ sudo mkdir /usr/local/docker/
把配置文件拷贝到刚才创建好的文件夹里
启动 redis
sudo docker run -p 6379:6379 --name redis --restart always -v /usr/local/docker/redis.conf:/etc/redis/redis.conf -v /usr/local/docker/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes
参数解释:
-p 6379:6379:把容器内的 6379 端口映射到宿主机 6379 端口
-v /usr/local/docker/redis.conf:/etc/redis/redis.conf:把宿主机配置好的 redis.conf 放到容器内的这个位置中
-v /usr/local/docker/data:/data:把 redis 持久化的数据在宿主机内显示,做数据备份
redis-server /etc/redis/redis.conf:这个是关键配置,让 redis 不是无配置启动,而是按照这个 redis.conf 的配置启动
–appendonly yes:redis 启动后数据持久化
查看是否启动成功
docker ps
truedei@truedei:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
85cb7d83a2ff redis "docker-entrypoint.s…" 7 minutes ago Up 7 minutes 0.0.0.0:6379->6379/tcp redis
0a122a08125f mysql:5.7.29 "docker-entrypoint.s…" 5 weeks ago Up About an hour 0.0.0.0:3306->3306/tcp, 33060/tcp mysql57
truedei@truedei:~$
可以查看一下日志:
sudo docker logs redis
truedei@truedei:~$ sudo docker logs redis
1:C 29 May 2020 01:16:22.107 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 29 May 2020 01:16:22.107 # Redis version=6.0.3, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 29 May 2020 01:16:22.107 # Configuration loaded
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.0.3 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 1
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
1:M 29 May 2020 01:16:22.108 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 29 May 2020 01:16:22.108 # Server initialized
1:M 29 May 2020 01:16:22.108 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1:M 29 May 2020 01:16:22.108 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
1:M 29 May 2020 01:16:22.108 * Ready to accept connections
truedei@truedei:~$
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于