Redis启动多端口运行多实例

来自linux中国网wiki
Evan讨论 | 贡献2019年10月14日 (一) 13:52的版本 (导入1个版本)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳到导航 跳到搜索

Redis启动多端口运行多实例

最方便 就是  redis-server --port 6380 &    #启动6380端口的redis实例。 但是重启什么的就不好了 所以多作个启动脚本是必要的 


[root@_test ]# cat /etc/init.d/redis6380 
#!/bin/sh
#Configurations injected by install_server below....

EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
#PIDFILE=/var/run/redis_6379.pid
PIDFILE=/data/redis/redis_6380.pid
CONF="/etc/redis/6380.conf"
REDISPASS="1234"
REDISPORT="6380"
###############
# SysV Init Information
# chkconfig: - 58 74
# description: redis_6379 is the redis daemon.
### BEGIN INIT INFO
# Provides: redis_6379
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Should-Start: $syslog $named
# Should-Stop: $syslog $named
# Short-Description: start and stop redis_6379
# Description: Redis daemon
### END INIT INFO
#by evan
. /etc/rc.d/init.d/functions


case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
            echo "$PIDFILE exists, process is already running or crashed"
        else
            echo "Starting Redis server..."
          #daemon --user ${REDIS_USER-redis} "$exec $REDIS_CONFIG"
         daemon --user redis  "$EXEC $CONF"
          #"$EXEC  --user redis $CONF"
           # $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
            echo "$PIDFILE does not exist, process is not running"
        else
            PID=$(cat $PIDFILE)
            echo "Stopping ..."
            $CLIEXEC -p $REDISPORT -a $REDISPASS  shutdown
            while [ -x /proc/${PID} ]
            do
                echo "Waiting for Redis to shutdown ..."
                sleep 1
            done
            echo "Redis stopped"
        fi
        ;;
    status)
        PID=$(cat $PIDFILE)
        if [ ! -x /proc/${PID} ]
        then
            echo Redis is not running
        else
            echo "Redis is running ($PID)"
        fi
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Please use start, stop, restart or status as first argument"
        ;;
esac 

参考

单机运行多端口、多实例redis http://www.361way.com/muti-redis-host/3467.html

Redis启动多端口、运行多实例 http://blog.csdn.net/rachel_luo/article/details/8858302