Redis使用守护进程启动sentinel并指定其日志目录

正常Redis-server可以通过配置文件来指定守护进程启动以及指定日志路径,但sentinel就不一样了。
正常启动redis的sentinel时,进程会直接在前台跑,一退出sentinel进程就关了:

[root@redis_01 redis]# redis-server /etc/redis/sentinel.conf --sentinel
7980:X 23 Nov 18:02:41.348 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.0.5 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in sentinel mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 26379
 |    `-._   `._    /     _.-'    |     PID: 7980
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

7980:X 23 Nov 18:02:41.355 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
7980:X 23 Nov 18:02:41.355 # Sentinel runid is 43de323d55627d896b2caf1da2e305f0eb59dcee
7980:X 23 Nov 18:02:41.356 # +monitor master mymaster 127.0.0.1 6379 quorum 1
^C7980:signal-handler (1448273325) Received SIGINT scheduling shutdown...
7980:X 23 Nov 18:08:45.618 # User requested shutdown...
7980:X 23 Nov 18:08:45.618 # Sentinel is now ready to exit, bye bye...
[root@redis_01 redis]# ll

第一种方法:
使用nohub来启动sentinel,使得进程在后台启动以及在指定目录记录日志信息:
[root@redis_01 redis]# nohup /usr/local/redis/bin/redis-sentinel /etc/redis/sentinel.conf  >> /var/log/redis_sentinel.log 2>&1 &
[1] 8002
[root@redis_01 redis]# netstat -tunpl|grep sentinel
tcp        0      0 0.0.0.0:26379               0.0.0.0:*                   LISTEN      8002/redis-sentinel 
tcp        0      0 :::26379                    :::*                        LISTEN      8002/redis-sentinel 
[root@redis_01 redis]# tail -f /var/log/redis_sentinel.log 
8002:X 23 Nov 18:25:52.043 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
8002:X 23 Nov 18:25:52.043 # Sentinel runid is 7f1d63c2aede6ac97242aeaaba26d10778e28f0a
8002:X 23 Nov 18:25:52.043 # +monitor master mymaster 127.0.0.1 6379 quorum 1
这样就可以实现后台其他以及日志记录了。

第二种方法:
在sentinel的配置文件中添加以下内容:
[root@redis_01 redis]# vim sentinel.conf 
daemonize yes
logfile "/var/log/sentinel_log.log"
启动,查看日志:
[root@redis_01 redis]# redis-server /etc/redis/sentinel.conf --sentinel
[root@redis_01 redis]# cat /var/log/sentinel_log.log 
11109:X 26 Nov 11:22:04.376 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.0.5 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in sentinel mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 26379
 |    `-._   `._    /     _.-'    |     PID: 11109
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

11109:X 26 Nov 11:22:04.379 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
11109:X 26 Nov 11:22:04.379 # Sentinel runid is 0f82780194cd3822ab32397b01996e205b4195c9
11109:X 26 Nov 11:22:04.379 # +monitor master mymaster 127.0.0.1 6379 quorum 1
[root@redis_01 redis]# ll
[root@redis_01 redis]# ps -ef|grep sentinel
root     11109     1  0 11:22 ?        00:00:00 redis-server *:26379 [sentinel]                 
root     11115 11076  0 11:22 pts/0    00:00:00 grep sentinel
已正常启动。

本人使用第二种,所以也推荐第二种方法大笑

转载自:http://www.suohi.cc/posts/5652e9401f6d1303e9f04a4d

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值