Docker初识:Redis服务的搭建(单机版)

一、版本说明:

系统:centos 7

docker:18

redis:6.0.3

二、单机服务搭建

1、下载redis

[root@VM_0_6_centos conf]# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
redis                       latest              987b78fc9e38        3 weeks ago         104MB

2、新建配置文件redis.conf

[root@VM_0_6_centos standalone]# ls
conf  data  
[root@VM_0_6_centos standalone]# pwd
/opt/redis/standalone
[root@VM_0_6_centos standalone]# cd conf/
[root@VM_0_6_centos conf]# ls
redis.conf

redis.conf

#绑定网卡IP
bind 0.0.0.0
#是否禁止公网访问redis cache 开启条件 没有bind IP  没有设置requirepass访问密码
protected-mode no
#是否开启守护模式
daemonize no
#aof日志 每次写操作都记录一条日志
appendonly yes
#是否开启集群
cluster-enabled no
#密码
requirepass 123456

3、启动命令

docker run -d  -p 6378:6379 --restart always --name redisStandalone -v /opt/redis/standalone/conf/redis.conf:/etc/redis/redis.conf -v /opt/redis/standalone/data:/etc/redis/data redis

4、查看镜像

[root@VM_0_6_centos conf]# docker ps -a
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS                     PORTS                              NAMES
ba0728d45348        redis                "docker-entrypoint.s…"   7 minutes ago       Up 7 minutes               0.0.0.0:6378->6379/tcp             redisStandalone

5、测试是否成功

[root@VM_0_6_centos conf]# docker exec -it ba0728d45348 /bin/bash
root@ba0728d45348:/data# redis-cli -p 6379 -c
127.0.0.1:6379>
127.0.0.1:6379>
127.0.0.1:6379> exit
root@ba0728d45348:/data# exit
exit
[root@VM_0_6_centos conf]#

或者使用RedisDesktopManager 连接查看。

6、遇到的问题。

6.1、ERR AUTH <password> called without any password configured for the default user. Are you sure your configuration is correct?

docker重启后,原设置的密码会失效,需要重新设置。(刚发现)

root@ba0728d45348:/data# redis-cli -h localhost
localhost:6379> auth 123456
(error) ERR AUTH <password> called without any password configured for the default user. Are you sure your configuration is correct?
localhost:6379> config get requirepass
1) "requirepass"
2) ""
localhost:6379> config set requirepass 123456
OK
localhost:6379> auth 123456
OK
localhost:6379>

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 Docker Compose 可以快速搭建 Redis 集群,实现高可用性和高性能的分布式缓存。下面是搭建 Redis 集群的步骤: 1. 创建一个 redis-cluster 的文件夹,在其中创建多个文件夹,每个文件夹代表一个 Redis 节点,例如 redis6479、redis6480 等。 2. 在每个节点文件夹中创建 docker-compose.yml 文件,文件内容如下: version: '3.3' services: redis: image: redis command: redis-server --appendonly yes ports: - "6379" volumes: - ./data:/data networks: - redis-cluster networks: redis-cluster: driver: bridge 3. 在每个节点文件夹中创建 redis.conf 文件,文件内容如下: port 6379 cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 appendonly yes 4. 在 redis-cluster 文件夹中创建 docker-compose.yml 文件,文件内容如下: version: '3.3' services: redis6479: network_mode: 'host' image: redis container_name: redis6479 restart: always logging: driver: 'json-file' options: max-size: '5g' volumes: - ./data:/data - ./redis.conf:/usr/local/etc/redis/redis.conf - ./logs:/logs command: redis-server /usr/local/etc/redis/redis.conf redis6480: network_mode: 'host' image: redis container_name: redis6480 restart: always logging: driver: 'json-file' options: max-size: '5g' volumes: - ./data:/data - ./redis.conf:/usr/local/etc/redis/redis.conf - ./logs:/logs command: redis-server /usr/local/etc/redis/redis.conf 5. 在 redis-cluster 文件夹中运行 docker-compose up 命令启动 Redis 集群。 相关问题: 1. Docker Compose 是什么? 2. Redis 集群有哪些优点? 3. 如何使用 Docker Compose 部署其他应用?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值