Linux如何让Redis-server在后台运行

时间:2021-12-29 01:19:25
文档课题:Linux如何让Redis-server在后台运行.
系统:rhel 7.9
数据库:redis 6.2.6
1、问题描述
redis安装后运行reids-server命令,内容显示如下.此时在该session中无法执行其它操作,当执行ctrl+c关闭界面后才能输入其它命令,但此时redis进程也会被关闭. 
[root@leo-redis626-a redis-6.2.6]# redis-server
56317:C 02 Apr 2023 23:13:12.679 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
56317:C 02 Apr 2023 23:13:12.679 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=56317, just started
56317:C 02 Apr 2023 23:13:12.679 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
56317:M 02 Apr 2023 23:13:12.681 * Increased maximum number of open files to 10032 (it was originally set to 1024).
56317:M 02 Apr 2023 23:13:12.681 * monotonic clock: POSIX clock_gettime
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 6.2.6 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                  
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 56317
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           https://redis.io       
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

56317:M 02 Apr 2023 23:13:12.682 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
56317:M 02 Apr 2023 23:13:12.682 # Server initialized
56317:M 02 Apr 2023 23:13:12.682 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
56317:M 02 Apr 2023 23:13:12.682 * Ready to accept connections
2、后台运行redis
如何在后台运行redis?本次测试是新建的配置文件,可在该文件中添加daemonize yes,如此以守护进程的方式启动redis.
[root@leo-redis626-a redis-6.2.6]# vi redis6379.conf 
include /usr/local/src/redis-6.2.6/redis.conf
pidfile /var/run/redis_6379.pid
port 6379
dbfilename dump6379.rdb
daemonize yes
说明:“daemonize yes”为新增内容.
3、结果验证
--如下所示,此时启动redis,不再弹出一堆显示,同时可以在当前session进行其它操作.
[root@leo-redis626-a redis-6.2.6]# redis-server redis6379.conf
[root@leo-redis626-a redis-6.2.6]# ps -ef|grep redis
avahi       831      1  0 08:25 ?        00:00:00 avahi-daemon: running [leo-redis626-a.local]
root       2790      1  1 08:46 ?        00:00:00 redis-server 127.0.0.1:6379
root       2802   2308  0 08:46 pts/0    00:00:00 grep --color=auto redis

参考网址:https://jingyan.baidu.com/article/fc07f98931aa4953fee51948.html