美文网首页
redis.conf详解之pidfile

redis.conf详解之pidfile

作者: 小易哥学呀学 | 来源:发表于2021-12-18 22:25 被阅读0次

用法

pidfile /var/run/redis_6379.pid

 

注意事项:

如果pidfile文件创建失败,也不会影响redis启动。
配置了daemonizepidfile都会创建pidfile文件。
 

redis源码

当你配置了daemonize却没有配置pidfile时,pidfile的默认路径以及文件名

// https://github.com/redis/redis/blob/6.2.6/src/server.h
115 #define CONFIG_DEFAULT_PID_FILE "/var/run/redis.pid"

什么情况会创建pidfile:配置了daemonize 或 配置了pidfile

// https://github.com/redis/redis/blob/6.2.6/src/server.c
7996   int background = server.daemonize && !server.supervised;
8016   if (background || server.pidfile) createPidFile();

创建pidfile文件的源码。

// https://github.com/redis/redis/blob/6.2.6/src/server.c
7108 void createPidFile(void) {
7109     /* If pidfile requested, but no pidfile defined, use
7110      * default pidfile path */
7111     if (!server.pidfile) server.pidfile = zstrdup(CONFIG_DEFAULT_PID_FILE);
7112
7113     /* Try to write the pid file in a best-effort way. */
7114     FILE *fp = fopen(server.pidfile,"w");
7115     if (fp) {
7116         fprintf(fp,"%d\n",(int)getpid());
7117         fclose(fp);
7118     }
7119 }

什么情况会删除pidfile:配置了daemonize 或 配置了pidfile

// https://github.com/redis/redis/blob/6.2.6/src/server.c
5535 int prepareForShutdown(int flags) {
...忽略部分...
5623     /* Remove the pid file if possible and needed. */
5624     if (server.daemonize || server.pidfile) {
5625         serverLog(LL_NOTICE,"Removing the pid file.");
5626         unlink(server.pidfile);
5627     }

 

原生注释

# If a pid file is specified, Redis writes it where specified at startup
# and removes it at exit.
#
# When the server runs non daemonized, no pid file is created if none is
# specified in the configuration. When the server is daemonized, the pid file
# is used even if not specified, defaulting to "/usr/local/var/run/redis.pid".
#
# Creating a pid file is best effort: if Redis is not able to create it
# nothing bad happens, the server will start and run normally.
#
# Note that on modern Linux systems "/run/redis.pid" is more conforming
# and should be used instead.
#pidfile /var/run/redis_6379.pid

本文属于原创,首发于微信公众号【小易哥学呀学】,如需转载请后台留言。
加微信入交流群。vx:17610015120

相关文章

  • redis.conf详解之pidfile

    用法 注意事项: 如果pidfile文件创建失败,也不会影响redis启动。配置了daemonize或pidfil...

  • redis.conf详解之include

    1、用法: 在 $yourPath/redis.conf 文件中添加以下配置 2、用途: 模块化配置,比如所有服务...

  • redis.conf详解之module

    1、用法: 在 $yourPath/redis.conf 文件中添加以下配置 2、module制作: 准备工作 1...

  • redis.conf详解之timeout

    用法 单位是秒 用途 在timeout时间内如果没有数据交互,redis侧将关闭连接。没有数据交互:redis客户...

  • redis.conf详解之port

    用法 用途 指定redis监听的端口。 注意事项: 1.默认是63792.配置为0时将不监听任何端口(也就是服务没...

  • redis.conf详解之bind

    用法 绑定到本机的其中一个ip 绑定到本机的两个ip,如果10.0.0.1无效redis依旧可以启动。 绑定到本机...

  • redis.conf详解之daemonize

    用法 作为非守护进程运行 作为守护进程运行 注意事项: 默认情况下,Redis不作为守护进程运行。如果以守护进程运...

  • redis.conf详解之maxclients

    本文基于 redis_version:6.2.5 用法 设置一个redis实例支持的最大连接数。 注意事项: 默认...

  • Redis.conf 详解

    Redis.conf 详解 参考地址:https://www.cnblogs.com/zhang-ke/p/598...

  • Redis.conf详解

    Redis.conf详解 单位 对大小写不敏感 包含include /path/to/local.conf 网...

网友评论

      本文标题:redis.conf详解之pidfile

      本文链接:https://www.haomeiwen.com/subject/ezdefrtx.html