Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Redis automatic installation and cluster building process

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Redis instance installation

Installation instructions: automatically extract the installation package, compile and install according to the specified path, copy the configuration file template to the data path of the Redis instance, and modify it according to the port number.

Profile template

Configuration file, current shell script, installation package

Parameter 1: Redis installation package path

Parameter 2: install instance path

Parameter 3: installation package name

Parameter 4: the port number of the installation instance

#! / bin/bashset-eif [$#-lt 4]; then echo "$(basename $0): Missing script argument" echo "$(installdir $0) [installfilename] [port]" exit 9fipotInuse = `netstat-anp | awk'{print $4}'| grep $4 | wc-l`if [$PotInUse-gt 0]; then echo "ERROR" $4 "Port is used by another process!" Exit 9fibasedir=$1installdir=$2installfilename=$3port=$4cd $basedirtar-zxvf $installfilename.tar.gz > / dev/null 2 > & 1 & cd $installfilenamemkdir-p $installdirmake PREFIX=$installdir installsleep 1s cp $basedir/redis.conf $installdirsed-I "s/instance_port/$port/g" $installdir/redis.confsleep 1s cd $installdir./bin/redis-server redis.conf > / dev/null 2 > & 1 &

Profile template

# # INCLUDES # # include / path/to/local.conf# include / path/to/other.conf## # MODULES # # loadmodule / path/to/my_module.so# loadmodule / path/to/other_module.so## NETWORK # # bind 127.0.0.1 & your ipport instance_porttcp-backlog 511timeout 0tcp-keepalive 300 GENERAL # # daemonize yessupervised nopidfile. / redis_instance_port .pidloglevel noticelogfile. / redis_log.logdatabases 16always-show-logo yes## SNAPSHOTTING # # save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbdir. / # # REPLICATION # # masterauth replica-serve-stale-data yesreplica-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noreplica-priority 100## # # SECURITY # # requirepass your_passwrod## CLIENTS # # maxclients 10000### # # MEMORY MANAGEMENT # # maxmemory # maxmemory-policy noeviction# maxmemory-samples 5# replica-ignore-maxmemory yes## LAZY FREEING # # # lazyfree-lazy-eviction nolazyfree-lazy-expire nolazyfree-lazy-server-del noreplica-lazy-flush no## APPEND ONLY MODE # # appendonly noappendfilename "appendonly.aof "# appendfsync alwaysappendfsync everysec# appendfsync nono-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yesaof-use-rdb-preamble yes## LUA SCRIPTING # # lua-time-limit 500 # # REDIS CLUSTER # # cluster-enabled yes# cluster-replica-validity-factor 10# cluster-require-full-coverage yes# cluster-replica-no-failover no## CLUSTER DOCKER/NAT Support # SLOW LOG # # slowlog-log-slower-than 10000slowlog-max-len 128# # LATENCY MONITOR # # latency-monitor-threshold 0## EVENT NOTIFICATION # # Notify-keyspace-events "# # ADVANCED CONFIG # # hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size-2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll -sparse-max-bytes 3000stream-node-max-bytes 4096stream-node-max-entries 100activerehashing yesclient-output-buffer-limit normal 00 0client-output-buffer-limit replica 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 6 million client-query-buffer-limit 1gb# proto-max-bulk-len 512mbhz 10dynamic-hz yesaof-rewrite-incremental-fsync yesrdb-save-incremental-fsync yes## ACTIVE DEFRAGMENTATION # # Enabled active defragmentation# activedefrag yes# Minimum amount of fragmentation waste to start activedefrag # active-defrag-ignore-bytes 100mb# Minimum percentage of fragmentation to start activedefrag # active-defrag-threshold-lower 10# Maximum percentage of fragmentation at which we use maximum effort# active-defrag-threshold-upper 100# Minimal effort for defrag in CPU percentage# active-defrag-cycle-min 5# Maximal effort for defrag in CPU percentage# active-defrag-cycle-max 75# Maximum Number of set/hash/zset/list fields that will be processed from# the main dictionary scan# active-defrag-max-scan-fields 1000

Installation example

Sh redis_install.sh / usr/local/redis/ / usr/local/redis5/redis9008/ redis-5.0.4 9008

Directory structure of Redi instance

Implementation of Redis Automation Cluster based on Python

Automatic cluster implementation based on Python. Initialize node to node_1~node_6, node instance needs to be cluster mode, three masters and three slaves, automate cluster, assign slots, join slave node, complete in about 3 seconds.

Import redis#masternode_1 = {'host':' 127.0.0.1, 'port': 9001,' password':'* *'} node_2 = {'host':' 127.0.0.1, 'port': 9002,' password':'* *'} node_3 = {'host':' 127.0.0.1, 'port': 9003 'password':' * *'} # slavenode_4 = {'host':' 127.0.0.1, 'port': 9004,' password':'* *'} node_5 = {'host':' 127.0.0.1, 'port': 9005,' password':'* *} node_6 = {'host':' 127.0.0.1, 'port': 9006 Redis_conn_1 = redis.StrictRedis (host=node_1 ["host"], port=node_1 ["port"], password=node_1 ["password"]) redis_conn_2 = redis.StrictRedis (host=node_2 ["host"], port=node_2 ["port"], password=node_2 ["password"]) redis_conn_3 = redis.StrictRedis (host=node_3 ["host"], port=node_3 ["port"]) Password=node_3 ["password"]) # cluster meetredis_conn_1.execute_command ("cluster meet {0} {1}" .format (node_2 ["host"], node_2 ["port"]) redis_conn_1.execute_command ("cluster meet {0} {1}" .format (node_3 ["host"]) Node_3 ["port"]) print ('# flushslots #') redis_conn_1.execute_command ('cluster flushslots') redis_conn_2.execute_command (' cluster flushslots') redis_conn_3.execute_command ('cluster flushslots') print (' # add slots## #') for i in range (0mem16383 / 1): if I

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report