很多小伙伴安装了redis发现,它并没有自己启动,然后需要运行redis-server才能启动,但是这样又不能挂在后台,我们希望的是让它一直保持运行,这样我们可以修改配置文件满足我们的需求
安装好redis,需要用redis-server运行,然后就出现如下画面
➜  ~ redis-server
40459:C 13 Dec 2019 18:53:42.465 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
40459:C 13 Dec 2019 18:53:42.466 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=40459, just started
40459:C 13 Dec 2019 18:53:42.466 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
40459:M 13 Dec 2019 18:53:42.467 * Increased maximum number of open files to 10032 (it was originally set to 256).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 5.0.5 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 40459
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'
40459:M 13 Dec 2019 18:53:42.471 # Server initialized
40459:M 13 Dec 2019 18:53:42.472 * DB loaded from disk: 0.001 seconds
40459:M 13 Dec 2019 18:53:42.472 * Ready to accept connections然后关掉terminal,redis也跟着退出了,如何以守护进程运行,让它时刻跑在后台呢?可以通过修改配置文件,然后运行时加上配置文件路径。
配置文件通常在 /etc/redis/redis.conf 我们修改这个文件
vim /etc/redis/redis.conf找到这个东西 daemonize 如果是 daemonize no 则改为 daemonize yes,然后保存退出,运行的时候使用如下命令:
redis-server /etc/redis/redis.conf如此即可让其运行在后台了,不会受关闭terminal连接影响。
viencoding.com版权所有,允许转载,但转载请注明出处和原文链接: http://45.76.225.121/article/254