码迷,mamicode.com
首页 > 其他好文 > 详细

脚本一键安装redis实现主从复制

时间:2018-04-16 14:33:10      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:redis自动化安装脚本

  • 安装脚本及配置文件上传至家目录即可,sh执行脚本即可选择主从
    #!/bin/bash
    #Description:atuo install redis
    #Date:2018.4.11
  • Download_redis=http://download.redis.io/releases/redis-3.2.1.tar.gz
    dir1=/opt
    redis=redis-3.2.1
    redis_conf1=/usr/local/redis-6379/redis.conf
    redis_conf2=/usr/local/redis-6380/redis.conf
    FILE1=$HOME/6379.conf
    FILE2=$HOME/6380.conf
    dir2=/server/scripts/redis
    count=ps -ef|grep redis|grep -v grep| wc -l

    install_yum () {
    echo -e "\033[41;37m <===开始安装redis依赖 软件,请稍等...===> \033[0m"
    sleep 2
    yum install -y gcc wget
    }

    install_dir () {
    cd $dir1
    wget -q $Download_redis
    echo -e "\033[41;37m <===redis下载中,请稍后...===> \033[0m"
    tar xf redis-3.2.1.tar.gz -C /usr/local
    cd /usr/local/$redis
    make
    make PREFIX=${redis_setup_dir} install
    if [ echo $? -eq 0 ];then
    echo -e "\e[1;32m redis安装成功. \e[0m"
    elif [ echo $? -ne 0 ];then
    echo -e "\e[1;31m redis安装失败,请检查环境. \e[0m"
    exit
    fi
    sleep 1
    }

    select_or () {
    echo "---------------------------------------------------------------
    select Master Slave
    1 Master
    2 Slave
    ----------------------------------------------------------------"

    read input
    
    case "$input" in 
         1)
          mv /usr/local/$redis /usr/local/redis-6379
          sleep 1
          cd /usr/local/redis-6379
          cp -f redis.conf redis.conf.bak
          cat "$HOME/6379.conf" >$redis_conf1
          /usr/local/redis-6379/src/redis-server /usr/local/redis-6379/redis.conf &
          sleep 3
          ;;
         2)
          mv /usr/local/$redis /usr/local/redis-6380
          sleep 1
          cd /usr/local/redis-6380
          cp -f redis.conf redis.conf.bak
          cat "$HOME/6380.conf" >$redis_conf2
          /usr/local/redis-6380/src/redis-server /usr/local/redi

    s-6380/redis.conf &
    sleep 3
    ;;
    *)
    echo "---------------------------------------------------------------
    select Master Slave
    1 Master
    2 Slave
    ----------------------------------------------------------------"
    esac
    }

    count_conf () {
    if [ $count -gt 1 ];then
    echo -e "\e[1;32m redis is running \e[0m"
    elif [ $count -le 1 ];then
    echo -e "\e[1;31m redis is not running \e[0m"
    fi
    }

    install_yum
    install_dir
    select_or
    count_conf


    2.主配置文件
    daemonize yes
    pidfile /usr/local/redis-6379/run/redis.pid
    bind 0.0.0.0
    port 6379
    timeout 300
    tcp-keepalive 0
    loglevel notice
    #logfile stdout
    databases 16
    unixsocketperm 0
    maxmemory 2000000000
    maxmemory-policy volatile-lru
    maxmemory-samples 3
    maxclients 10000
    #save 900 1
    #save 300 10
    #save 60 10000
    stop-writes-on-bgsave-error yes
    rdbcompression yes
    rdbchecksum yes
    dbfilename dump.rdb
    slave-serve-stale-data yes
    slave-read-only yes
    repl-ping-slave-period 10
    repl-timeout 60
    repl-disable-tcp-nodelay no
    slave-priority 100
    appendonly no
    appendfsync everysec
    no-appendfsync-on-rewrite no
    auto-aof-rewrite-percentage 100
    auto-aof-rewrite-min-size 64mb
    lua-time-limit 5000
    slowlog-log-slower-than 10000
    slowlog-max-len 1024
    hash-max-ziplist-entries 512
    hash-max-ziplist-value 64
    list-max-ziplist-entries 512
    list-max-ziplist-value 64
    set-max-intset-entries 512
    zset-max-ziplist-entries 128
    zset-max-ziplist-value 64
    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


    3.从配置文件
    daemonize yes
    pidfile /usr/local/redis-6380/run/redis.pid
    port 6380
    timeout 300
    tcp-keepalive 0
    loglevel notice
    #logfile stdout
    databases 16
    unixsocketperm 0
    maxmemory 2000000000
    maxmemory-policy volatile-lru
    maxmemory-samples 3
    maxclients 10000
    #save 900 1
    #save 300 10
    #save 60 10000
    stop-writes-on-bgsave-error yes
    rdbcompression yes
    rdbchecksum yes
    dbfilename dump.rdb
    slaveof 192.168.1.42 6379 (根据你实际的本地环境配置为主的ip 及端口)
    slave-serve-stale-data yes
    slave-read-only yes
    repl-ping-slave-period 10
    repl-timeout 60
    repl-disable-tcp-nodelay no
    slave-priority 100
    appendonly yes
    appendfsync everysec
    no-appendfsync-on-rewrite no
    auto-aof-rewrite-percentage 100
    auto-aof-rewrite-min-size 64mb
    lua-time-limit 5000
    slowlog-log-slower-than 10000
    slowlog-max-len 1024
    hash-max-ziplist-entries 512
    hash-max-ziplist-value 64
    list-max-ziplist-entries 512
    list-max-ziplist-value 64
    set-max-intset-entries 512
    zset-max-ziplist-entries 128
    zset-max-ziplist-value 64
    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

    脚本一键安装redis实现主从复制

    标签:redis自动化安装脚本

    原文地址:http://blog.51cto.com/11571922/2103928

    (0)
    (0)
       
    举报
    评论 一句话评论(0
    登录后才能评论!
    © 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
    迷上了代码!