Redis

為什麼 systemctl 不能在 CentOS 7 上啟動 redis-server?

  • October 13, 2020

我在一個新的 CentOS 7 機器上安裝了 redis,但無法使用 systemctl 啟動它。

它是這樣安裝的:

rpm -i http://dl.fedoraproject.org/pub/epel/beta/7/x86_64/epel-release-7-0.2.noarch.rpm
yum install redis

嘗試像這樣啟動它似乎默默地失敗了(沒有輸出):

systemctl start redis-server # also tried redis-server.service

以下是嘗試連接時發生的情況:

redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>

但是手動啟動它可以工作:

[root@redis ~]# redis-server /etc/redis.conf
[root@redis ~]# redis-cli
127.0.0.1:6379>

任何人都知道出了什麼問題,或者如何調試它?

更新:輸出/var/log/redis/redis.log如下。順便說一句,這是一個 512mb RAM VPS。

[1972] 29 Jul 18:52:16.258 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
[1972] 29 Jul 18:52:16.258 # Redis can't set maximum open files to 10032 because of OS error: Operation not permitted.
[1972] 29 Jul 18:52:16.258 # Current maximum open files is 1024. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
               _._
          _.-``__ ''-._
     _.-``    `.  `_.  ''-._           Redis 2.8.13 (00000000/0) 64 bit
 .-`` .-```.  ```\/    _.,_ ''-._
(    '      ,       .-`  | `,    )     Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
|    `-._   `._    /     _.-'    |     PID: 1972
 `-._    `-._  `-./  _.-'    _.-'
|`-._`-._    `-.__.-'    _.-'_.-'|
|    `-._`-._        _.-'_.-'    |           http://redis.io
 `-._    `-._`-.__.-'_.-'    _.-'
|`-._`-._    `-.__.-'    _.-'_.-'|
|    `-._`-._        _.-'_.-'    |
 `-._    `-._`-.__.-'_.-'    _.-'
     `-._    `-.__.-'    _.-'
         `-._        _.-'
             `-.__.-'

[1972] 29 Jul 18:52:16.259 # Server started, Redis version 2.8.13
[1972] 29 Jul 18:52:16.259 # 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.
[1972] 29 Jul 18:52:16.260 * DB loaded from disk: 0.001 seconds
[1972] 29 Jul 18:52:16.260 * The server is now ready to accept connections on port 6379
[1972] 29 Jul 18:52:16.265 # User requested shutdown...
[1972] 29 Jul 18:52:16.265 * Saving the final RDB snapshot before exiting.
[1972] 29 Jul 18:52:16.267 * DB saved on disk
[1972] 29 Jul 18:52:16.267 * Removing the pid file.
[1972] 29 Jul 18:52:16.267 # Redis is now ready to exit, bye bye...

和狀態:

[root@redis ~]# systemctl status redis-server
redis-server.service - Redis persistent key-value database
  Loaded: loaded (/usr/lib/systemd/system/redis-server.service; disabled)
  Active: inactive (dead)

Jul 29 18:52:16 redis systemd[1]: Starting Redis persistent key-value database...
Jul 29 18:52:16 redis systemd[1]: Started Redis persistent key-value database.

最後,修好了。Systemd 要求 redis 執行非守護程序,因此需要更改配置:

# /etc/redis.conf
daemonize yes # << comment this out

只是為了添加到接受的答案,我最近更新redis並遇到了同樣的問題。配置文件/etc/redis.conf已經有了這條線daemonize no,我仍然有這個問題。

redis我通過告訴與主管互動來修復它systemd

# /etc/redis.conf
supervised auto # or systemd

作為參考,我使用的系統執行的是 Arch Linux。

引用自:https://serverfault.com/questions/616430