13

I've installed redis on a new CentOS 7 box but can't start it using systemctl.

It was installed like this:

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

Attempting to start it like this seemed to silently fail (there was no output):

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

Here's what happens when trying to connect:

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

But starting it manually works:

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

Anyone know what's going wrong, or how to debug this?

UPDATE: Output of /var/log/redis/redis.log is below. Btw it's a 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...

And status:

[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.
Zubin
  • 509
  • 1
  • 4
  • 9
  • 2
    It started up OK, of course, and then `User requested shutdown...` No obvious reason for that. – Michael Hampton Jul 29 '14 at 23:11
  • @MichaelHampton yes it shuts down immediately. I'd really like to know why! The only difference I can see running it manually is that it's running as root (not redis user). – Zubin Jul 30 '14 at 03:28

2 Answers2

27

Finally, fixed it. Systemd requires redis to run non-daemonised, so the config needed to change:

# /etc/redis.conf
daemonize yes # << comment this out
Zubin
  • 509
  • 1
  • 4
  • 9
  • Great. This is a bug in the systemd unit file, and you should [report it](https://bugzilla.redhat.com/enter_bug.cgi?product=Fedora%20EPEL). – Michael Hampton Jul 30 '14 at 17:35
  • Did you ever solve this? You didn't mark it as solved. – Michael Hampton Oct 06 '14 at 18:23
  • 1
    @MichaelHampton Yep, the above technique worked. In addition, I [filed the bug](https://bugzilla.redhat.com/show_bug.cgi?id=1126246) and it's been fixed. – Zubin Oct 07 '14 at 21:41
  • bless you, you beautiful bastard – Artur Sapek Aug 14 '17 at 18:54
  • I found that I also needed to edit the redis.service file (in /etc/systemd/system/multi-user.target.wants), which is linked to /usr/lib/systemd/system/redis.server. I changed ```--daemonize yes``` to, you guessed it, ```--daemonize no```. – Martin Jan 08 '18 at 14:53
2

Just to add to the accepted answer, I recently updated redis and encountered the same problem. The configuration file /etc/redis.conf already had the line daemonize no and I still had that problem.

I fixed it by telling redis to interact with the supervisor systemd:

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

For reference, the system I was using was running Arch Linux.

Jerry Sun
  • 21
  • 1