自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何使用Visual Studio遠(yuǎn)程調(diào)試部署在Azure上的Web App

開發(fā) 架構(gòu)
Redis Sentinel是一個分布式系統(tǒng),釋出為一個單獨的可執(zhí)行文件 redis-sentinel , 但實際上它只是一個運行在特殊模式下的 Redis 服務(wù)器, 你可以在啟動一個普通 Redis 服務(wù)器時通過給定 --sentinel 選項來啟動 Redis Sentinel 。

介紹

Redis Sentinel 是一個分布式系統(tǒng), 你可以在一個架構(gòu)中運行多個 Sentinel 進(jìn)程(progress), 這些進(jìn)程使用流言協(xié)議(gossip protocols)來接收關(guān)于主服務(wù)器是否下線的信息, 并使用投票協(xié)議(agreement protocols)來決定是否執(zhí)行自動故障遷移, 以及選擇哪個從服務(wù)器作為新的主服務(wù)器。

雖然 Redis Sentinel 釋出為一個單獨的可執(zhí)行文件 redis-sentinel , 但實際上它只是一個運行在特殊模式下的 Redis 服務(wù)器, 你可以在啟動一個普通 Redis 服務(wù)器時通過給定 --sentinel 選項來啟動 Redis Sentinel 。

Sentinel 系統(tǒng)用于管理多個 Redis 服務(wù)器(instance), 該系統(tǒng)執(zhí)行以下三個任務(wù):

  • 監(jiān)控(Monitoring): Sentinel 會不斷地檢查你的主服務(wù)器和從服務(wù)器是否運作正常。
  • 提醒(Notification): 當(dāng)被監(jiān)控的某個 Redis 服務(wù)器出現(xiàn)問題時, Sentinel 可以通過 API 向管理員或者其他應(yīng)用程序發(fā)送通知。
  • 自動故障遷移(Automatic failover): 當(dāng)一個主服務(wù)器不能正常工作時, Sentinel 會開始一次自動故障遷移操作, 它會將失效主服務(wù)器的其中一個從服務(wù)器升級為新的主服務(wù)器, 并讓失效主服務(wù)器的其他從服務(wù)器改為復(fù)制新的主服務(wù)器; 當(dāng)客戶端試圖連接失效的主服務(wù)器時, 集群也會向客戶端返回新主服務(wù)器的地址, 使得集群可以使用新主服務(wù)器代替失效服務(wù)器。

redis版本:3.0.7

主:6379 ,sentinel:26379

從:6380 ,sentinel:26380

配置

本章主要介紹怎樣搭建自動故障轉(zhuǎn)移的reids群集,當(dāng)主宕機(jī)了從接替主成為新的主,宕機(jī)的主啟動后自動變成了從,其實它和Mysql的雙主模式是一樣的互為主從;redis群集需要用到redis-sentinel程序和sentinel.conf配置文件。

主配置

vim redis.conf

  1. daemonize yes 
  2.  
  3. pidfile /usr/local/redis-6379/run/redis.pid 
  4.  
  5. port 6379 
  6.  
  7. tcp-backlog 128 
  8.  
  9. timeout 0 
  10.  
  11. tcp-keepalive 0 
  12.  
  13. loglevel notice 
  14.  
  15. logfile "" 
  16.  
  17. databases 16 
  18.  
  19. save 900 1 
  20.  
  21. save 300 10 
  22.  
  23. save 60 10000 
  24.  
  25. stop-writes-on-bgsave-error yes 
  26.  
  27. rdbcompression yes 
  28.  
  29. rdbchecksum yes 
  30.  
  31. dbfilename dump.rdb 
  32.  
  33. dir "/usr/local/redis-6379" 
  34.  
  35. masterauth "123456" 
  36.  
  37. requirepass "123456" 
  38.  
  39. slave-serve-stale-data yes 
  40.  
  41. slave-read-only yes 
  42.  
  43. repl-diskless-sync no 
  44.  
  45. repl-diskless-sync-delay 5 
  46.  
  47. repl-disable-tcp-nodelay no 
  48.  
  49. slave-priority 100 
  50.  
  51. appendonly no 
  52.  
  53. appendfilename "appendonly.aof" 
  54.  
  55. appendfsync everysec 
  56.  
  57. no-appendfsync-on-rewrite no 
  58.  
  59. auto-aof-rewrite-percentage 100 
  60.  
  61. auto-aof-rewrite-min-size 64mb 
  62.  
  63. aof-load-truncated yes 
  64.  
  65. lua-time-limit 5000 
  66.  
  67. slowlog-log-slower-than 10000 
  68.  
  69. slowlog-max-len 128 
  70.  
  71. latency-monitor-threshold 0 
  72.  
  73. notify-keyspace-events "" 
  74.  
  75. hash-max-ziplist-entries 512 
  76.  
  77. hash-max-ziplist-value 64 
  78.  
  79. list-max-ziplist-entries 512 
  80.  
  81. list-max-ziplist-value 64 
  82.  
  83. set-max-intset-entries 512 
  84.  
  85. zset-max-ziplist-entries 128 
  86.  
  87. zset-max-ziplist-value 64 
  88.  
  89. hll-sparse-max-bytes 3000 
  90.  
  91. activerehashing yes 
  92.  
  93. client-output-buffer-limit normal 0 0 0 
  94.  
  95. client-output-buffer-limit slave 256mb 64mb 60 
  96.  
  97. client-output-buffer-limit pubsub 32mb 8mb 60 
  98.  
  99. hz 10 
  100.  
  101. aof-rewrite-incremental-fsync yes 

vim sentinel.conf

群集文件配置

  1. port 26379 
  2.  
  3. dir "/usr/local/redis-6379" 
  4.  
  5. # 守護(hù)進(jìn)程模式 
  6.  
  7. daemonize yes 
  8.  
  9. # 指明日志文件名 
  10.  
  11. logfile "./sentinel.log" 
  12.  
  13. sentinel monitor mymaster 192.168.137.40 6379 1 
  14.  
  15. sentinel down-after-milliseconds mymaster 5000 
  16.  
  17. sentinel failover-timeout mymaster 18000 
  18.  
  19. sentinel auth-pass mymaster 123456 

從配置

vim redis.conf

  1. daemonize yes 
  2.  
  3. pidfile "/usr/local/redis-6380/run/redis.pid" 
  4.  
  5. port 6380 
  6.  
  7. tcp-backlog 128 
  8.  
  9. timeout 0 
  10.  
  11. tcp-keepalive 0 
  12.  
  13. loglevel notice 
  14.  
  15. logfile "" 
  16.  
  17. databases 16 
  18.  
  19. save 900 1 
  20.  
  21. save 300 10 
  22.  
  23. save 60 10000 
  24.  
  25. stop-writes-on-bgsave-error yes 
  26.  
  27. rdbcompression yes 
  28.  
  29. rdbchecksum yes 
  30.  
  31. dbfilename "dump.rdb" 
  32.  
  33. dir "/usr/local/redis-6380" 
  34.  
  35. masterauth "123456" 
  36.  
  37. requirepass "123456" 
  38.  
  39. slave-serve-stale-data yes 
  40.  
  41. slave-read-only yes 
  42.  
  43. repl-diskless-sync no 
  44.  
  45. repl-diskless-sync-delay 5 
  46.  
  47. repl-disable-tcp-nodelay no 
  48.  
  49. slave-priority 100 
  50.  
  51. appendonly no 
  52.  
  53. appendfilename "appendonly.aof" 
  54.  
  55. appendfsync everysec 
  56.  
  57. no-appendfsync-on-rewrite no 
  58.  
  59. auto-aof-rewrite-percentage 100 
  60.  
  61. auto-aof-rewrite-min-size 64mb 
  62.  
  63. aof-load-truncated yes 
  64.  
  65. lua-time-limit 5000 
  66.  
  67. slowlog-log-slower-than 10000 
  68.  
  69. slowlog-max-len 128 
  70.  
  71. latency-monitor-threshold 0 
  72.  
  73. notify-keyspace-events "" 
  74.  
  75. hash-max-ziplist-entries 512 
  76.  
  77. hash-max-ziplist-value 64 
  78.  
  79. list-max-ziplist-entries 512 
  80.  
  81. list-max-ziplist-value 64 
  82.  
  83. set-max-intset-entries 512 
  84.  
  85. zset-max-ziplist-entries 128 
  86.  
  87. zset-max-ziplist-value 64 
  88.  
  89. hll-sparse-max-bytes 3000 
  90.  
  91. activerehashing yes 
  92.  
  93. client-output-buffer-limit normal 0 0 0 
  94.  
  95. client-output-buffer-limit slave 256mb 64mb 60 
  96.  
  97. client-output-buffer-limit pubsub 32mb 8mb 60 
  98.  
  99. hz 10 
  100.  
  101. aof-rewrite-incremental-fsync yes 

vim sentinel.conf

  1. #sentinel端口 
  2.  
  3. port 26380 
  4.  
  5. #工作路徑,注意路徑不要和主重復(fù) 
  6.  
  7. dir "/usr/local/redis-6380" 
  8.  
  9. # 守護(hù)進(jìn)程模式 
  10.  
  11. daemonize yes 
  12.  
  13. # 指明日志文件名 
  14.  
  15. logfile "./sentinel.log" 
  16.  
  17. #哨兵監(jiān)控的master,主從配置一樣, 
  18.  
  19. sentinel monitor mymaster 192.168.137.40 6379 1 
  20.  
  21. # master或slave多長時間(默認(rèn)30秒)不能使用后標(biāo)記為s_down狀態(tài)。 
  22.  
  23. sentinel down-after-milliseconds mymaster 5000 
  24.  
  25. #若sentinel在該配置值內(nèi)未能完成failover操作(即故障時master/slave自動切換),則認(rèn)為本次failover失敗。 
  26.  
  27. sentinel failover-timeout mymaster 18000 
  28.  
  29. #設(shè)置master和slaves驗證密碼 
  30.  
  31. sentinel auth-pass mymaster 123456 

啟動redis

主從都要啟動

  1. src/redis-server redis.conf 

啟動群集監(jiān)控

主從都要啟動

  1. src/redis-sentinel sentinel.conf --sentinel 

啟動報錯處理

錯誤1:

WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

  1. 兩個解決方法(overcommit_memory) 
  2.  
  3. 1. echo "vm.overcommit_memory=1" > /etc/sysctl.conf 或 vi /etcsysctl.conf , 然后reboot重啟機(jī)器 
  4.  
  5. 2. echo 1 > /proc/sys/vm/overcommit_memory 不需要啟機(jī)器就生效 
  1. overcommit_memory參數(shù)說明: 
  2.  
  3. 設(shè)置內(nèi)存分配策略(可選,根據(jù)服務(wù)器的實際情況進(jìn)行設(shè)置) 
  4.  
  5. /proc/sys/vm/overcommit_memory 
  6.  
  7. 可選值:0、1、2。 
  8.  
  9. 0, 表示內(nèi)核將檢查是否有足夠的可用內(nèi)存供應(yīng)用進(jìn)程使用;如果有足夠的可用內(nèi)存,內(nèi)存申請允許;否則,內(nèi)存申請失敗,并把錯誤返回給應(yīng)用進(jìn)程。 
  10.  
  11. 1, 表示內(nèi)核允許分配所有的物理內(nèi)存,而不管當(dāng)前的內(nèi)存狀態(tài)如何。 
  12.  
  13. 2, 表示內(nèi)核允許分配超過所有物理內(nèi)存和交換空間總和的內(nèi)存 
  14.  
  15. 注意:redis在dump數(shù)據(jù)的時候,會fork出一個子進(jìn)程,理論上child進(jìn)程所占用的內(nèi)存和parent是一樣的,比如parent占用 的內(nèi)存為8G,這個時候也要同樣分配8G的內(nèi)存給child,如果內(nèi)存無法負(fù)擔(dān),往往會造成redis服務(wù)器的down機(jī)或者IO負(fù)載過高,效率下降。所 以這里比較優(yōu)化的內(nèi)存分配策略應(yīng)該設(shè)置為 1(表示內(nèi)核允許分配所有的物理內(nèi)存,而不管當(dāng)前的內(nèi)存狀態(tài)如何)。 
  16.  
  17. 這里又涉及到Overcommit和OOM。 
  18.  
  19. 什么是Overcommit和OOM 
  20.  
  21. 在Unix中,當(dāng)一個用戶進(jìn)程使用malloc()函數(shù)申請內(nèi)存時,假如返回值是NULL,則這個進(jìn)程知道當(dāng)前沒有可用內(nèi)存空間,就會做相應(yīng)的處理工作。許多進(jìn)程會打印錯誤信息并退出。 
  22.  
  23. Linux使用另外一種處理方式,它對大部分申請內(nèi)存的請求都回復(fù)"yes",以便能跑更多更大的程序。因為申請內(nèi)存后,并不會馬上使用內(nèi)存。這種技術(shù)叫做Overcommit。 
  24.  
  25. 當(dāng)內(nèi)存不足時,會發(fā)生OOM killer(OOM=out-of-memory)。它會選擇殺死一些進(jìn)程(用戶態(tài)進(jìn)程,不是內(nèi)核線程),以便釋放內(nèi)存。 
  26.  
  27. Overcommit的策略 
  28.  
  29. Linux下overcommit有三種策略(Documentation/vm/overcommit-accounting): 
  30.  
  31. 0. 啟發(fā)式策略。合理的overcommit會被接受,不合理的overcommit會被拒絕。 
  32.  
  33. 1. 任何overcommit都會被接受。 
  34.  
  35. 2. 當(dāng)系統(tǒng)分配的內(nèi)存超過swap+N%*物理RAM(N%由vm.overcommit_ratio決定)時,會拒絕commit。 
  36.  
  37. overcommit的策略通過vm.overcommit_memory設(shè)置。 
  38.  
  39. overcommit的百分比由vm.overcommit_ratio設(shè)置。 
  40.  
  41. # echo 2 > /proc/sys/vm/overcommit_memory 
  42.  
  43. # echo 80 > /proc/sys/vm/overcommit_ratio 
  44.  
  45. 當(dāng)oom-killer發(fā)生時,linux會選擇殺死哪些進(jìn)程 
  46.  
  47. 選擇進(jìn)程的函數(shù)是oom_badness函數(shù)(在mm/oom_kill.c中),該函數(shù)會計算每個進(jìn)程的點數(shù)(0~1000)。 
  48.  
  49. 點數(shù)越高,這個進(jìn)程越有可能被殺死。 
  50.  
  51. 每個進(jìn)程的點數(shù)跟oom_score_adj有關(guān),而且oom_score_adj可以被設(shè)置(-1000***,1000***)。 

錯誤2:

WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

  1. echo 511 > /proc/sys/net/core/somaxconn 

錯誤3:

16433:X 12 Jun 14:52:37.734 * Increased maximum number of open files to 10032 (it was originally set to 1024).

  1. 新裝的linux默認(rèn)只有1024,當(dāng)負(fù)載較大時,會經(jīng)常出現(xiàn)error: too many open files 
  2.  
  3. ulimit -a:使用可以查看當(dāng)前系統(tǒng)的所有限制值 
  4.  
  5. vim /etc/security/limits.conf 
  6.  
  7. 在文件的末尾加上 
  8.  
  9. * soft nofile 65535 
  10.  
  11. * hard nofile 65535 
  12.  
  13. 執(zhí)行su或者重新關(guān)閉連接用戶再執(zhí)行ulimit -a就可以查看修改后的結(jié)果。 

故障切換機(jī)制

1. 啟動群集后,群集程序默認(rèn)會在從庫的redis文件中加入連接主的配置

  1. # Generated by CONFIG REWRITE 
  2.  
  3. slaveof 192.168.137.40 6379 

2.啟動群集之后,群集程序默認(rèn)會在主從的sentinel.conf文件中加入群集信息

主:

  1. port 26379 
  2.  
  3. dir "/usr/local/redis-6379" 
  4.  
  5. # 守護(hù)進(jìn)程模式 
  6.  
  7. daemonize yes 
  8.  
  9. # 指明日志文件名 
  10.  
  11. logfile "./sentinel.log" 
  12.  
  13. sentinel monitor mymaster 192.168.137.40 6379 1 
  14.  
  15. sentinel down-after-milliseconds mymaster 5000 
  16.  
  17. sentinel failover-timeout mymaster 18000 
  18.  
  19. sentinel auth-pass mymaster 123456 
  20.  
  21. # Generated by CONFIG REWRITE 
  22.  
  23. sentinel config-epoch mymaster 0 
  24.  
  25. sentinel leader-epoch mymaster 1 
  26.  
  27. sentinel known-slave mymaster 192.168.137.40 6380 
  28.  
  29. sentinel known-sentinel mymaster 192.168.137.40 26380 c77c5f64aaad0137a228875e531c7127ceeb5c3f 
  30.  
  31. sentinel current-epoch 1 

從:

  1. #sentinel端口 
  2.  
  3. port 26380 
  4.  
  5. #工作路徑 
  6.  
  7. dir "/usr/local/redis-6380" 
  8.  
  9. # 守護(hù)進(jìn)程模式 
  10.  
  11. daemonize yes 
  12.  
  13. # 指明日志文件名 
  14.  
  15. logfile "./sentinel.log" 
  16.  
  17. #哨兵監(jiān)控的master,主從配置一樣,在進(jìn)行主從切換時6379會變成當(dāng)前的master端口, 
  18.  
  19. sentinel monitor mymaster 192.168.137.40 6379 1 
  20.  
  21. # master或slave多長時間(默認(rèn)30秒)不能使用后標(biāo)記為s_down狀態(tài)。 
  22.  
  23. sentinel down-after-milliseconds mymaster 5000 
  24.  
  25. #若sentinel在該配置值內(nèi)未能完成failover操作(即故障時master/slave自動切換),則認(rèn)為本次failover失敗。 
  26.  
  27. sentinel failover-timeout mymaster 18000 
  28.  
  29. #設(shè)置master和slaves驗證密碼 
  30.  
  31. sentinel auth-pass mymaster 123456 
  32.  
  33. #哨兵程序自動添加的部分 
  34.  
  35. # Generated by CONFIG REWRITE 
  36.  
  37. sentinel config-epoch mymaster 0 
  38.  
  39. sentinel leader-epoch mymaster 1 
  40.  
  41. ###指明了當(dāng)前群集的從庫的ip和端口,在主從切換時該值會改變 
  42.  
  43. sentinel known-slave mymaster 192.168.137.40 6380 
  44.  
  45. ###除了當(dāng)前的哨兵還有哪些監(jiān)控的哨兵 
  46.  
  47. sentinel known-sentinel mymaster 192.168.137.40 26379 7a88891a6147e202a53601ca16a3d438e9d55c9d 
  48.  
  49. sentinel current-epoch 1 

模擬主故障

  1. [root@monitor redis-6380]# ps -ef|grep redis 
  2.  
  3. root 4171 1 0 14:20 ? 00:00:15 /usr/local/redis-6379/src/redis-server *:6379 
  4.  
  5. root 4175 1 0 14:20 ? 00:00:15 /usr/local/redis-6380/src/redis-server *:6380 
  6.  
  7. root 4305 1 0 15:28 ? 00:00:05 /usr/local/redis-6379/src/redis-sentinel *:26379 [sentinel] 
  8.  
  9. root 4306 1 0 15:28 ? 00:00:05 /usr/local/redis-6380/src/redis-sentinel *:26380 [sentinel] 
  10.  
  11. root 4337 4144 0 15:56 pts/1 00:00:00 grep redis 
  12.  
  13. [root@monitor redis-6380]# kill -9 4171 
  14.  
  15. [root@monitor redis-6380]# ps -ef|grep redis 
  16.  
  17. root 4175 1 0 14:20 ? 00:00:15 /usr/local/redis-6380/src/redis-server *:6380 
  18.  
  19. root 4305 1 0 15:28 ? 00:00:05 /usr/local/redis-6379/src/redis-sentinel *:26379 [sentinel] 
  20.  
  21. root 4306 1 0 15:28 ? 00:00:05 /usr/local/redis-6380/src/redis-sentinel *:26380 [sentinel] 
  22.  
  23. root 4339 4144 0 15:56 pts/1 00:00:00 grep redis 
  24.  
  25. [root@monitor redis-6380]# 

從哨兵配置文件中可以看到當(dāng)前的主庫的已經(jīng)發(fā)生了改變

從日志文件也可以看到當(dāng)前的主已經(jīng)從6379轉(zhuǎn)換成了6380

總結(jié)

redis的哨兵端口26379、26380使用客戶端軟件無法連接,使用程序可以連接,客戶端軟件只能直接連接6379和6380端口。使用哨兵監(jiān)控當(dāng)主故障后會自動切換從為主,當(dāng)主啟動后就變成了從。 

責(zé)任編輯:武曉燕 來源: 博客園
相關(guān)推薦

2016-08-11 14:32:54

Visual StudAzure遠(yuǎn)程調(diào)試

2009-11-23 14:32:55

Visual Stud

2012-09-17 13:49:31

2013-05-29 14:54:49

Visual Stud

2019-07-15 10:00:10

ChocoWindows 10代碼

2023-12-13 07:17:38

2009-12-16 15:05:15

Visual Stud

2009-11-13 14:49:50

Visual StudWindows Azu

2011-08-29 10:11:49

QTWindowsVisual Stud

2010-12-14 09:15:50

Visual Stud

2009-11-10 09:13:47

Visual Stud

2013-08-01 15:12:03

Visual Stud

2009-04-23 14:05:28

Visual Stud歷史調(diào)試功能

2010-03-10 11:00:26

Zend Studio遠(yuǎn)程調(diào)試

2023-02-02 09:33:04

Linux控制臺程序

2014-02-14 10:48:32

Visual StudNode.js

2009-12-03 15:58:33

Visual Stud

2009-12-04 10:35:56

Visual Stud

2019-12-20 10:28:54

工具代碼開發(fā)

2014-12-17 15:18:27

LinuxMonoWindows
點贊
收藏

51CTO技術(shù)棧公眾號