Pagoda server multi site configuration of multiple redis nodes and self start scheme
· Memo notes · 0 comment · 2,241 Views

Pagoda server multi site configuration of multiple redis nodes and self start scheme

· Memo notes · 0 comment · 2,241 Views

The existing problems are as follows:

When a server deploys multiple sites, the first website is installed with redis plug-in, and the connection is successful. Because there is only one redis port, when the second and third websites have installed the redis extension, they will automatically jump to the first site. Therefore, there will be conflicts after the deployment of multiple websites. Therefore, if you visit different websites on the same server on one computer, you will pop up the redis node of another website. I'm really upset!

Problems to be solved are as follows:

When deploying different sites on the same server, multiple redis instances need to be started: a redis server is divided into multiple nodes, and each node is assigned a port (63806381...) , the default port is 6379. Each node corresponds to a redis configuration file, such as redis6380.conf and redis6381.conf.

The solutions are as follows:

Step 1: copy multiple redis.conf and modify the configuration. Do what you want

 #CD / www / server / Regis ා CP redis.conf redis6380.conf ᦇ VI redis6380.conf ා note: modify redis6380.conf this step can be modified in the pagoda panel, only the following items can be modified 
 port 6380 
 pidfile / www / server / redis / redis_ 6380.pid
logfile "/www/server/redis/redis_ 6380.log"
dbfilename dump_ 6380.rdb

Step 2: enter the / etc / init. D directory, copy multiple redis startup entries and modify the configuration. Follow the requirements strictly

 #cd /etc/init.d
#cp redis redis6380
#vi redis6380

Modify redis in the following script_ Port port number

 #!/bin/sh
# chkconfig: 2345 56 26
# description: Redis Service

### BEGIN INIT INFO
# Provides:          Redis
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts Redis
# Description:       starts the BT-Web
### END INIT INFO

# Simple Redis init.d script conceived  to work on Linux systems
# as it does use of the /proc filesystem.

REDIS_ PORT="6380"
CONF="/www/server/redis/redis${REDIS_ PORT}.conf"
REDISPORT=$(cat $CONF |grep port|grep -v '#'|awk '{print $2}')
REDISPASS=$(cat $CONF |grep requirepass|grep -v '#'|awk '{print $2}')
REDISHOST=$(cat $CONF |grep bind|grep -v '#'|awk '{print $2}')
if [ "$REDISPASS" != "" ];then
    REDISPASS=" -a $REDISPASS"
fi
if [ -f "/www/server/redis/start${REDIS_ PORT}.pl" ];then
    STARPORT=$(cat /www/server/redis/start${REDIS_ PORT}.pl)
else
    STARPORT="${REDIS_ PORT}"
fi
EXEC=/www/server/redis/src/redis-server
CLIEXEC="/www/server/redis/src/redis-cli -h $REDISHOST -p $STARPORT$REDISPASS"
PIDFILE=/var/run/redis_ ${REDIS_ PORT}.pid

redis_ start(){
    if [ -f $PIDFILE ]
    then
            echo "$PIDFILE exists, process is already running or crashed"
    else
            echo "Starting Redis server..."
            nohup sudo -u redis $EXEC $CONF >> /www/server/redis/logs${REDIS_ PORT}.pl 2>&1 &
            echo ${REDISPORT} > /www/server/redis/start${REDIS_ PORT}.pl
    fi
}
redis_ stop(){
        echo "Stopping ..."
        $CLIEXEC shutdown
        sleep 1
        PID=`ps aux|grep "sudo -u redis"|grep -v "grep"|grep -v "/etc/init.d/redis${REDIS_ PORT}"|awk '{print $2}'`
        if [ "${PID}" != "" ];then
                sleep 3
                pkill -9 redis-server
                rm -f $PIDFILE
        fi
        echo "Redis stopped"
}


case "$1" in
    start)
        redis_ start
        ;;
    stop)
        redis_ stop
        ;;
    restart|reload)
        redis_ stop
        sleep 0.3
        redis_ start
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

Step 3: put redis6380 Add to auto start item, view startup item

 #CD / etc / init. D 
 chkconfig -- add redis6380 or ා chkconfig redis6380 on ᦇ chkconfig -- list 
 note: the output result only shows SYSV services, and does not contain 
 native SYSTEMd services. SYSV configuration data 
 may be overridden by the native SYSTEMd configuration. to list SYSTEMd services, run 'systemctl list unit files'. to view the services enabled in specific target, please execute 'systemctl list dependencies [target]'. BT0: off 1: off 2: on 3: on 4: on 5: on 6: off BT_ Syssafe 0: off 1: off 2: on 3: on 4: on 5: on 5: on 5: on 5: off 1: off 2: on 3: on 4: on 5: on 6: off mysqld 0: off 1: off 2: off 3: off 4: on 5: on 6: off netconsole 0: off 1: off 2: off 3: off 5: off 6: off network 0: off 1: off 2: on 3: on 4: On 5: on 6: off 
 nginx 0: off 1: off 2: on 3: on 4: on 5: on 6: off php-fpm-54 0: off 1: off 2: on 3: on 4: on 5: on 6: off 
 php-fpm-56 0: off 1: off 2: on 3: on 4: on 5: on 6: off 
 redis 0: off 1: off 2: on 3: on 4: on 5: on 6: off Redis6381 0: off 1: off 2: on 3: on 4: on 6: off

In the same way, if you want to add more than N, you can do whatever you want

Start immediately after adding a startup entry. Method:

 cd /etc/init.d
./redis6380 start

This article can not be reproduced without permission. If you need to reprint, please indicate the source https://www.scit028.com/post-260.html

Comments are closed.