centos服务器重启后启动redis服务
一、 未配置 系统 Unit 手动重启

1、查看redis配置文件路径
在这里插入图片描述
2、找到 redis-server 启动文件
在这里插入图片描述
3、 服务启动

 ./redis-server ../etc/redis.conf

4、查看服务状态

在这里插入图片描述

二、 配置 redis service 启动服务

1、创建服务(redis.conf 配置)

vim /lib/systemd/system/redis.service

[Unit]
Description=Redis
After=network.target

[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf (配置自己redis 配置文件路径)
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
Alias=redis.service
[Install]
WantedBy=multi-user.target
[Unit] 表示这是基础信息
Description 是描述
After 是在那个服务后面启动,一般是网络服务启动后启动
[Service] 表示这里是服务信息 ExecStart 是启动服务的命令
ExecStop 是停止服务的指令
[Install] 表示这是是安装相关信息 WantedBy 是以哪种方式启动:
multi-user.target表明当系统以多用户方式(默认的运行级别)启动时,这个服务需要被自动运行

2、刷新配置
刚刚配置的服务需要让systemctl能识别,就必须刷新配置
systemctl daemon-reload

3、redis 启动、重启、停止

启动redis
systemctl start redis
systemctl restart redis
systemctl stop redis
systemctl status redis # 查看 redis 状态

4、开机自启动

redis服务加入开机启动
systemctl enable redis
禁止开机启动
systemctl disable redis

参考:https://blog.csdn.net/chwshuang/article/details/68489968

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐