您当前的位置: 首页 >  docker

java持续实践

暂无认证

  • 3浏览

    0关注

    746博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

谷粒商城04-docker中安装redis

java持续实践 发布时间:2020-07-27 21:46:15 ,浏览量:3

docker中安装redis

下载redis镜像

[root@hadoop-104 ~]# docker pull redis
Using default tag: latest
latest: Pulling from library/redis
123275d6e508: Already exists 
f2edbd6a658e: Pull complete 
66960bede47c: Pull complete 
79dc0b596c90: Pull complete 
de36df38e0b6: Pull complete 
602cd484ff92: Pull complete 
Digest: sha256:1d0b903e3770c2c3c79961b73a53e963f4fd4b2674c2c4911472e8a054cb5728
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest

设置配置文件, 启动容器

[root@hadoop-104 ~]# mkdir -p /mydata/redis/conf
先创建 redis.conf文件
[root@hadoop-104 ~]# touch /mydata/redis/conf/redis.conf
[root@hadoop-104 ~]# echo "appendonly yes"  >> /mydata/redis/conf/redis.conf
启动Redis容器 
[root@localhost conf]# docker run -p 6379:6379 --name redis -v /mydata/redis/data:/data \
> -v/mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
> -d redis redis-server /etc/redis/redis.conf
[root@hadoop-104 ~]# 

连接到docker的redis客户端进行测试

[root@localhost conf]# docker exec -it redis redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set a b
OK
127.0.0.1:6379> get a
"b"

设置Redis的AOF持久化 , 如果不设置持久化, 那么每次Redis容器重启, 数据都会丢失。 cd /mydata/redis/conf vi redis.conf 在此配置文件中,加入如下的一行数据 appendonly yes 配置完成后, 重启Redis [root@localhost conf]# docker restart redis

重启Redis后, 进行如下的实验, 设置一个key ,再次重启Redis ,可以看到依然可以通过key获取值,成功的设置了持久化。

[root@localhost conf]# docker exec -it redis redis-cli
127.0.0.1:6379> set a b
OK
127.0.0.1:6379> get a
"b"
127.0.0.1:6379> exit
[root@localhost conf]# docker restart redis
redis
[root@localhost conf]# docker exec -it redis redis-cli
127.0.0.1:6379> get a
"b"
127.0.0.1:6379>

设置redis容器在docker启动的时候启动

[root@localhost vagrant]# docker update redis --restart=always
redis
[root@localhost vagrant]#

使用redis-desktop-manager-0.8.8.384进行连接, 密码填写空的 Redis 官方的配置文件地址 https://raw.githubusercontent.com/antirez/redis/6.0/redis.conf

关注
打赏
1658054974
查看更多评论
立即登录/注册

微信扫码登录

0.0398s