Redis安装

说明:使用以下脚本,将redis安装包放在同级目录下即可开始安装

xxx.sh install  #  安装redis
xxx.sh unintall  # 卸载redis

安装包获取:链接:https://pan.baidu.com/s/1r-cl1bmI9QZhiEql5NlQtQ?pwd=qi5i
redis安装包及脚本

给脚本授权
chmod +x xxx.sh

执行脚本,开始安装 xxx.sh install

#!/bin/bash
# description 安装redis至/home/目录下

install_redis() {
    
    mkdir -p /home/redis/logs

    #  根据需要修改解压路径
    tar -zxf ./redis-stack-server-6.2.2-v4.rhel7.x86_64.tar.gz -C /home/
    echo "export PATH=/home/redis/bin:$PATH" >>/etc/profile
    mv /home/redis-stack-server-6.2.2-v4/* /home/redis/
    rm -rf /home/redis-stack-server-6.2.2-v4
    source /etc/profile

    cat >/home/redis/etc/redis-stack.conf <<EOF
protected-mode no
requirepass Lz!2023@aD
logfile "/home/redis/logs/redis.log"
appendonly yes
port 16379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /home/redis/redis_6379.pid
loglevel notice
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
rdb-del-sync-files no
dir /home/redis/
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
oom-score-adj no
oom-score-adj-values 0 200 800
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
jemalloc-bg-thread yes

EOF

    # 启动redis

    # /home/redis/bin/redis-server /etc/redis/etc/redis-stack.conf

    cat >/etc/systemd/system/redis.service <<EOF
[Unit]
Description=RedisService


[Service]
ExecStart=/home/redis/bin/redis-server /home/redis/etc/redis-stack.conf --daemonize no --supervised systemd
Restart=on-failure
RestartSec=15

[Install]
WantedBy=multi-user.target

EOF

    systemctl daemon-reload

    systemctl start redis
    systemctl enable redis
    

}

uninstall_redis() {

    systemctl stop redis
     rm  -rf /home/redis
}

redis_param=$1
case $redis_param in
install | INSTALL)

    install_redis

    ;;
uninstall | UNINSTALL)
    uninstall_redis
    ;;
*)
    echo "usage: redis_install.sh install|INSTALL|unistall|UNINSTALL."
    ;;

esac
posted @ 2023-09-14 17:58  梁永旺  阅读(0)  评论(0编辑  收藏  举报