Existing problems:

When a server deploys multiple sites, the first website is installed with the Redis plug-in, and the connection is successful. Since there is only one Redis port, when the second and third websites install Redis extensions, they will automatically jump to the first site. Therefore, there will be conflicts after multiple websites are deployed. As a result, accessing different websites on the same server on one computer will pop up the Redis node of another website. I'm really upset!

Problems to be solved:

When deploying different sites on the same server, multiple Redis instances need to be started: one 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 solution is as follows:

Step 1: Copy multiple redis.confs and modify the configuration. Do what you want

 #cd /www/server/regis #cp redis.conf redis6380.conf #Vi redis6380. conf # Note: You can modify redis6380. conf by entering 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. You should strictly follow the requirements

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

Modify the REDIS_PORT port number in the following script

 #!/ 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: Add redis6380...... To the self startup item and view the startup item

 #cd /etc/init.d #Chkconfig -- add redis6380 or # chkconfig redis6380 on #chkconfig --list Note: The output results only show SysV services, not including Native systemd service. SysV configuration data It may be overwritten by the native systemd configuration. To list systemd services, execute 'systemctl list unit files'. To view the services enabled on a specific target, please execute 'systemctl list-dependencies [target]'。 Bt 0: 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 6: off Memcached 0: Off 1: Off 2: On 3: On 4: On 5: On 6: Off Mysqld 0: Off 1: Off 2: On 3: On 4: On 5: On 6: Off Netconsole 0: close 1: close 2: close 3: close 4: close 5: close 6: close Network 0: Off 1: Off 2: On 3: On 4: On 5: On 6: Off Nginx 0: close 1: close 2: open 3: open 4: open 5: open 6: close 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 Redis6380 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 5: On 6: Off

In the same way, you can add more than N if you want, and then just do whatever you want

After adding a startup item, start it immediately

 cd /etc/init.d ./redis6380 start
This article cannot be reproduced without permission. If it needs to be reproduced, please indicate the source https://www.scit028.com/post-260.html
Last modification: February 19, 2022
If you think my article is useful to you, please feel free to appreciate it