本文介绍了在linux系统中,设置redis开机自启动的配置步骤,设置开机自启动的方式使用的是systemctl,详细介绍如下:
# /usr/lib/systemd/system/下新建redis.service文件
cd /usr/lib/systemd/system
touch redis.service
# 在redis.service中写入如下内容:
[Unit]
Description=Redis persistent key-value database
After=network.target
[Service]
User=prouser
Group=rd
Type=forking
ExecStart=/opt/app/redis/bin/redis-server /opt/app/redis/bin/redis.conf
ExecStop=/opt/app/redis/bin/redis-cli shutdown
Restart=on-failure
PrivateTmp=true
[Install]
WantedBy=multi-user.target
# 写入内容结束
systemctl daemon-reload # 重载配置
systemctl enable redis # 设置开机自启动
systemctl disable redis # 取消开机自启动
systemctl start redis # 开启
systemctl stop redis # 关闭