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

前端 未结 3 1601
眼角桃花
眼角桃花 2021-02-15 14:16

I\'m using kue which uses node_redis, but I\'m also already using node_redis for my sessions, so I\'d like to have kue create a server on a specific po

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-15 14:44

    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.

提交回复
热议问题