下载 redis源码包
解压
编译
make
make PREFIX=/usr/local/redis install
修改工作区属主
chown -R redis:redis /usr/local/redis
复制编辑配置文件
cp redis.conf /etc/redis.conf
添加系统用户
useradd -r --shell=/sbin/nologin --home-dir=/usr/local/redis redis
编辑服务配置
[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=/usr/local/redis/bin/redis-server /etc/redis.conf --supervised systemd
ExecStop=/usr/libexec/redis-shutdown
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
停止脚本/usr/libexec/redis-shutdown
!/bin/bash
Wrapper to close properly redis and sentinel
test x"$REDIS_DEBUG" != x && set -x
REDIS_CLI=/usr/local/redis/bin/redis-cli
Retrieve service name
SERVICE_NAME="SERVICE_NAME" ]; then
SERVICE_NAME=redis
fi
Get the proper config file based on service name
CONFIG_FILE="/etc/$SERVICE_NAME.conf"
Use awk to retrieve host, port from config file
HOST=awk '/^[[:blank:]]*bind/ { print $2 }' $CONFIG_FILE | tail -n1
PORT=awk '/^[[:blank:]]*port/ { print $2 }' $CONFIG_FILE | tail -n1
PASS=awk '/^[[:blank:]]*requirepass/ { print $2 }' $CONFIG_FILE | tail -n1
SOCK=awk '/^[[:blank:]]*unixsocket\s/ { print $2 }' $CONFIG_FILE | tail -n1
Just in case, use default host, port
HOST=SERVICE_NAME" = redis ]; then
PORT={PORT:-26739}
fi
Setup additional parameters
e.g password-protected redis instances
[ -z "PASS"
shutdown the service properly
if [ -e "REDIS_CLI -s
ADDITIONAL_PARAMS shutdown
else
HOST -p
ADDITIONAL_PARAMS shutdown
fi