How can I run redis on a single server on different ports?

喜欢而已 提交于 2019-12-03 16:19:12

Launch redis-server and supply a different argument for '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 from, say, /etc/rc.local as well so that this happens at startup.

But maybe you can also rethink your approach. Redis is so good at handling writes that you may just get by with a second database?

You can run multiple redis instance with different ports in a single machine.this concern is right mean you can follow the below steps.

By installing the first Redis instance, It listens on localhost:6379 by default.

  • For Second Instance
    create a new working directory

The default redis instance uses /var/lib/redis as its working directory, dumped memory content is saved under this directory with name dump.rdb if you did not change it manually.to avoid runtime conflict, we need to create a new working directory

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

Generate configurations

Create a new configuration file by copying /etc/redis.conf

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

Edit following settings to avoid conflicts

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

Create service file

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

Modify the settings under Service section

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

Set to start with boot

      systemctl enable redis2

Start 2nd redis

service redis2 start


check status

lsof -i:6379
lsof -i:6380

By Following this you can start two redis server.If you want more repeat the steps again.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!