zoukankan      html  css  js  c++  java
  • centos 7 redis4.0.11 主从

    redis-master:192.168.199.223

    redis-slave: 192.168.199.224

    mkdir -p /usr/local/log/
    cd /opt wget http://download.redis.io/releases/redis-4.0.11.tar.gz tar zxvf redis-4.0.11.tar.gz mv redis-4.0.11 redis cd redis make&&make install
    redis-master配置文件
    [root@test ~]# cat /opt/redis/redis.conf |grep -Ev '^$|^#'

    redis-master配置文件
    [root@test ~]# cat /opt/redis/redis.conf |grep -Ev '^$|^#'
    bind 192.168.199.223
    protected-mode yes
    port 6379
    tcp-backlog 511
    timeout 0
    tcp-keepalive 300
    daemonize yes
    supervised no
    pidfile /var/run/redis_6379.pid
    loglevel notice
    logfile "/usr/local/log/redis-6379.log"
    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 ./
    slave-serve-stale-data yes
    slave-read-only yes
    repl-diskless-sync no
    repl-diskless-sync-delay 5
    repl-disable-tcp-nodelay no
    slave-priority 100
    requirepass jason_zhang
    lazyfree-lazy-eviction no
    lazyfree-lazy-expire no
    lazyfree-lazy-server-del no
    slave-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 no
    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
    maxmemory 2048mb
    maxmemory-policy allkeys-lfu
    maxmemory-samples 5
    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
    activerehashing yes
    client-output-buffer-limit normal 0 0 0
    client-output-buffer-limit slave 256mb 64mb 60
    client-output-buffer-limit pubsub 32mb 8mb 60
    hz 10
    aof-rewrite-incremental-fsync yes

     
    redis-slave配置文件
    [root@jason opt]# cat /opt/redis/redis.conf|grep -Ev '^$|^#'
    bind 127.0.0.1
    protected-mode yes
    port 6379
    tcp-backlog 511
    timeout 0
    tcp-keepalive 300
    daemonize yes
    supervised no
    pidfile /var/run/redis_6379.pid
    loglevel notice
    logfile "/usr/local/log/redis-6379.log"
    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 ./
    slaveof 192.168.199.223  6379
    masterauth  jason_zhang
    slave-serve-stale-data yes
    slave-read-only yes
    repl-diskless-sync no
    repl-diskless-sync-delay 5
    repl-disable-tcp-nodelay no
    slave-priority 100
    requirepass  jason_zhang
    lazyfree-lazy-eviction no
    lazyfree-lazy-expire no
    lazyfree-lazy-server-del no
    slave-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 no
    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
    activerehashing yes
    client-output-buffer-limit normal 0 0 0
    client-output-buffer-limit slave 256mb 64mb 60
    client-output-buffer-limit pubsub 32mb 8mb 60
    hz 10
    aof-rewrite-incremental-fsync yes

    启动master和slave的redis服务(如果不能同步请重启redis服务或者重启主机)

    cd /usr/local/bin
    ./redis-server  /opt/redis/redis.conf

    master

    添加两个键值jason 、monday 键值为jason_test    monday_test

    语法  set jason   jason_test

     

    命令 INFO 查看redis信息

    redis-slave

    连上redis

     测试写入

    测试删除

     配置启动脚本

    vim redis

    #!/bin/bash
    #chkconfig: 2345 80 90
    # Simple Redis init.d script conceived to work on Linux systems
    # as it does use of the /proc filesystem.
    
    PATH=/usr/local/bin:/sbin:/usr/bin:/bin
    REDISPORT=6379
    EXEC=/usr/local/bin/redis-server
    REDIS_CLI=/usr/local/bin/redis-cli
       
    PIDFILE=/var/run/redis.pid
    CONF="/opt/redis/redis.conf"
       
    case "$1" in
        start)
            if [ -f $PIDFILE ]
            then
                    echo "$PIDFILE exists, process is already running or crashed"
            else
                    echo "Starting Redis server..."
                    $EXEC $CONF
            fi
            if [ "$?"="0" ] 
            then
                  echo "Redis is running..."
            fi
            ;;
        stop)
            if [ ! -f $PIDFILE ]
            then
                    echo "$PIDFILE does not exist, process is not running"
            else
                    PID=$(cat $PIDFILE)
                    echo "Stopping ..."
                    $REDIS_CLI -p $REDISPORT SHUTDOWN
                    while [ -x ${PIDFILE} ]
                   do
                        echo "Waiting for Redis to shutdown ..."
                        sleep 1
                    done
                    echo "Redis stopped"
            fi
            ;;
       restart|force-reload)
            ${0} stop
            ${0} start
            ;;
      *)
        echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
            exit 1
    esac
    # 复制脚本文件到init.d目录下
    cp redis /etc/init.d/
    
    # 给脚本增加运行权限
    chmod +x /etc/init.d/redis
    
    # 添加服务
    chkconfig --add redis
    
    # 配置启动级别
    chkconfig --level 2345 redis on

     重启redis,kill掉进程,重新启动

    或者连上客户端之后,执行shutdown命令,再启动服务

    设置最大内存

    CONFIG SET maxmemory 100MB
    CONFIG GET maxmemory

    配置文件中将bind配置为0.0.0.0进行监听

    0.0.0.0在服务器的环境中,指的就是服务器上所有的ipv4地址,如果机器上有2个ip 192.168.30.10 和 10.0.2.15,redis在配置中,如果配置监听在0.0.0.0这个地址上,那么,通过这2个ip地址都是能够到达这个redis服务的。同时呢,访问本地的127.0.0.1也是能够访问到redis服务的。

    参考:http://happyqing.iteye.com/blog/2348255

               https://www.cnblogs.com/stulzq/p/9288401.html

        https://www.ilanni.com/?p=11838#%E4%B8%80%E3%80%81redis%E6%BA%90%E7%A0%81%E5%AE%89%E8%A3%85

    查看版本

    redis-server -v

    使用yum直接安装最新版的redis

    yum install -y http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
    yum --enablerepo=remi install redis -y
    systemctl start redis
    
    
  • 相关阅读:
    [LintCode] Maximum Subarray Difference
    [HDU 3415] Max Sum of Max-K-sub-sequence
    [LintCode] Count of Smaller Number before itself
    [LeetCode] Invert Binary Tree
    [LintCode] Max Tree
    [LeetCode] Implement Stack using Queues
    [LintCode] Maximum Subarray III
    [LeetCode] Basic Calculator & Basic Calculator II
    [LeetCode] Rectangle Area
    Tensorflow[目录结构]
  • 原文地址:https://www.cnblogs.com/xiaoyou2018/p/9597964.html
Copyright © 2011-2022 走看看