中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

做企業(yè)網(wǎng)站需要買什么百度有幾個總部

做企業(yè)網(wǎng)站需要買什么,百度有幾個總部,男朋友是做網(wǎng)站的賺錢不,新型建站技術(shù)一 關(guān)系型數(shù)據(jù)庫和 NoSQL 數(shù)據(jù)庫 數(shù)據(jù)庫主要分為兩大類:關(guān)系型數(shù)據(jù)庫與 NoSQL 數(shù)據(jù)庫 關(guān)系型數(shù)據(jù)庫 ,是建立在關(guān)系模型基礎(chǔ)上的數(shù)據(jù)庫,其借助于集合代數(shù)等數(shù)學(xué)概念和方法來處理數(shù)據(jù)庫中的數(shù)據(jù)主流的 MySQL 、 Oracle 、 MS SQL Server 和 D…

一 關(guān)系型數(shù)據(jù)庫和 NoSQL 數(shù)據(jù)庫

數(shù)據(jù)庫主要分為兩大類:關(guān)系型數(shù)據(jù)庫與 NoSQL 數(shù)據(jù)庫

關(guān)系型數(shù)據(jù)庫 ,是建立在關(guān)系模型基礎(chǔ)上的數(shù)據(jù)庫,其借助于集合代數(shù)等數(shù)學(xué)概念和方法來處理數(shù)據(jù)庫中的數(shù)據(jù)主流的 MySQL 、 Oracle 、 MS SQL Server DB2 都屬于這類傳統(tǒng)數(shù)據(jù)庫。
NoSQL 數(shù)據(jù)庫 ,全稱為 Not Only SQL ,意思就是適用關(guān)系型數(shù)據(jù)庫的時候就使用關(guān)系型數(shù)據(jù)庫,不適用的時候也沒有必要非使用關(guān)系型數(shù)據(jù)庫不可,可以考慮使用更加合適的數(shù)據(jù)存儲。主要分為臨時性鍵值存儲(memcached Redis )、永久性鍵值存儲( ROMA 、 Redis )、面向文檔的數(shù)據(jù)庫(MongoDB 、 CouchDB )、面向列的數(shù)據(jù)庫( Cassandra HBase ),每種 NoSQL 都有其特有的使用場景及優(yōu)點(diǎn)。

為什么還要用 NoSQL 數(shù)據(jù)庫呢?

主要是由于隨著互聯(lián)網(wǎng)發(fā)展,數(shù)據(jù)量越來越大,對性能要求越來越高,傳統(tǒng)數(shù)據(jù)庫存在著先天性的缺陷,即單機(jī)(單庫)性能瓶頸,并且擴(kuò)展困難。這樣既有單機(jī)單庫瓶頸,卻又?jǐn)U展困難,自然無法滿足日益增長的海量數(shù)據(jù)存儲及其性能要求,所以才會出現(xiàn)了各種不同的 NoSQL 產(chǎn)品, NoSQL 根本性的優(yōu)勢在于在云計算時代,簡單、易于大規(guī)模分布式擴(kuò)展,并且讀寫性能非常高

RDBMSNOSQL的特點(diǎn)及優(yōu)缺點(diǎn):

Remote Dictionary Server 簡介

中文官網(wǎng)?? https://redis.cn

什么是redis ?

Redis (Remote Dictionary Server)
2009 年發(fā)布,開發(fā)者是意大利的薩爾瓦多 · 桑菲利波普( Salvatore Sanfilippo ),他本想為自己的公司開發(fā)一個用于替換MySQL 的產(chǎn)品 Redis ,但是沒有想到他把 Redis 開源后大受歡迎,短短幾年, Redis 就有了很大的用戶群體,目前國內(nèi)外使用的公司眾多, 比如 : 阿里 , 百度 , 新浪微博 , 知乎網(wǎng) ,GitHub,Twitter
Redis 是一個開源的、遵循 BSD 協(xié)議的、基于內(nèi)存的而且目前比較流行的鍵值數(shù)據(jù)庫 (key-value database),是一個非關(guān)系型數(shù)據(jù)庫, redis 提供將內(nèi)存通過網(wǎng)絡(luò)遠(yuǎn)程共享的一種服務(wù),提供類似功能的還有memcached ,但相比 memcached redis 還提供了易擴(kuò)展、高性能、具備數(shù)據(jù)持久性等功能。
Redis 在高并發(fā)、低延遲環(huán)境要求比較高的環(huán)境使用量非常廣泛。

Redis特性 ?

  • 速度快: 10W QPS,基于內(nèi)存,C語言實(shí)現(xiàn)
  • 單線程
  • 持久化
  • 支持多種數(shù)據(jù)結(jié)構(gòu)
  • 支持多種編程語言
  • 功能豐富: 支持Lua腳本,發(fā)布訂閱,事務(wù),pipeline等功能
  • 簡單: 代碼短小精悍(單機(jī)核心代碼只有23000行左右),單線程開發(fā)容易,不依賴外部庫,使用簡單
  • 主從復(fù)制
  • 支持高可用和分布式

單線程為何如此快 ?
  • 純內(nèi)存
  • 非阻塞
  • 避免線程切換和競態(tài)消耗

?Redis應(yīng)用場景

  • Session 共享:常見于web集群中的Tomcat或者PHP中多web服務(wù)器session共享
  • 緩存:數(shù)據(jù)查詢、電商網(wǎng)站商品信息、新聞內(nèi)容
  • 計數(shù)器:訪問排行榜、商品瀏覽數(shù)等和次數(shù)相關(guān)的數(shù)值統(tǒng)計場景
  • 微博/微信社交場合:共同好友,粉絲數(shù),關(guān)注,點(diǎn)贊評論等
  • 消息隊列:ELK的日志緩存、部分業(yè)務(wù)的訂閱發(fā)布系統(tǒng)
  • 地理位置: 基于GEO(地理信息定位),實(shí)現(xiàn)搖一搖,附近的人,外賣等功能

?緩存的實(shí)現(xiàn)流程

數(shù)據(jù)更新操作流程

數(shù)據(jù)讀操作流程

? Redis的安裝

官方下載地址:http://download.redis.io/releases/ ?

?源碼安裝

[root@redis-node1 ~]# tar zxf redis-7.4.0.tar.gz #壓縮包自行下載
[root@redis-node1 ~]# ls
anaconda-ks.cfg  redis-7.4.0  redis-7.4.0.tar.gz
[root@redis-node1 ~]# yum install make gcc initscripts -y #安裝編譯工具#執(zhí)行編譯命令
[root@redis-node1 redis-7.4.0]# make && make install[root@redis-node1 redis-7.4.0]# cd utils/
[root@redis-node1 utils]# vim install_server.sh #講一下內(nèi)容注釋掉#bail if this system is managed by systemd#_pid_1_exe="$(readlink -f /proc/1/exe)"#if [ "${_pid_1_exe##*/}" = systemd ]#then# echo "This systems seems to use systemd."# echo "Please take a look at the provided example service unit files in this     directory, and adapt and install them. Sorry!"# exit 1#fi[root@redis-node1 utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis serverPlease select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful![root@redis-node1 utils]# vim /etc/redis/6379.conf #修改以下參數(shù)
bind * -::*
protected-mode no[root@redis-node1 utils]# /etc/init.d/redis_6379 restart
Stopping ...
Redis stopped
Starting Redis server...[root@redis-node1 utils]# netstat -antlupe | grep redis
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      0          31759      7611/redis-server *
tcp6       0      0 :::6379                 :::*                    LISTEN      0          31760      7611/redis-server *[root@redis-node1 utils]# redis-cli
127.0.0.1:6379>

四 Redis 主從復(fù)制

環(huán)境配置

redis-node1 master
redis-node2 slave
redis-node3 slave
在配置多臺 redis 時建議用復(fù)制的方式節(jié)省編譯時間

配置主從同步?

1.修改mastser節(jié)點(diǎn)的配置文件

[root@redis-node1 bin]# vim /etc/redis/6379.confprotected-mode no #關(guān)閉protected模式[root@redis-node1 utils]# /etc/init.d/redis_6379 restart

2.配置slave節(jié)點(diǎn)

[root@redis-node2 bin]# vim /etc/redis/6379.confprotected-mode no #關(guān)閉protected模式
replicaof 172.25.254.10 6379[root@redis-node2 utils]# /etc/init.d/redis_6379 restart[root@redis-node3 bin]# vim /etc/redis/6379.confprotected-mode no #關(guān)閉protected模式
replicaof 172.25.254.100 6379[root@redis-node3 utils]# /etc/init.d/redis_6379 restart

3.測試效果 ?

[root@redis-node1 bin]# redis-cli
127.0.0.1:6379> INFO replication
# Replication
role:master
connected_slaves:2
slave0:ip=172.25.254.20,port=6379,state=online,offset=2636,lag=1
slave1:ip=172.25.254.30,port=6379,state=online,offset=2636,lag=0
master_failover_state:no-failover
master_replid:2aac666a85461a4af445c6f48397a074ea2a500e
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:2636
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:2636127.0.0.1:6379> set name zhangsan
OK[root@redis-node2 utils]# redis-cli
127.0.0.1:6379> get name
"zhangsan"[root@redis-node3 utils]# redis-cli
127.0.0.1:6379> get name
"zhangsan"

主從同步過程

  • slave節(jié)點(diǎn)發(fā)送同步親求到master節(jié)點(diǎn)
  • slave節(jié)點(diǎn)通過master節(jié)點(diǎn)的認(rèn)證開始進(jìn)行同步
  • master節(jié)點(diǎn)會開啟bgsave進(jìn)程發(fā)送內(nèi)存rbdslave節(jié)點(diǎn),在此過程中是異步操作,也就是說 master節(jié)點(diǎn)仍然可以進(jìn)行寫入動作
  • slave節(jié)點(diǎn)收到rdb后首先清空自己的所有數(shù)據(jù)
  • slave節(jié)點(diǎn)加載rdb并進(jìn)行數(shù)據(jù)恢復(fù)
  • masterslave同步過程中master還會開啟新的bgsave進(jìn)程把沒有同步的數(shù)據(jù)進(jìn)行緩存
  • 然后通過自有的replactionfeedslave函數(shù)把未通過內(nèi)存快照發(fā)動到slave的數(shù)據(jù)一條一條寫入到
slave

五 Redis的哨兵(高可用)

?Redis哨兵

Sentinel 進(jìn)程是用于監(jiān)控 redis 集群中 Master 主服務(wù)器工作的狀態(tài),在 Master 主服務(wù)器發(fā)生故障的時候,可以實(shí)現(xiàn)Master Slave 服務(wù)器的切換,保證系統(tǒng)的高可用,此功能在 redis2.6+ 的版本已引用, Redis 的哨兵模式到了2.8 版本之后就穩(wěn)定了下來。一般在生產(chǎn)環(huán)境也建議使用 Redis 2.8 版本的以后版本。

每個哨兵 (Sentinel) 進(jìn)程會向其它哨兵 (Sentinel) 、 Master 、 Slave 定時發(fā)送消息,以確認(rèn)對方是否 ”著,如果發(fā)現(xiàn)對方在指定配置時間( 此項(xiàng)可配置 ) 內(nèi)未得到回應(yīng),則暫時認(rèn)為對方已離線,也就是所謂的 ”主觀認(rèn)為宕機(jī)” ( 主觀 : 是每個成員都具有的獨(dú)自的而且可能相同也可能不同的意識 ) ,英文名稱:Subjective Down,簡稱 SDOWN
有主觀宕機(jī),對應(yīng)的有客觀宕機(jī)。當(dāng) 哨兵群 中的多數(shù) Sentinel 進(jìn)程在對 Master 主服務(wù)器做出 SDOWN 的判斷,并且通過 SENTINEL is-master-down-by-addr 命令互相交流之后,得出的 Master Server 下線判斷,這種方式就是“ 客觀宕機(jī) ”( 客觀 : 是不依賴于某種意識而已經(jīng)實(shí)際存在的一切事物 ) ,英文名稱是:Objectively Down, 簡稱 ODOWN
通過一定的 vote 算法,從剩下的 slave 從服務(wù)器節(jié)點(diǎn)中,選一臺提升為 Master 服務(wù)器節(jié)點(diǎn),然后自動修改相關(guān)配置,并開啟故障轉(zhuǎn)移(failover
Sentinel 機(jī)制可以解決 master slave 角色的自動切換問題,但單個 Master 的性能瓶頸問題無法解決 , 類似于MySQL 中的 MHA 功能
Redis Sentinel 中的 Sentinel 節(jié)點(diǎn)個數(shù)應(yīng)該為大于等于 3 且最好為奇數(shù)
sentinel 中的三個定時任務(wù)
  • 10秒每個sentinelmasterslave執(zhí)行info ????????
  • 發(fā)現(xiàn)slave節(jié)點(diǎn)
  • 確認(rèn)主從關(guān)系
  • 2秒每個sentinel通過master節(jié)點(diǎn)的channel交換信息(pub/sub)
  • 通過sentinel__:hello頻道交互
  • 交互對節(jié)點(diǎn)的看法和自身信息
  • 1秒每個sentinel對其他sentinelredis執(zhí)行pi

哨兵的實(shí)驗(yàn)過程

在所有階段中關(guān)閉 protected-mode no

1.master節(jié)點(diǎn)中

#編輯配置文件
[root@redis-node1 ~]# cd redis-7.4.0/
[root@redis-node1 redis-7.4.0]# cp sentinel.conf /etc/redis/
[root@redis-node1 redis-7.4.0]# vim /etc/redis/sentinel.conf
protected-mode no #關(guān)閉保護(hù)模式
port 26379 #監(jiān)聽端口
daemonize no #進(jìn)入不打如后臺
pidfile /var/run/redis-sentinel.pid #sentinel進(jìn)程pid文件
loglevel notice #日志級別
sentinel monitor mymaster 172.25.254.100 6379 2 #創(chuàng)建sentinel監(jiān)控監(jiān)控master主
機(jī),2表示必須得到2票
sentinel down-after-milliseconds mymaster 10000 #master中斷時長,10秒連不上視為
master下線
sentinel parallel-syncs mymaster 1 #發(fā)生故障轉(zhuǎn)移后,同時開始同步新
master數(shù)據(jù)的slave數(shù)量
sentinel failover-timeout mymaster 180000 #整個故障切換的超時時間為3分鐘
####復(fù)制配置文件到其他階段
[root@redis-node1 redis-7.4.0]# scp /etc/redis/sentinel.conf
root@172.25.254.20:/etc/redis/[root@redis-node1 redis-7.4.0]# scp /etc/redis/sentinel.conf
root@172.25.254.30:/etc/redis/

?2 啟動服務(wù)

[root@redis-node1 redis]# redis-sentinel /etc/redis/sentinel.conf
8186:X 08 Sep 2024 18:28:42.695 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. 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.
8186:X 08 Sep 2024 18:28:42.695 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
8186:X 08 Sep 2024 18:28:42.695 * Redis version=7.4.0, bits=64, commit=00000000, modified=0, pid=8186, just started
8186:X 08 Sep 2024 18:28:42.695 * Configuration loaded
8186:X 08 Sep 2024 18:28:42.696 * Increased maximum number of open files to 10032 (it was originally set to 1024).
8186:X 08 Sep 2024 18:28:42.696 * monotonic clock: POSIX clock_gettime_.__.-``__ ''-.__.-``    `.  `_.  ''-._           Redis Community Edition.-`` .-```.  ```\/    _.,_ ''-._     7.4.0 (00000000/0) 64 bit(    '      ,       .-`  | `,    )     Running in sentinel mode|`-._`-...-` __...-.``-._|'` _.-'|     Port: 26379|    `-._   `._    /     _.-'    |     PID: 8186`-._    `-._  `-./  _.-'    _.-'|`-._`-._    `-.__.-'    _.-'_.-'||    `-._`-._        _.-'_.-'    |           https://redis.io`-._    `-._`-.__.-'_.-'    _.-'|`-._`-._    `-.__.-'    _.-'_.-'||    `-._`-._        _.-'_.-'    |`-._    `-._`-.__.-'_.-'    _.-'`-._    `-.__.-'    _.-'`-._        _.-'`-.__.-'8186:X 08 Sep 2024 18:28:42.698 * Sentinel new configuration saved on disk
8186:X 08 Sep 2024 18:28:42.699 * Sentinel ID is 6f61c9c00908c018579564cacb1b87ce1819ae39
8186:X 08 Sep 2024 18:28:42.699 # +monitor master mymaster 172.25.254.10 6379 quorum 2
8186:X 08 Sep 2024 18:28:42.699 * +slave slave 172.25.254.20:6379 172.25.254.20 6379 @ mymaster 172.25.254.10 6379
8186:X 08 Sep 2024 18:28:42.701 * Sentinel new configuration saved on disk
8186:X 08 Sep 2024 18:28:42.701 * +slave slave 172.25.254.30:6379 172.25.254.30 6379 @ mymaster 172.25.254.10 6379
8186:X 08 Sep 2024 18:28:42.702 * Sentinel new configuration saved on disk
8186:X 08 Sep 2024 18:29:05.029 * +sentinel sentinel 4a69b2501e30133613ef79a691fb79e469987a2a 172.25.254.20 26379 @ mymaster 172.25.254.10 6379
8186:X 08 Sep 2024 18:29:05.031 * Sentinel new configuration saved on disk
8186:X 08 Sep 2024 18:29:15.502 * +sentinel sentinel b6de2cc3781faf822bf6a89b9c8d70e5b9a2d0c9 172.25.254.30 26379 @ mymaster 172.25.254.10 6379
8186:X 08 Sep 2024 18:29:15.504 * Sentinel new configuration saved on disk
8186:X 08 Sep 2024 18:30:03.421 # +sdown master mymaster 172.25.254.10 6379
8186:X 08 Sep 2024 18:30:03.457 * Sentinel new configuration saved on disk

注意:/etc/redis/sentinel.conf 文件在用哨兵程序調(diào)用后會更改其配置文件,如果需要重新做需要刪掉文件重新編輯

測試:

[root@redis-node1 ~]# redis-cli
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=172.25.254.20,port=6379,state=online,offset=31425,lag=0
slave1:ip=172.25.254.30,port=6379,state=online,offset=31425,lag=0
master_failover_state:no-failover
master_replid:f5747c81b81bc83acf68a269251225721fbf810e
master_replid2:f289a3b72a069a75915690ba0f102e8f08b7a074
master_repl_offset:31707
second_repl_offset:23776
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:23776
repl_backlog_histlen:7932
127.0.0.1:6379> SHUTDOWN
(0.92s)[root@redis-node2 ~]# redis-cli
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=172.25.254.30,port=6379,state=online,offset=44414,lag=0
master_failover_state:no-failover
master_replid:988d209809c7e1980bb24f83f53964a750e0cf81
master_replid2:f5747c81b81bc83acf68a269251225721fbf810e
master_repl_offset:44555
second_repl_offset:34875
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:15
repl_backlog_histlen:44541

在整個架構(gòu)中可能會出現(xiàn)的問題

問題:
在生產(chǎn)環(huán)境中如果 master slave 中的網(wǎng)絡(luò)出現(xiàn)故障,由于哨兵的存在會把 master 提出去
當(dāng)網(wǎng)絡(luò)恢復(fù)后, master 發(fā)現(xiàn)環(huán)境發(fā)生改變, master 就會把自己的身份轉(zhuǎn)換成 slave
master 變成 slave 后會把網(wǎng)絡(luò)故障那段時間寫入自己中的數(shù)據(jù)清掉,這樣數(shù)據(jù)就丟失了。
解決:
master 在被寫入數(shù)據(jù)時會持續(xù)連接 slave mater 確保有 2 slave 可以寫入我才允許寫入
如果 slave 數(shù)量少于 2 個便拒絕寫入。
#在master中配置
[root@redis-node2 ~]# redis-cli
127.0.0.1:6379> config get min-slaves-to-write
1) "min-slaves-to-write"
2) "0"
127.0.0.1:6379> config set min-slaves-to-write 2
OK
127.0.0.1:6379> config get min-slaves-to-write
1) "min-slaves-to-write"
2) "2"
##################################以上為臨時修改#永久修改
[root@redis-node2 ~]# vim /etc/redis/6379.conf
min-slaves-to-write 2

?六?Redis Cluster(無中心化設(shè)計)

Redis Cluster 工作原理

在哨兵 sentinel 機(jī)制中,可以解決 redis 高可用問題,即當(dāng) master 故障后可以自動將 slave 提升為 master, 從而可以保證redis 服務(wù)的正常使用,但是無法解決 redis 單機(jī)寫入的瓶頸問題,即單機(jī) redis 寫入性能受限于單機(jī)的內(nèi)存大小、并發(fā)數(shù)量、網(wǎng)卡速率等因素。
redis 3.0 版本之后推出了無中心架構(gòu)的 redis cluster 機(jī)制,在無中心的 redis 集群當(dāng)中,其每個節(jié)點(diǎn)保存當(dāng)前節(jié)點(diǎn)數(shù)據(jù)和整個集群狀態(tài), 每個節(jié)點(diǎn)都和其他所有節(jié)點(diǎn)連接。
Redis Cluster特點(diǎn)如下
1. 所有Redis節(jié)點(diǎn)使用(PING機(jī)制)互聯(lián)
2. 集群中某個節(jié)點(diǎn)的是否失效,是由整個集群中超過半數(shù)的節(jié)點(diǎn)監(jiān)測都失效,才能算真正的失效
3. 客戶端不需要proxy即可直接連接redis,應(yīng)用程序中需要配置有全部的redis服務(wù)器IP
4. redis cluster把所有的redis node 平均映射到 0-16383個槽位(slot)上,讀寫需要到指定的redis node上進(jìn)行操作,因此有多少個redis node相當(dāng)于redis 并發(fā)擴(kuò)展了多少倍,每個redis node承擔(dān)16384/N個槽位
5. Redis cluster預(yù)先分配16384個(slot)槽位,當(dāng)需要在redis集群中寫入一個key -value的時候,會使用CRC16(key) mod 16384之后的值,決定將key寫入值哪一個槽位從而決定寫入哪一個Redis節(jié)點(diǎn)上,從而有效解決單機(jī)瓶頸。
Redis cluster 架構(gòu)
假如三個主節(jié)點(diǎn)分別是: A, B, C 三個節(jié)點(diǎn),采用哈希槽 (hash slot) 的方式來分配 16384 slot 的話它們
三個節(jié)點(diǎn)分別承擔(dān)的 slot 區(qū)間可以是:
節(jié)點(diǎn) A 覆蓋 0 5460
節(jié)點(diǎn) B 覆蓋 5461 10922
節(jié)點(diǎn) C 覆蓋 10923 16383

?

Redis cluster 主從架構(gòu)
Redis cluster 的架構(gòu)雖然解決了并發(fā)的問題,但是又引入了一個新的問題,每個 Redis master 的高可用如何解決?
那就是對每個 master 節(jié)點(diǎn)都實(shí)現(xiàn)主從復(fù)制 , 從而實(shí)現(xiàn) redis 高可用性

?Redis Cluster 部署架構(gòu)說明

創(chuàng)建redis cluster的前提?

1. 每個 redis node 節(jié)點(diǎn)采用相同的硬件配置、相同的密碼、相同的 redis 版本。
2. 每個節(jié)點(diǎn)必須開啟的參數(shù)
  • cluster-enabled yes ??#必須開啟集群狀態(tài),開啟后redis進(jìn)程會有cluster顯示
  • cluster-config-file nodes-6380.conf #此文件有redis cluster集群自動創(chuàng)建和維護(hù),不需要任何手動操作
3. 所有 redis 服務(wù)器必須沒有任何數(shù)據(jù)
4. 先啟動為單機(jī) redis 且沒有任何 key value

?部署redis cluster

在所有 redis 主機(jī)中
[root@redis-node1 ~]# vim /etc/redis/redis.conf #修改以下參數(shù)
bind * -::*
masterauth "123456" #集群主從認(rèn)證requirepass "123456" #redis登陸密碼 redis-cli 命令連接redis后要用“auth 密碼”進(jìn)行認(rèn)證cluster-enabled yes #開啟cluster集群功能cluster-config-file nodes-6379.conf #指定集群配置文件cluster-node-timeout 15000 #節(jié)點(diǎn)加入集群的超時時間單位是ms[root@redis-node1 ~]# systemctl restart redis.service[root@redis-node1 ~]# redis-cli
127.0.0.1:6379> info
NOAUTH Authentication required.
127.0.0.1:6379> AUTH 123456
OK
127.0.0.1:6379> info#其他主機(jī)均要配置以上配置(簡便方案)
[root@redis-node1 ~]# for i in 20 30 110 120 130 ;do scp /etc/redis/redis.conf root@172.25.254.$i:/etc/redis/redis.conf ; done
#再重啟服務(wù)

redis-cli --cluster 參數(shù)說明

[root@redis-node1 ~]# redis-cli  --cluster help
Cluster Manager Commands:
create host1:port1 ... hostN:portN #創(chuàng)建集群
--cluster-replicas <arg> #指定master的副本數(shù)check <host:port> or <host> <port> #檢測集群信息info <host:port> or <host> <port> #查看集群信息fix <host:port> or <host> <port> #修復(fù)集群reshard <host:port> or <host> <port> #在線熱遷移集群指定主機(jī)的slots數(shù)據(jù)rebalance <host:port> or <host> <port> #平衡各集群主機(jī)的slot數(shù)量add-node new_host:new_port existing_host:existing_port #添加主機(jī)del-node host:port node_id #刪除主機(jī)import host:port #導(dǎo)入外部redis服務(wù)器的數(shù)據(jù)到
當(dāng)前集群

創(chuàng)建redis-cluster

[root@redis-node1 ~]# redis-cli  --cluster  create -a 123456 \
> 172.25.254.10:6379 172.25.254.20:6379 172.25.254.30:6379 \
> 172.25.254.110:6379 172.25.254.120:6379 172.25.254.130:6379 \
> --cluster-replicas 1
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460 #哈希槽分配
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 172.25.254.120:6379 to 172.25.254.10:6379 #主從分配情況
Adding replica 172.25.254.130:6379 to 172.25.254.20:6379
Adding replica 172.25.254.110:6379 to 172.25.254.30:6379
M: c0b144b6e29ea811040dd9e67a5b6ea8b8a1f5ea 172.25.254.10:6379slots:[0-5460] (5461 slots) master
M: 5614ce1e5d6c25524126130864b7eea815c373a0 172.25.254.20:6379slots:[5461-10922] (5462 slots) master
M: f2a85df5b5355b3fd7ded898552b8bbfd2c2f925 172.25.254.30:6379slots:[10923-16383] (5461 slots) master
S: adf52933b7434c129b81292b47103e6b1eab23fb 172.25.254.110:6379replicates f2a85df5b5355b3fd7ded898552b8bbfd2c2f925
S: b3f4291d1a2313d3a9907bf65e8287f488292c66 172.25.254.120:6379replicates c0b144b6e29ea811040dd9e67a5b6ea8b8a1f5ea
S: aee197141809a2f031f7e952d504c6aa9dd0c0c3 172.25.254.130:6379replicates 5614ce1e5d6c25524126130864b7eea815c373a0
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
...
>>> Performing Cluster Check (using node 172.25.254.10:6379)
M: c0b144b6e29ea811040dd9e67a5b6ea8b8a1f5ea 172.25.254.10:6379slots:[0-5460] (5461 slots) master1 additional replica(s)
S: aee197141809a2f031f7e952d504c6aa9dd0c0c3 172.25.254.130:6379slots: (0 slots) slavereplicates 5614ce1e5d6c25524126130864b7eea815c373a0
S: b3f4291d1a2313d3a9907bf65e8287f488292c66 172.25.254.120:6379slots: (0 slots) slavereplicates c0b144b6e29ea811040dd9e67a5b6ea8b8a1f5ea
M: f2a85df5b5355b3fd7ded898552b8bbfd2c2f925 172.25.254.30:6379slots:[10923-16383] (5461 slots) master1 additional replica(s)
S: adf52933b7434c129b81292b47103e6b1eab23fb 172.25.254.110:6379slots: (0 slots) slavereplicates f2a85df5b5355b3fd7ded898552b8bbfd2c2f925
M: 5614ce1e5d6c25524126130864b7eea815c373a0 172.25.254.20:6379slots:[5461-10922] (5462 slots) master1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...    #檢查打開的哈希槽位
>>> Check slots coverage...    #檢查槽位覆蓋范圍
[OK] All 16384 slots covered.    #所有槽位分配完成

?檢測redis集群狀態(tài)

[root@redis-node1 ~]# redis-cli -a 123456 --cluster info 172.25.254.10:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
172.25.254.10:6379 (c0b144b6...) -> 0 keys | 5461 slots | 1 slaves.
172.25.254.30:6379 (f2a85df5...) -> 0 keys | 5461 slots | 1 slaves.
172.25.254.20:6379 (5614ce1e...) -> 0 keys | 5462 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
[root@redis-node1 ~]# redis-cli -a 123456 --cluster check 172.25.254.10:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
172.25.254.10:6379 (c0b144b6...) -> 0 keys | 5461 slots | 1 slaves.
172.25.254.30:6379 (f2a85df5...) -> 0 keys | 5461 slots | 1 slaves.
172.25.254.20:6379 (5614ce1e...) -> 0 keys | 5462 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 172.25.254.10:6379)
M: c0b144b6e29ea811040dd9e67a5b6ea8b8a1f5ea 172.25.254.10:6379slots:[0-5460] (5461 slots) master1 additional replica(s)
S: aee197141809a2f031f7e952d504c6aa9dd0c0c3 172.25.254.130:6379slots: (0 slots) slavereplicates 5614ce1e5d6c25524126130864b7eea815c373a0
S: b3f4291d1a2313d3a9907bf65e8287f488292c66 172.25.254.120:6379slots: (0 slots) slavereplicates c0b144b6e29ea811040dd9e67a5b6ea8b8a1f5ea
M: f2a85df5b5355b3fd7ded898552b8bbfd2c2f925 172.25.254.30:6379slots:[10923-16383] (5461 slots) master1 additional replica(s)
S: adf52933b7434c129b81292b47103e6b1eab23fb 172.25.254.110:6379slots: (0 slots) slavereplicates f2a85df5b5355b3fd7ded898552b8bbfd2c2f925
M: 5614ce1e5d6c25524126130864b7eea815c373a0 172.25.254.20:6379slots:[5461-10922] (5462 slots) master1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
寫入數(shù)據(jù)
[root@redis-node1 ~]# redis-cli -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> set name haha
(error) MOVED 5798 172.25.254.20:6379 #被分配到172.25.254.20的hash槽位上[root@redis-node2 ~]# redis-cli
127.0.0.1:6379> AUTH 123456
OK
127.0.0.1:6379>  set name haha
OK

集群擴(kuò)容

添加節(jié)點(diǎn)的時候是先添加 node 節(jié)點(diǎn)到集群,然后分配槽位,刪除節(jié)點(diǎn)的操作與添加節(jié)點(diǎn)的操作正好相反,是先將被刪除的Redis node 上的槽位遷移到集群中的其他 Redis node 節(jié)點(diǎn)上,然后再將其刪除,如果一個Redis node 節(jié)點(diǎn)上的槽位沒有被完全遷移,刪除該 node 的時候會提示有數(shù)據(jù)且無法刪除。
#添加master
[root@redis-node2 ~]# redis-cli -a 123456 --cluster add-node 172.25.254.50:6379 172.25.254.20:6379#分配槽位
[root@redis-node2 ~]# redis-cli -a 123456 --cluster reshard 172.25.254.20:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing Cluster Check (using node 172.25.254.20:6379)
M: 5614ce1e5d6c25524126130864b7eea815c373a0 172.25.254.20:6379slots:[5461-10922] (5462 slots) master1 additional replica(s)
M: c2ee7a506d8cc97b8f1b3b697d30aae90d51890a 172.25.254.50:6379slots: (0 slots) master
M: f2a85df5b5355b3fd7ded898552b8bbfd2c2f925 172.25.254.30:6379slots:[10923-16383] (5461 slots) master1 additional replica(s)
M: c0b144b6e29ea811040dd9e67a5b6ea8b8a1f5ea 172.25.254.10:6379slots:[0-5460] (5461 slots) master1 additional replica(s)
S: aee197141809a2f031f7e952d504c6aa9dd0c0c3 172.25.254.130:6379slots: (0 slots) slavereplicates 5614ce1e5d6c25524126130864b7eea815c373a0
S: b3f4291d1a2313d3a9907bf65e8287f488292c66 172.25.254.120:6379slots: (0 slots) slavereplicates c0b144b6e29ea811040dd9e67a5b6ea8b8a1f5ea
S: adf52933b7434c129b81292b47103e6b1eab23fb 172.25.254.110:6379slots: (0 slots) slavereplicates f2a85df5b5355b3fd7ded898552b8bbfd2c2f925
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 4096
What is the receiving node ID? c2ee7a506d8cc97b8f1b3b697d30aae90d51890a
Please enter all the source node IDs.Type 'all' to use all the nodes as source nodes for the hash slots.Type 'done' once you entered all the source nodes IDs.
Source node #1: all#添加salve
[root@redis-node2 ~]# redis-cli -a 123456 --cluster add-node 172.25.254.150:6379 172.25.254.20:6379  --cluster-slave --cluster-master-id  5614ce1e5d6c25524126130864b7eea815c373a0#查看集群信息
[root@redis-node2 ~]# redis-cli -a 123456 --cluster check 172.25.254.20:6379          Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
172.25.254.20:6379 (5614ce1e...) -> 0 keys | 4096 slots | 1 slaves.
172.25.254.50:6379 (c2ee7a50...) -> 1 keys | 4096 slots | 1 slaves.
172.25.254.30:6379 (f2a85df5...) -> 0 keys | 4096 slots | 1 slaves.
172.25.254.10:6379 (c0b144b6...) -> 0 keys | 4096 slots | 1 slaves.
[OK] 1 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 172.25.254.20:6379)
M: 5614ce1e5d6c25524126130864b7eea815c373a0 172.25.254.20:6379slots:[6827-10922] (4096 slots) master1 additional replica(s)
S: 4325081cf2646880c6848decfda9a87f01068e97 172.25.254.150:6379slots: (0 slots) slavereplicates c2ee7a506d8cc97b8f1b3b697d30aae90d51890a
M: c2ee7a506d8cc97b8f1b3b697d30aae90d51890a 172.25.254.50:6379slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master1 additional replica(s)
M: f2a85df5b5355b3fd7ded898552b8bbfd2c2f925 172.25.254.30:6379slots:[12288-16383] (4096 slots) master1 additional replica(s)
M: c0b144b6e29ea811040dd9e67a5b6ea8b8a1f5ea 172.25.254.10:6379slots:[1365-5460] (4096 slots) master1 additional replica(s)
S: aee197141809a2f031f7e952d504c6aa9dd0c0c3 172.25.254.130:6379slots: (0 slots) slavereplicates 5614ce1e5d6c25524126130864b7eea815c373a0
S: b3f4291d1a2313d3a9907bf65e8287f488292c66 172.25.254.120:6379slots: (0 slots) slavereplicates c0b144b6e29ea811040dd9e67a5b6ea8b8a1f5ea
S: adf52933b7434c129b81292b47103e6b1eab23fb 172.25.254.110:6379slots: (0 slots) slavereplicates f2a85df5b5355b3fd7ded898552b8bbfd2c2f925
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

clsuter集群維護(hù)

#clave節(jié)點(diǎn)沒有數(shù)據(jù),可以直接刪除
[root@redis-node2 ~]# redis-cli  -a 123456 --cluster del-node 172.25.254.150:6379  4325081cf2646880c6848decfda9a87f01068e97#移除要下線主機(jī)的哈希槽位(master節(jié)點(diǎn)上)
[root@redis-node2 ~]# redis-cli -a 123456 --cluster reshard 172.25.254.20:6379 
How many slots do you want to move (from 1 to 16384)? 4096
What is the receiving node ID? 5614ce1e5d6c25524126130864b7eea815c373a0
Please enter all the source node IDs.Type 'all' to use all the nodes as source nodes for the hash slots.Type 'done' once you entered all the source nodes IDs.
Source node #1: c2ee7a506d8cc97b8f1b3b697d30aae90d51890a #移除節(jié)點(diǎn)的id
Source node #2: done[root@redis-node2 ~]# redis-cli  -a 123456 --cluster del-node 172.25.254.50:6379 c2ee7a506d8cc97b8f1b3b697d30aae90d51890a #再刪除節(jié)點(diǎn)

http://www.risenshineclean.com/news/12193.html

相關(guān)文章:

  • 短視頻培訓(xùn)機(jī)構(gòu)seo入門到精通
  • 網(wǎng)站上文章字體部分復(fù)制怎么做seo關(guān)鍵詞排名優(yōu)化怎么樣
  • 武安市網(wǎng)站建設(shè)青島運(yùn)營網(wǎng)絡(luò)推廣業(yè)務(wù)
  • 營銷培訓(xùn)班深圳短視頻seo教程
  • 360搜索建站公司免費(fèi)發(fā)布推廣的網(wǎng)站有哪些
  • 墻蛙網(wǎng)站誰家做的搜索引擎優(yōu)化概述
  • 網(wǎng)站懸浮廣告代碼網(wǎng)站策劃書模板范文
  • 自己做網(wǎng)站教程做銷售有什么技巧和方法
  • 個人網(wǎng)站主頁設(shè)計網(wǎng)絡(luò)優(yōu)化的基本方法
  • 做用戶運(yùn)營應(yīng)該關(guān)注哪些網(wǎng)站十大輿情網(wǎng)站
  • 網(wǎng)站開發(fā)國內(nèi)外研究狀況九易建網(wǎng)站的建站模板
  • 網(wǎng)站建設(shè)_免費(fèi)視頻武漢剛剛突然宣布
  • 做一個模板網(wǎng)站多少錢如何推廣好一個產(chǎn)品
  • 絞銅機(jī) 東莞網(wǎng)站建設(shè)網(wǎng)站seo排名培訓(xùn)
  • 男的直接做的視頻網(wǎng)站站長seo推廣
  • 北京企業(yè)網(wǎng)站設(shè)計制作百度關(guān)鍵字推廣費(fèi)用
  • 做拼貨商城網(wǎng)站國際婚戀網(wǎng)站排名
  • 企業(yè)做網(wǎng)站需要哪些材料網(wǎng)絡(luò)優(yōu)化培訓(xùn)騙局
  • ac86u做網(wǎng)站服務(wù)器百度競價推廣方案范文
  • javascript菜鳥教程簡單網(wǎng)站建設(shè)優(yōu)化推廣
  • 公司網(wǎng)站用什么開發(fā)云服務(wù)器免費(fèi)
  • 推廣做網(wǎng)站怎么樣電子商務(wù)網(wǎng)站
  • wordpress的語言優(yōu)化營商環(huán)境條例
  • 北海網(wǎng)站建設(shè)比百度強(qiáng)大的搜索引擎
  • 西寧網(wǎng)站維護(hù)推廣引流網(wǎng)站
  • 網(wǎng)站引導(dǎo)視頻怎么做友情鏈接交換條件
  • 建材網(wǎng)站石家莊網(wǎng)絡(luò)推廣平臺
  • 如何讓百度不收錄網(wǎng)站b2b免費(fèi)發(fā)布平臺
  • 汕頭食品駿域網(wǎng)站建設(shè)廣州seo
  • 用asp.net做的 購物網(wǎng)站視頻百度快速排名平臺