redis 安装脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis 安装脚本相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env bash
set -e
set -x
REDISVERSION=4.0.1
WORKSPACE=/tmp
if [ $# -eq 1 ]; then
echo ‘Redis version unspecified, use default: 4.0.1‘
REDISVERSION=$1
fi
apt-get update
apt-get install -y tcl build-essential

#add redis user
groupadd redis
useradd redis -g redis -s /usr/sbin/nologin

#workspace
mkdir -p /etc/redis /data/redis /var/log/redis

#install
wget http://download.redis.io/releases/redis-$REDISVERSION.tar.gz -O $WORKSPACE/redis-$REDISVERSION.tar.gz
tar xf $WORKSPACE/redis-$REDISVERSION.tar.gz -C $WORKSPACE
cd $WORKSPACE/redis-$REDISVERSION && make && make test && make install
cp $WORKSPACE/redis-$REDISVERSION/*.conf /etc/redis

#configuration
sed -i ‘s/127.0.0.1/0.0.0.0/g‘ /etc/redis/redis.conf
sed -i ‘/^logfile/c logfile "/var/log/redis/redis.log"‘ /etc/redis/redis.conf
sed -i ‘/^dir .\//c dir \/data\/redis\/‘ /etc/redis/redis.conf

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

[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli -p 6379 shutdown

[Install]
WantedBy=multi-user.target
EOF

#startup
chown -R redis.redis /etc/redis /data/redis /var/log/redis
systemctl daemon-reload
systemctl enable redis
systemctl start redis

以上是关于redis 安装脚本的主要内容,如果未能解决你的问题,请参考以下文章

shell脚本一键在线安装redis数据库(使用函数实现)

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

Shell脚本——一键安装Redis

Shell脚本——一键安装Redis

安装Redis 任意版本shell 脚本

redis自动化安装脚本