脚本一键安装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

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

    时间: 2024-11-13 03:47:27

    脚本一键安装redis实现主从复制的相关文章

    shell脚本一键安装redis集群

    简介: 明天再写,上脚本 #!/bin/bash #------------------------------------------------------------------------------------------------------------------# #| Some people die at the age of 25 and don't bury themselves in the earth until they are 75 |# #-----------

    Centos 6.4上面用Shell脚本一键安装mysql 5.6.15

    Centos 6.4上面用Shell脚本一键安装mysql 5.6.15  #!/bin/bash if [ `uname -m` == "x86_64" ];then machine=x86_64 else machine=i686 fi mysqlBasedir=/storage/server/mysql mysqlDatadir=${mysqlBasedir}/data/ mysqlLogdir=/storage/log/mysql mysqlUser=mysql mysqlGr

    Shell脚本一键安装LNMP环境

    https://sourceforge.net/projects/opensourcefile/files/ Nginx是一款高性能的HTTP和反向代理服务器.Nginx在反向代理,Rewrite规则,稳定性,静态文件处理,内存消耗等方面表现了很强的优势.因此公司线上和测试环境的WEB服务大多数采用的是LNMP环境,经常要进行LNMP环境的搭建,下面是用SHELL脚本写的一键安装LNMP环境的脚本.1)系统环境介绍Centos 5.8 64位 (已测试)Nginx: nginx-1.4.1.ta

    用批处理脚本一键安装 MongoDB

    下载MongoDB安装文件,解压到D:\MongoDB: 运行脚本: @echo off set mongobin=D:\MongoDB ::在mongodb文件夹下建立data,log文件夹 md %mongobin%\data md %mongobin%\log cd %mongobin%\bin mongod --repair --dbpath "%mongobin%\data\db" mongod --install --serviceName "MongoDBMas

    shell脚本一键安装MySQL5.5

    执行脚本之前必须下载MySQL5.5二进制压缩安装包.我是事先下载好了的.下边执行shell脚本. #!/bin/bash #auth:taoyake /bin/mkdir -p /taokey/tools cd /taokey/tools/ tar -zxf mysql-5.5.32-linux2.6-x86_64.tar.gz  sleep 3 cp -R mysql-5.5.32-linux2.6-x86_64 /usr/local/mysql sleep 3 cd /usr/local/

    使用shell脚本一键安装zabbix并配置客户端的自动发现选项

    1.缘由: 我自己的ESXi服务器上上最近新加了好多虚拟主机,但我现在还不会安装,使用,那种批量运维工具(saltstack,ansible,puppet等).虽然还有一种方法:就是通过shell工具一次打开若干个窗口,然后在编辑框中输一行行的输入命令,点击全部窗口执行.可是我的老笔记本已经撑不住这么开这么多窗口了,. 2.然后 开始写zabbix_agent安装脚本,通过手工上传到各个虚拟机中执行,这里推荐大家在初始化Linux的时候,别忘记安装lrzsz,rz和sz可以拖动上传文件到Linu

    Nginx脚本一键安装第二版

    #!/bin/bash #判断是否是roo用户 if [ $(id -u) != "0" ]; then         echo "Error:You must be root to run this script" fi #每次使用只需修改自定义内容即可 #自定义用户名和组 Group_Name="nginx" User_Name="nginx" #自定义nginx变量 Install_Path="/usr/lo

    linux下一键安装redis并设置为后台进程及开机启动

    1.下载适合你的版本的redis(下载页面https://redis.io/download),我下载的是4.0.6版本 wget http://download.redis.io/releases/redis-4.0.6.tar.gz 2.解压 tar zxvf redis-4.0.6.tar.gz 3.编译 cd redis-4.0.6/ make make install 4.安装并启动 cd utils ./install_server.sh * 第4步安装时会有几项提示一路按回车即可.

    【高效率】shell脚本一键安装Tomcat服务

    脚本环境 1.linux centos 7或redhat 62.光盘镜像文件已挂载3.系统在可连接外网的环境中4.先下载jdk和tomcat软件包百度云链接提取码:89be 实验步骤 1.上传软件包到Linux系统中2.编写脚本vim tomcat.sh #!/bin/bash#this is tomcat shell #先关闭防火墙,增强性systemctl stop firewalldsetenforce 0num1=`env | grep USER | grep root | wc -l