• 周五. 5月 3rd, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

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

admin

11月 28, 2021

一、配置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


发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注