linux使用systemctl命令配置redis自启动

一、配置Redis

  redis解压完成后,配置redis目录下的redis.conf文件。bind和protected-mode两项属性作用可参考:关于主机连接虚拟机centOS中的redis;daemonize设置为yes后可后台运行。

bind 0.0.0.0
protected-mode no
daemonize yes

二、创建服务

  在/usr/lib/systemd/system下创建redisd.service文件,内容如下。/data/redis为redis安装目录路径。

[Unit]
Description=Redis
After=network.target

[Service]
Type=forking
ExecStart=/data/redis/bin/redis-server /data/redis/redis.conf
ExecReload=/data/redis/bin/redis-server -s reload
ExecStop=/data/redis/bin/redis-server -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

三、创建软链接与开机自启

  运行命令 systemctl enable redisd 即可自动创建软链接并添加开机自启。

四、相关命令

  启动redis服务

systemctl start redisd

  重启redis服务

systemctl restart redisd

  停止redis服务

systemctl stop redisd

  添加开机自启

systemctl enable redisd

  禁止开机自启

systemctl disable redisd

  查看状态

systemctl status redisd


posted @ 2021-08-18 11:11  星辰°  阅读(2028)  评论(0编辑  收藏  举报