zoukankan      html  css  js  c++  java
  • 安装redis

    #!/bin/bash

    read -e -p 'input the version you want(like 5.0.5):' version
    # version
    VERSION=redis-${version:-5.0.5}

    PASSWORD=`< /dev/urandom tr -cd _A-Z-a-z-0-9@#^ | head -c ${1:-24}; echo`

    # download path
    LOAD_PATH=/tmp
    # install path
    INSTALL_PATH=/data/apps/redis
    if [ ! -d ${INSTALL_PATH} ];then
    mkdir -pv $INSTALL_PATH
    fi
    cd /tmp
    # download source packagei
    wget http://download.redis.io/releases/$VERSION.tar.gz
    # decompression
    tar -xf $VERSION.tar.gz
    # compile and install
    cd $VERSION
    make
    if [ $? -ne 0 ];then
    make MALLOC=libc
    fi
    make install PREFIX=$INSTALL_PATH

    if [ $? -ne 0 ];then
    echo "redis 安装失败。。。"
    exit 1
    fi
    cd $INSTALL_PATH
    mkdir conf logs data
    cp -rf /tmp/$VERSION/redis.conf $INSTALL_PATH/conf/
    sed -i '/dir ./d' conf/redis.conf
    sed -i '/logfile ""/d' conf/redis.conf
    echo "dir $INSTALL_PATH/data" >> conf/redis.conf
    echo "logfile $INSTALL_PATH/logs/access.log" >> conf/redis.conf
    sed -i "s/# requirepass foobared/requirepass $PASSWORD/" conf/redis.conf
    sed -i 's/appendonly no/appendonly yes/' conf/redis.conf
    #sed -i 's/protected-mode no/protected-mode yes/' conf/redis.conf
    sed -i "s/bind 127.0.0.1/bind 0.0.0.0/" conf/redis.conf
    #sed -i 's/daemonize no/daemonize yes/' conf/redis.conf
    useradd redis
    chown -R redis.redis $INSTALL_PATH

    cat <<EOF >> /usr/lib/systemd/system/redis.service
    [Unit]
    Description=Redis Server Manager
    After=syslog.target
    After=network.target

    [Service]
    Type=simple
    User=redis
    Group=redis
    PIDFile=/var/run/redis_6379.pid
    ExecStart=$INSTALL_PATH/bin/redis-server $INSTALL_PATH/conf/redis.conf
    ExecStop=$INSTALL_PATH/bin/redis-cli shutdown
    Restart=always
    #ReadWriteDirectories=$INSTALL_PATH/data
    [Install]
    WantedBy=multi-user.target
    EOF

    systemctl daemon-reload
    systemctl start redis
    systemctl enable redis

    echo "$VERSION 安装成功!密码是: $PASSWORD "

    # 配置主从同步

     dir   /data/apps/redis/data
     protectd-mode no
     appendonly yes
     bind  0.0.0.0
     daemonize no
    
     slaveof $MASTER_IP $MASTER_PORT
     slave-read-only no
    
     masterauth $MASTER_PWD
     requirepass $SLAVE_PWD
  • 相关阅读:
    tomcat启动Publishing failed with multiple errors
    oracle中merge into用法解析
    ORACLE数据库导出表,字段名,长度,类型,字段注释,表注释语句
    orcale的to_number方法
    Git删除无效远程分支
    .net core文件系统简介
    PowerShell的一些资料整理
    Jetbrains推出了一款新的编程字体Mono
    .net core程序强制以管理员权限启动
    在Asp.net Razor Pages/MVC程序中集成Blazor
  • 原文地址:https://www.cnblogs.com/ray-mmss/p/11154914.html
Copyright © 2011-2022 走看看