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



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM