<返回更多

Linux环境下通过shell脚本一键安装redis

2022-03-03    明日人生
加入收藏

编写shell脚本:

cat install_redis.sh

#!/bin/bash

redis_config=/usr/local/redis/bin/redis.conf

function gcc_install(){
    yum install gcc gcc-c++ man wget telnet perl-devel Python-devel net-tools -y
}

function install_redis () {
    cd /usr/local/src
	wget http://download.redis.io/releases/redis-6.2.6.tar.gz
	tar -zxf redis-6.2.6.tar.gz
    cd  redis-6.2.6 && make && make install PREFIX=/usr/local/redis
    mkdir -p /usr/local/redis/{bin,run,log,data}
    yes| cp -r /usr/local/src/redis-6.2.6/redis.conf /usr/local/redis/bin/
    yes| cp -r /usr/local/src/redis-6.2.6/redis-server /usr/local/redis/bin/
    sed -ri '/^daemonize/s/yes/no/' $redis_config
    sed -ri '/^bind/s/127.0.0.1/0.0.0.0' $redis_config
    sed -ri '/^dir/s/.///usr//local/redis/data/' $redis_config
    sed -ri '/^protected-mode/s/yes/no/' $redis_config
    sed -ri '/^logfile/s/""/"/usr//local/redis/log/redis.log"/' $redis_config
}


cat > /usr/lib/systemd/system/redis.service << EOF
[Unit]
After=network.target 

[Service]
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf --supervised systemd
ExecStop=/bin/kill -s QUIT $MAINPID
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl start redis.service

gcc_install
redis_install

如果您喜欢本文,就请动动您的发财手为本文点赞评论转发,让我们一起学习更多运维相关知识,最后请记得关注我。

声明:本站部分内容来自互联网,如有版权侵犯或其他问题请与我们联系,我们将立即删除或处理。
▍相关推荐
更多资讯 >>>