美文网首页docker
docker 下安装 redis:5.0.9

docker 下安装 redis:5.0.9

作者: acc8226 | 来源:发表于2020-07-06 01:21 被阅读0次

    目前 5.x 系列中 5.0.9 为最新版本。

    docker pull redis:5.0.9
    

    $ docker pull redis:latest 为安装最新版本的redis.

    直接运行redis

    docker run --name myredis -d redis
    

    或者自定义配置conf

    docker run -itd --name my-redis -p 6379:6379 -v /home/docker-config/redis-config/redis.conf:/etc/redis/redis.conf redis:5.0.9 redis-server /etc/redis/redis.conf  --appendonly yes
    

    参数说明:

    • appendonly yes:开启数据持久化

    http://download.redis.io/releases/redis-5.0.9.tar.gz 官网扒下 redis.conf 配置文件。至此解决创建Redis容器没有conf配置文件的问题

    我们使用grep命令来简单的处理一个下,然后就可以看到redis.conf的所有配置信息,但是现在输入的命令是不可以编辑的
    命令cat redis.conf | grep -v "#" | grep -v "^$"

    redis.conf 修改说明

    1. bind 127.0.0.1 ::1 绑定的主机地址这一行注释掉。
    2. protected-mode 要设置成no (默认为yes的, 防止了远程访问,在redis3.2.3版本后)
    3. 设置密码
    4. 关闭守护进程 daemonize no redis默认不是以守护进程的方式运行,在开发过程中我们都会把这个配置开启 配置为yes 。
      然后在回顾一下docker run命令里边有一个参数 -d 这个参数也是以守护进程执行。
      这下应该就很清楚了,是redis.conf跟docker配置冲突
      打开配置文件把守护进程修改为no
    # bind 127.0.0.1
    
    protected-mode no
    
    requirepass useaverystrongpasswordfoobared666useaverystrongpassword888useaverystrongpassword999useaverystrongpassword110
    
    daemonize no
    

    redis.conf 提取的完整版

    protected-mode no
    port 6379
    tcp-backlog 511
    timeout 0
    tcp-keepalive 300
    daemonize no
    supervised no
    pidfile /var/run/redis_6379.pid
    loglevel notice
    logfile ""
    databases 16
    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-diskless-sync-delay 5
    repl-disable-tcp-nodelay no
    replica-priority 100
    requirepass useaverystrongpasswordfoobared666useaverystrongpassword888useaverystrongpassword999useaverystrongpassword110
    lazyfree-lazy-eviction no
    lazyfree-lazy-expire no
    lazyfree-lazy-server-del no
    replica-lazy-flush no
    appendonly no
    appendfilename "appendonly.aof"
    appendfsync everysec
    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-log-slower-than 10000
    slowlog-max-len 128
    latency-monitor-threshold 0
    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
    client-output-buffer-limit normal 0 0 0
    client-output-buffer-limit replica 256mb 64mb 60
    client-output-buffer-limit pubsub 32mb 8mb 60
    hz 10
    dynamic-hz yes
    aof-rewrite-incremental-fsync yes
    rdb-save-incremental-fsync yes
    

    通过 redis-cli 查看连接

    # 直接登录
    docker exec -it myredis redis-cli
    
    #  加 -a 表示通过密码登录
    docker exec -it myredis redis-cli -a useaverystrongpasswordfoobared666useaverystrongpassword888useaverystrongpassword999useaverystrongpassword110
    

    例如使用 windows 进行登录,举例登录到 ip: 117.x.x.x

    redis-cli.exe -h 117.x.x.x -a useaverystrongpasswordfoobared666useaverystrongpassword888useaverystrongpassword999useaverystrongpassword110
    

    相关文章

      网友评论

        本文标题:docker 下安装 redis:5.0.9

        本文链接:https://www.haomeiwen.com/subject/kfpbqktx.html