最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Redis自動化安裝及集群實(shí)現(xiàn)搭建過程

 更新時間:2019年09月19日 09:09:51   投稿:mrr  
這篇文章主要介紹了Redis自動化安裝以及集群實(shí)現(xiàn)搭建過程,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下

Redis實(shí)例安裝

安裝說明:自動解壓縮安裝包,按照指定路徑編譯安裝,復(fù)制配置文件模板到Redis實(shí)例路的數(shù)據(jù)徑下,根據(jù)端口號修改

配置文件模板

配置文件,當(dāng)前shell腳本,安裝包

參數(shù)1:basedir,redis安裝包路徑

參數(shù)2:安裝實(shí)例路徑

參數(shù)3:安裝包名稱

參數(shù)4:安裝實(shí)例的端口號

#!/bin/bash
set -e
if [ $# -lt 4 ]; then
    echo "$(basename $0): Missing script argument"
    echo "$(installdir $0) [installfilename] [port] "
    exit 9
fi
PotInUse=`netstat -anp | awk '{print $4}' | grep $4 | wc -l`
if [ $PotInUse -gt 0 ];then
 echo "ERROR" $4 "Port is used by another process!"
 exit 9
fi
basedir=$1
installdir=$2
installfilename=$3
port=$4
cd $basedir
tar -zxvf $installfilename.tar.gz >/dev/null 2>&1 &
cd $installfilename
mkdir -p $installdir
make PREFIX=$installdir install
sleep 1s 
cp $basedir/redis.conf $installdir

sed -i "s/instance_port/$port/g" $installdir/redis.conf
sleep 1s 
cd $installdir
./bin/redis-server redis.conf >/dev/null 2>&1 &

配置文件模板

################################## 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 ip
port instance_port
tcp-backlog 511
timeout 0
tcp-keepalive 300
################################# GENERAL #####################################
daemonize yes
supervised no
pidfile ./redis_instance_port.pid
loglevel notice
logfile ./redis_log.log
databases 16
always-show-logo yes
################################ SNAPSHOTTING ################################
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
################################# REPLICATION #################################
# masterauth <master-password>
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
################################## SECURITY ###################################
requirepass your_passwrod
################################### CLIENTS ####################################
# maxclients 10000
############################## MEMORY MANAGEMENT ################################
# maxmemory <bytes>
# maxmemory-policy noeviction
# maxmemory-samples 5
# replica-ignore-maxmemory yes
############################# LAZY FREEING ####################################
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
############################## APPEND ONLY MODE ###############################
appendonly no
appendfilename "appendonly.aof"
# appendfsync always
appendfsync everysec
# appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
################################ LUA SCRIPTING ###############################
lua-time-limit 5000
################################ 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 10000
slowlog-max-len 128
################################ LATENCY MONITOR ##############################
latency-monitor-threshold 0
############################# EVENT NOTIFICATION ##############################
notify-keyspace-events ""
############################### ADVANCED CONFIG ###############################
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
# client-query-buffer-limit 1gb
# proto-max-bulk-len 512mb
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
########################### ACTIVE DEFRAGMENTATION #######################
# Enabled active defragmentation
# activedefrag yes
# Minimum amount of fragmentation waste to start active defrag
# active-defrag-ignore-bytes 100mb
# Minimum percentage of fragmentation to start active defrag
# 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

安裝示例

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

Redi實(shí)例的目錄結(jié)構(gòu)

基于Python的Redis自動化集群實(shí)現(xiàn)

基于Python的自動化集群實(shí)現(xiàn),初始化節(jié)點(diǎn)為node_1~node_6,節(jié)點(diǎn)實(shí)例需要為集群模式,三主三從,自動化集群,分配slots,加入從節(jié)點(diǎn),3秒鐘左右完成

import redis

#master
node_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': '***'}
#slave
node_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, 'password': '***'}

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 meet
redis_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('#################flush slots #################')
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(0,16383+1):
  if i <= 5461:
    try:
      redis_conn_1.execute_command('cluster addslots {0}'.format(i))
    except:
      print('cluster addslots {0}'.format(i) +' error')
  elif 5461 < i and i <= 10922:
    try:
      redis_conn_2.execute_command('cluster addslots {0}'.format(i))
    except:
      print('cluster addslots {0}'.format(i) + ' error')
  elif 10922 < i:
    try:
      redis_conn_3.execute_command('cluster addslots {0}'.format(i))
    except:
      print('cluster addslots {0}'.format(i) + ' error')
print()
print('#################cluster status#################')
print()
print('##################'+str(node_1["host"])+':'+str(node_1["port"])+'##################')
print(str(redis_conn_1.execute_command('cluster info'), encoding = "utf-8").split("\n")[0])
print('##################'+str(node_2["host"])+':'+str(node_2["port"])+'##################')
print(str(redis_conn_1.execute_command('cluster info'), encoding = "utf-8").split("\n")[0])
print('##################'+str(node_3["host"])+':'+str(node_3["port"])+'##################')
print(str(redis_conn_1.execute_command('cluster info'), encoding = "utf-8").split("\n")[0])
#slave cluster meet
redis_conn_1.execute_command("cluster meet {0} {1}".format(node_4["host"],node_4["port"]))
redis_conn_2.execute_command("cluster meet {0} {1}".format(node_5["host"],node_5["port"]))
redis_conn_3.execute_command("cluster meet {0} {1}".format(node_6["host"],node_6["port"]))
#cluster nodes
print(str(redis_conn_1.execute_command('cluster nodes'), encoding = "utf-8"))

示例

這樣一個Redis的集群,從實(shí)例的安裝到集群的安裝,環(huán)境依賴本身沒有問題的話,基本上1分鐘之內(nèi)可以完成這個搭建過程。

總結(jié)

以上所述是小編給大家介紹的Redis自動化安裝及集群實(shí)現(xiàn)搭建過程,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

  • Redis中LRU淘汰策略的深入分析

    Redis中LRU淘汰策略的深入分析

    這篇文章主要給大家介紹了關(guān)于Redis中LRU淘汰策略的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Redis具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • Redis 在真實(shí)世界的 5 個用法

    Redis 在真實(shí)世界的 5 個用法

    Redis是一個開源的使用ANSI C語言編寫、支持網(wǎng)絡(luò)、可基于內(nèi)存亦可持久化的日志型、Key-Value數(shù)據(jù)庫,并提供多種語言的API這篇文章主要介紹了Redis 在真實(shí)世界的 5 個用法,需要的朋友可以參考下
    2018-03-03
  • Redis中一個String類型引發(fā)的慘案

    Redis中一個String類型引發(fā)的慘案

    著存儲的數(shù)據(jù)量越來越大,Redis的內(nèi)存的使用量也快速上升,結(jié)果遇到了大內(nèi)存Redis實(shí)例因?yàn)樯蒖DB而響應(yīng)變慢的問題。很顯然String類型并不是一種好的選擇,那有什么辦法可以降低內(nèi)存消耗嗎?帶著這個問題一起通過本文學(xué)習(xí)下吧
    2021-07-07
  • Redis中的配置文件,數(shù)據(jù)持久化,事務(wù)

    Redis中的配置文件,數(shù)據(jù)持久化,事務(wù)

    這篇文章主要介紹了Redis中的配置文件,數(shù)據(jù)持久化,事務(wù)問題,具有很好的參考價值,希望對大家有所幫助。
    2022-12-12
  • redis哈希類型_動力節(jié)點(diǎn)Java學(xué)院整理

    redis哈希類型_動力節(jié)點(diǎn)Java學(xué)院整理

    這篇文章主要介紹了redis哈希類型的常用方法及原理淺析,感興趣的朋友一起看看吧
    2017-08-08
  • Redis中鍵和數(shù)據(jù)庫通用指令詳解

    Redis中鍵和數(shù)據(jù)庫通用指令詳解

    這篇文章主要為大家介紹了Redis中鍵和數(shù)據(jù)庫通用指令基本操作詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-08-08
  • redis樂觀鎖與悲觀鎖的實(shí)戰(zhàn)?

    redis樂觀鎖與悲觀鎖的實(shí)戰(zhàn)?

    Redis提供了兩種鎖機(jī)制,即樂觀鎖和悲觀鎖。本文主要介紹了redis樂觀鎖與悲觀鎖的實(shí)戰(zhàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • Redis數(shù)據(jù)結(jié)構(gòu)SortedSet的底層原理解析

    Redis數(shù)據(jù)結(jié)構(gòu)SortedSet的底層原理解析

    這篇文章主要介紹了Redis數(shù)據(jù)結(jié)構(gòu)SortedSet的底層原理解析,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-07-07
  • 詳解redis在服務(wù)器linux下啟動的相關(guān)命令(安裝和配置)

    詳解redis在服務(wù)器linux下啟動的相關(guān)命令(安裝和配置)

    這篇文章主要介紹了redis在服務(wù)器linux下的啟動的相關(guān)命令(安裝和配置),本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-08-08
  • Redis String 類型和 Hash 類型學(xué)習(xí)筆記與總結(jié)

    Redis String 類型和 Hash 類型學(xué)習(xí)筆記與總結(jié)

    這篇文章主要介紹了Redis String 類型和 Hash 類型學(xué)習(xí)筆記與總結(jié),本文分別對String 類型的一些方法和Hash 類型做了詳細(xì)介紹,需要的朋友可以參考下
    2015-06-06

最新評論

新干县| 道真| 东乌珠穆沁旗| 吴川市| 梧州市| 麻阳| 马尔康县| 高邮市| 布尔津县| 大关县| 项城市| 高雄市| 永胜县| 佳木斯市| 琼中| 盐源县| 威远县| 隆化县| 莲花县| 金川县| 潜江市| 修武县| 阳朔县| 韶山市| 长沙市| 南京市| 乌兰浩特市| 醴陵市| 武鸣县| 菏泽市| 景东| 会宁县| 高雄县| 民丰县| 嘉禾县| 绍兴市| 富源县| 庐江县| 红河县| 临武县| 普宁市|