cat > /usr/lib/systemd/system/redis.service << EOF
[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /etc/redis.conf --supervised systemd
ExecStop=/usr/local/redis/bin/redis-cli -a 密码 -p 6379 shutdown
#需要先创建用户
#User=redis
#Group=redis
#RuntimeDirectory=redis
#RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
#=======================
cat > /usr/lib/systemd/system/sentinel.service << EOF
[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-sentinel /etc/sentinel.conf
ExecStop=/usr/local/redis/bin/redis-cli -h 127.0.0.1 -p 26379 shutdown
#需要先创建用户
#User=redis
#Group=redis
#RuntimeDirectory=redis
#RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload