Centos7 redis 5.0 服务设置、启动、停止、开机启动 我会带着你远行 2021-12-15 12:07 610阅读 0赞 redis 没有配置服务,没有开启动,每次都要手工配置。 解决这个麻烦,我们new一个服务,然后开机启动即可。 **1、创建服务(redis.conf 配置文件要注意,经过cp产生了很多个redis.conf)** vi /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 (这里注意下) ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target * \[Install\] * WantedBy=multi-user.target * \[Unit\] 表示这是基础信息 * Description 是描述 * After 是在那个服务后面启动,一般是网络服务启动后启动 * \[Service\] 表示这里是服务信息 ExecStart 是启动服务的命令 * ExecStop 是停止服务的指令 * \[Install\] 表示这是是安装相关信息 WantedBy 是以哪种方式启动: * multi-user.target表明当系统以多用户方式(默认的运行级别)启动时,这个服务需要被自动运行。 更详细的service文件说明请访问:这里 **2、 创建软链接(这一步我没有操作,redis分为redis-server和redis-clil,我觉得蛮方便的,有兴趣的朋友可以试试)** 创建软链接是为了下一步系统初始化时自动启动服务 ln -s /lib/systemd/system/redis.service /etc/systemd/system/multi-user.target.wants/redis.service 创建软链接就好比Windows下的快捷方式 ln -s 是创建软链接 ln -s 原文件 目标文件(快捷方式的决定地址) 如果创建软连接的时候出现异常,不要担心,看看/etc/systemd/system/multi-user.target.wants/ 目录是否正常创建软链接为准,有时候报错只是提示一下,其实成功了。 $ ll /etc/systemd/system/multi-user.target.wants/ total 8 drwxr-xr-x 2 root root 4096 Mar 30 15:46 ./ drwxr-xr-x 13 root root 4096 Mar 13 14:18 ../ lrwxrwxrwx 1 root root 31 Nov 23 14:43 redis.service -> /lib/systemd/system/redis.service ...略... **3、刷新配置** 刚刚配置的服务需要让systemctl能识别,就必须刷新配置 systemctl daemon-reload **4、启动、重启、停止** 启动redis systemctl start redis systemctl restart redis systemctl stop redis **5、开机自启动** redis服务加入开机启动 systemctl enable redis 禁止开机启动 systemctl disable redis **6、查看状态** systemctl status redis 参考:https://blog.csdn.net/chwshuang/article/details/68489968 修改了点路径,其余未变,仅供参考。 转载于:https://www.cnblogs.com/SunnyZhu/p/9835082.html
还没有评论,来说两句吧...