How to run redis on the same server on different ports?

I use kue , which uses node_redis , but I also use it node_redisfor my sessions, so I would like to kuecreate a server on a specific port, speaks by default 6379, and then kuelistens on the port 1234.

How can I do this? I found this article that talks about something similar, but I really don't want to create an init script for this.

+4
source share
2 answers

Run redis-server and supply another argument for the "port", which can be done on the command line:

edd@max:~$ redis-server -h
Usage: ./redis-server [/path/to/redis.conf] [options]
       ./redis-server - (read config from stdin)
       ./redis-server -v or --version
       ./redis-server -h or --help
       ./redis-server --test-memory <megabytes>

Examples:
       ./redis-server (run the server with default conf)
       ./redis-server /etc/redis/6379.conf
       ./redis-server --port 7777
       ./redis-server --port 7777 --slaveof 127.0.0.1 8888
       ./redis-server /etc/myredis.conf --loglevel verbose

Sentinel mode:
       ./redis-server /etc/sentinel.conf --sentinel
edd@max:~$ 

You can do this, for example /etc/rc.local, so that it happens at startup.

But perhaps you can also rethink your approach. Is Redis so good at handling records that you can just get along with a second database?

+18
source

You can run multiple instances of Redis with different ports on the same computer. This is true as you can follow these steps.

When installing the first instance of Redis, it listens for localhost: 6379 by default.

  • For the second instance,
    create a new working directory

redis /var/lib/redis , - dump.rdb, . ,

mkdir -p /var/lib/redis2/
chown redis /var/lib/redis2/
chgrp redis /var/lib/redis2/

, /etc/redis.conf

cp /etc/redis.conf /etc/redis2.conf
chown redis /etc/redis2.conf

,

logfile "/var/log/redis/redis2.log"
dir "/var/lib/redis2"
pidfile "/var/run/redis/redis2.pid"
port 6380

cp /usr/lib/systemd/system/redis.service /usr/lib/systemd/system/redis2.service

[Service]
ExecStart=/usr/bin/redis-server /etc/redis2.conf --daemonize no
ExecStop=/usr/bin/redis-shutdown redis2

      systemctl enable redis2

2-

service redis2 start


check status

lsof -i:6379
lsof -i:6380

, Redis. , .

0

Source: https://habr.com/ru/post/1547343/


All Articles