安装redis
cd /opt
useradd redis
mkdir -pv /data/apps/redis/{conf,logs,data}
wget http://download.redis.io/releases/redis-5.0.0.tar.gz
tar -xf redis-5.0.0.tar.gz
cd redis-5.0.0
make install PREFIX=/data/apps/redis
cp redis.conf /data/apps/redis/conf/
chown -R redis.redis /data/apps/redis
cd /data/apps/redis
sed -i 's/appendonly no/appendonly yes/' conf/redis.conf
sed -i '/^dir/d' conf/redis.conf
echo "dir /data/apps/redis/data" >> conf/redis.conf
echo "requirepass `< /dev/urandom tr -cd _A-Z-a-z-0-9@#^ | head -c ${1:-20}; echo`" >> conf/redis.conf
sed -i 's#logfile ""#logfile "/data/apps/redis/logs/redis.log"#g' conf/redis.conf
sed -i 's/bind 127.0.0.1/bind 0.0.0.0/' conf/redis.conf
sed -i 's/protected-mode yes/protected-mode no/' conf/redis.conf
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=/data/apps/redis/bin/redis-server /data/apps/redis/conf/redis.conf
ExecStop=/data/apps/redis/bin/redis-cli shutdown
Restart=always
#ReadWriteDirectories=/data/apps/redis/data
[Install]
WantedBy=multi-user.target
EOF