sparkContext# Runjob method The role of the Func function

2023-03-16  

Installation and other preparations can refer to the official website of Redis:Redis document
Here we mainly share two scripts (I took the big guys,@fengyong7723131 original text, I did not succeed in the beginning, I made some changes after practice)

The file structure after preparing for preparation is made according to the guidance of the official website: This is:

[email protected]:~/redis-cluster$ ll
total 8
drwxrwxr-x 1 piao piao  512 Aug  4 15:51 node_7000/
drwxrwxr-x 1 piao piao  512 Aug  4 15:42 node_7001/
drwxrwxr-x 1 piao piao  512 Aug  4 15:42 node_7002/
drwxrwxr-x 1 piao piao  512 Aug  4 17:36 node_7003/
drwxrwxr-x 1 piao piao  512 Aug  4 17:36 node_7004/
drwxrwxr-x 1 piao piao  512 Aug  4 17:36 node_7005/

No need to copy Redis-Server alone to the cluster folder. You can directly use the package management software (APT, YUM) to install Redis to call Redis-Server

The configuration file in the

node is added with a PID file configuration to facilitate the stop cluster:

port 7000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
pidfile redis.pid

#!/bin/bash
cluster_home=/home/piao/redis-cluster
cluster_dir=`ls`
#Node node number
node_size=0
#Node node array
nodes=[]
# 信息 file
infoFile="infoFile"
#pid file
pidFile="pidFile"
# Create InfoFile and PIDFILE files
touch infoFile
touch pidFile
 
# Redis node under the folder starting with node, condition 1: Node start, condition two: must be a folder
function starCluster(){
    
echo "" > $infoFile
echo "======================= The end number of the end: ================= === "
for node in $cluster_dir
 do
  echo ${node}
  if [ -d $node ]
   then 
    echo "${node}is a folder "
  else
    echo "${node}Not a folder "
  fi
  if [ "${node:0:5}" = "node_" ]
   then
      echo "starting $node"
      node_size=`expr ${
     node_size} + 1`
      cd $cluster_home/$node
      redis-server redis.conf >> $infoFile& 
  fi
done
echo ""
echo "======================================================"
echo "==================${node_size}a redis node ====================
echo "======================================================"
}
 
# Close all nodes
function stopCluster(){
    
#cat $infoFile | grep "PID" |  awk '{ infoSize=length($0);infoIndex=index($0,"PID");print substr($0,infoIndex+4,infoSize) }' > $pidFile
echo "================================================="
for node in $cluster_dir
 do
  if [ "${node:0:5}" = "node_" ]
   then
    echo -e "`cat ${
      node}/redis.pid`, \c" 
    kill -9 `cat ${
     node}/redis.pid` &
  fi
done  
echo ""
echo "======================================================"
}
 
case $1 in
start) starCluster
;;
stop) stopCluster
;;
esac

#!/bin/bash
cluster_home=/home/piao/redis-cluster/
cd $cluster_home
cluster_dir=`ls`
for node in $cluster_dir
do
  if [ "${node:0:5}" = "node_" ]
   then
	echo "Clear$node"
	rm -rf $node/appendonly.aof $node/dump.rdb $node/nodes.conf
  fi
done
redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 --cluster-replicas 1

After the cluster script is executed, you need to enter YES manually

PS: You need to pay attention to safety with Redis. The server should at least use the firewall. If the redis plus the password, it is better.

The password of the
Redis cluster seems to be manually set in each node, which can be added to the node configuration file

After

requirepass 123456

or connect to Redis, use the following command configuration:

127.0.0.1:7000 > config set requirepass 123456

source

Related Posts

Android opens the album to select the picture or open the camera to take a picture and cut it

pooling method summarizes sunshinein

Spring timer-annotation

Spring timer-annotation

sparkContext# Runjob method The role of the Func function

Random Posts

AES five encryption modes There are five working systems in the

The structure, coding and decoding Apale

FZU2203-Competition-10.1 Training Tournament

Latex picture form mixed row MyS

ES modify the IK Word Source Source MYSQL Hot Word Dynamic Update (report an error to solve X3) A problem that