初識redis-cluster

来源:https://www.cnblogs.com/chanAndy/archive/2018/10/27/9851512.html
-Advertisement-
Play Games

安裝redis 部署集群 參考資料 https://www.cnblogs.com/it-cen/p/4295984.html https://blog.csdn.net/naixiyi/article/details/51346880 https://www.cnblogs.com/Patrick ...


安裝redis

 1 [root@localhost ~]# cd /datas/soft/
 2 [root@localhost soft]# ll redis-5.0.0.tar.gz     // 已經下載的最新版
 3 -rwxrwxrwx 1 www www 1947721 Oct 22 14:21 redis-5.0.0.tar.gz
 4 [root@localhost soft]# tar -xzf redis-5.0.0.tar.gz
 5 [root@localhost soft]# cd redis-5.0.0
 6 [root@localhost redis-5.0.0]# make
 7 [root@localhost redis-5.0.0]# cd src
 8 [root@localhost src]# make install PREFIX=/datas/soft/redis5
 9 [root@localhost src]# mkdir /datas/soft/redis5/etc
10 [root@localhost src]# cp ../redis.conf /datas/soft/redis5/etc/
11 [root@localhost src]# vim redis.conf
12     daemonize yes  // 後臺運行
13 [root@localhost src]# cd /datas/soft/redis5/bin/
14 [root@localhost bin]# ./redis-server ../etc/redis.conf
15 16936:C 24 Oct 2018 20:01:42.406 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
16 16936:C 24 Oct 2018 20:01:42.406 # Redis version=5.0.0, bits=64, commit=00000000, modified=0, pid=16936, just started
17 16936:C 24 Oct 2018 20:01:42.406 # Configuration loaded
18 [root@localhost bin]# ps auxf | grep redis
19 root      16943  0.0  0.0 103304   872 pts/1    S+   20:02   0:00      |   \_ grep redis                     
20 root      16937  0.1  0.7 152484  7760 ?        Ssl  20:01   0:00 ./redis-server 127.0.0.1:6379
21 [root@localhost bin]# ./redis-cli -p 6379
22 127.0.0.1:6379> set a hahaha6379
23 OK
24 127.0.0.1:6379> get a
25 "hahaha6379"

部署集群

  1 [root@localhost bin]# cd ../etc
  2 [root@localhost etc]# mkdir redis-cluster
  3 [root@localhost etc]# cd redis-cluster
  4 [root@localhost redis-cluster]# mkdir 30001
  5 [root@localhost redis-cluster]# cd 30001
  6 [root@localhost 30001]# cp ../../redis.conf ./
  7 [root@localhost 30001]# vim redis.conf
  8     port 30001  // 綁定埠號
  9     daemonize yes  // 後臺運行
 10     pidfile /datas/soft/redis5/etc/redis-cluster/30001/redis.pid  // 修改pid進程文件名
 11     logfile /datas/soft/redis5/etc/redis-cluster/30001/redis.log  // 修改日誌文件名稱
 12     dir /datas/soft/redis5/etc/redis-cluster/30001/  // 修改數據文件存放地址
 13     cluster-enabled yes  // 啟用集群
 14     cluster-config-file nodes-30001.conf  // 配置每個節點的配置文件,同樣以埠號為名稱
 15     cluster-node-timeout 15000  // 配置集群節點的超時時間,可改可不改
 16     appendonly yes  // 啟動AOF增量持久化策略
 17     appendfsync always  // 發生改變就記錄日誌
 18 [root@localhost redis-cluster]# ll    // 相同步驟配置其他埠
 19 total 24
 20 drwxr-xr-x 2 root root 4096 Oct 24 21:34 30001
 21 drwxr-xr-x 2 root root 4096 Oct 24 21:34 30002
 22 drwxr-xr-x 2 root root 4096 Oct 24 21:35 30003
 23 drwxr-xr-x 2 root root 4096 Oct 24 21:35 30004
 24 drwxr-xr-x 2 root root 4096 Oct 24 21:35 30005
 25 drwxr-xr-x 2 root root 4096 Oct 24 21:35 30006
 26 [root@localhost redis-cluster]# /datas/soft/redis5/bin/redis-server /datas/soft/redis5/etc/redis-cluster/30001/redis.conf      // 啟動
 27 [root@localhost redis-cluster]# /datas/soft/redis5/bin/redis-server /datas/soft/redis5/etc/redis-cluster/30002/redis.conf 
 28 [root@localhost redis-cluster]# /datas/soft/redis5/bin/redis-server /datas/soft/redis5/etc/redis-cluster/30003/redis.conf 
 29 [root@localhost redis-cluster]# /datas/soft/redis5/bin/redis-server /datas/soft/redis5/etc/redis-cluster/30004/redis.conf 
 30 [root@localhost redis-cluster]# /datas/soft/redis5/bin/redis-server /datas/soft/redis5/etc/redis-cluster/30005/redis.conf 
 31 [root@localhost redis-cluster]# /datas/soft/redis5/bin/redis-server /datas/soft/redis5/etc/redis-cluster/30006/redis.conf 
 32 [root@localhost redis-cluster]# ps auxf | grep redis
 33 root      17034  0.0  0.0 103304   876 pts/1    S+   21:38   0:00      |   \_ grep redis
 34 root      16937  0.2  1.0 158116 10400 ?        Ssl  20:01   0:13 ./redis-server 127.0.0.1:6379   
 35 root      16997  0.9  0.7 155552  7952 ?        Ssl  21:38   0:00 /datas/soft/redis5/bin/redis-server 127.0.0.1:30001 [cluster]                            
 36 root      17003  0.6  0.7 155552  7952 ?        Ssl  21:38   0:00 /datas/soft/redis5/bin/redis-server 127.0.0.1:30002 [cluster]                            
 37 root      17008  0.6  0.7 155552  7968 ?        Ssl  21:38   0:00 /datas/soft/redis5/bin/redis-server 127.0.0.1:30003 [cluster]                            
 38 root      17013  0.6  1.2 159648 12100 ?        Ssl  21:38   0:00 /datas/soft/redis5/bin/redis-server 127.0.0.1:30004 [cluster]                            
 39 root      17020  0.4  1.2 159648 12120 ?        Ssl  21:38   0:00 /datas/soft/redis5/bin/redis-server 127.0.0.1:30005 [cluster]                            
 40 root      17027  0.7  1.2 159648 12104 ?        Ssl  21:38   0:00 /datas/soft/redis5/bin/redis-server 127.0.0.1:30006 [cluster]                            
 41 [root@localhost redis-cluster]# ll /datas/soft/redis5/etc/redis-cluster/30001/
 42 total 88
 43 -rw-r--r-- 1 root root     0 Oct 22 15:01 appendonly.aof
 44 -rw-r--r-- 1 root root   175 Oct 24 21:38 dump.rdb
 45 -rw-r--r-- 1 root root   787 Oct 24 21:38 nodes-30001.conf
 46 -rwxr-xr-x 1 root root 62271 Oct 24 21:34 redis.conf
 47 -rw-r--r-- 1 root root 10257 Oct 24 21:38 redis.log
 48 -rw-r--r-- 1 root root     6 Oct 24 21:38 redis.pid
 49 
 50 [root@localhost redis-cluster]# cd ../../bin/
 51 [root@localhost bin]# yum install -y ruby
 52 [root@localhost bin]# yum install -y rubygems
 53 [root@localhost bin]# cp /datas/soft/redis-5.0.0/src/redis-trib.rb ./
 54 [root@localhost bin]# ruby redis-trib.rb create --replicas 1 127.0.0.1:30001 127.0.0.1:30002 127.0.0.1:30003 127.0.0.1:30004 127.0.0.1:30005 127.0.0.1:30006
 55 redis-trib.rb:6: odd number list for Hash
 56         white: 29,
 57               ^
 58 redis-trib.rb:6: syntax error, unexpected ':', expecting '}'
 59         white: 29,
 60               ^
 61 redis-trib.rb:7: syntax error, unexpected ',', expecting kEND
 62 [root@localhost bin]# ruby -v
 63 ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]
 64 [root@localhost bin]# yum remove -y ruby
 65 [root@localhost bin]# yum remove -y rubygems
 66 [root@localhost bin]# cd /datas/soft/
 67 [root@localhost soft]# ll ruby-2.4.5.tar.gz     // ruby最新版
 68 -rwxr-xr-x   1 root root 14232887 Oct 24 19:33 ruby-2.4.5.tar.gz
 69 [root@localhost soft]# tar -xzf ruby-2.4.5.tar.gz
 70 [root@localhost soft]# cd ruby-2.4.5
 71 [root@localhost ruby-2.4.5]# ./configure
 72 [root@localhost ruby-2.4.5]# make
 73 [root@localhost ruby-2.4.5]# make install
 74 [root@localhost ruby-2.4.5]# ruby -v
 75 ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux]
 76 [root@localhost ruby-2.4.5]# cd /datas/soft/redis5/bin/
 77 [root@localhost bin]# ruby redis-trib.rb create --replicas 1 127.0.0.1:30001 127.0.0.1:30002 127.0.0.1:30003 127.0.0.1:30004 127.0.0.1:30005 127.0.0.1:30006
 78 WARNING: redis-trib.rb is not longer available!
 79 You should use redis-cli instead.
 80 
 81 All commands and features belonging to redis-trib.rb have been moved
 82 to redis-cli.
 83 In order to use them you should call redis-cli with the --cluster
 84 option followed by the subcommand name, arguments and options.
 85 
 86 Use the following syntax:
 87 redis-cli --cluster SUBCOMMAND [ARGUMENTS] [OPTIONS]
 88 
 89 Example:
 90 redis-cli --cluster create 127.0.0.1:30001 127.0.0.1:30002 127.0.0.1:30003 127.0.0.1:30004 127.0.0.1:30005 127.0.0.1:30006 --cluster-replicas 1
 91 
 92 To get help about all subcommands, type:
 93 redis-cli --cluster help
 94 
 95 [root@localhost bin]# ./redis-cli --cluster create 127.0.0.1:30001 127.0.0.1:30002 127.0.0.1:30003 127.0.0.1:30004 127.0.0.1:30005 127.0.0.1:30006 --cluster-replicas 1
 96 >>> Performing hash slots allocation on 6 nodes...
 97 Master[0] -> Slots 0 - 5460
 98 Master[1] -> Slots 5461 - 10922
 99 Master[2] -> Slots 10923 - 16383
100 Adding replica 127.0.0.1:30004 to 127.0.0.1:30001
101 Adding replica 127.0.0.1:30005 to 127.0.0.1:30002
102 Adding replica 127.0.0.1:30006 to 127.0.0.1:30003
103 >>> Trying to optimize slaves allocation for anti-affinity
104 [WARNING] Some slaves are in the same host as their master
105 M: 0ef9bb46603bc2703e2f812316b2d17e4664a285 127.0.0.1:30001
106    slots:[0-5460] (5461 slots) master
107 M: 1cce19c5b8f58666199445ee858b0a699cf523f9 127.0.0.1:30002
108    slots:[5461-10922] (5462 slots) master
109 M: 040afde427d4df0738b4705006309fc171403613 127.0.0.1:30003
110    slots:[10923-16383] (5461 slots) master
111 S: 7bb7a15f22730493cd7c66954a39e4008788c879 127.0.0.1:30004
112    replicates 1cce19c5b8f58666199445ee858b0a699cf523f9
113 S: c08daea6c990cb2732d95ae03c201c94523c0eff 127.0.0.1:30005
114    replicates 040afde427d4df0738b4705006309fc171403613
115 S: 7acc8a1f489ec954f069f998792eea8982653e70 127.0.0.1:30006
116    replicates 0ef9bb46603bc2703e2f812316b2d17e4664a285
117 Can I set the above configuration? (type 'yes' to accept): yes
118 >>> Nodes configuration updated
119 >>> Assign a different config epoch to each node
120 >>> Sending CLUSTER MEET messages to join the cluster
121 Waiting for the cluster to join
122 ..
123 >>> Performing Cluster Check (using node 127.0.0.1:30001)
124 M: 0ef9bb46603bc2703e2f812316b2d17e4664a285 127.0.0.1:30001
125    slots:[0-5460] (5461 slots) master
126    1 additional replica(s)
127 S: 7bb7a15f22730493cd7c66954a39e4008788c879 127.0.0.1:30004
128    slots: (0 slots) slave
129    replicates 1cce19c5b8f58666199445ee858b0a699cf523f9
130 M: 1cce19c5b8f58666199445ee858b0a699cf523f9 127.0.0.1:30002
131    slots:[5461-10922] (5462 slots) master
132    1 additional replica(s)
133 S: 7acc8a1f489ec954f069f998792eea8982653e70 127.0.0.1:30006
134    slots: (0 slots) slave
135    replicates 0ef9bb46603bc2703e2f812316b2d17e4664a285
136 S: c08daea6c990cb2732d95ae03c201c94523c0eff 127.0.0.1:30005
137    slots: (0 slots) slave
138    replicates 040afde427d4df0738b4705006309fc171403613
139 M: 040afde427d4df0738b4705006309fc171403613 127.0.0.1:30003
140    slots:[10923-16383] (5461 slots) master
141    1 additional replica(s)
142 [OK] All nodes agree about slots configuration.
143 >>> Check for open slots...
144 >>> Check slots coverage...
145 [OK] All 16384 slots covered.
146 [root@localhost bin]# ./redis-cli -c -p 30001
147 127.0.0.1:30001> set a hahahaha30001
148 -> Redirected to slot [15495] located at 127.0.0.1:30003
149 OK
150 127.0.0.1:30003> get a
151 "hahahaha30001"
152 127.0.0.1:30003> 
153 [root@localhost bin]# ./redis-cli -c -p 30006
154 127.0.0.1:30006> get a
155 -> Redirected to slot [15495] located at 127.0.0.1:30003
156 "hahahaha30001"
157 127.0.0.1:30003>

參考資料

https://www.cnblogs.com/it-cen/p/4295984.html

https://blog.csdn.net/naixiyi/article/details/51346880

https://www.cnblogs.com/PatrickLiu/p/8458788.html

http://www.runoob.com/ruby/ruby-installation-unix.html

https://blog.csdn.net/vtopqx/article/details/50235737

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 那啥,半個月沒開電腦了,這幾天打開發現系統沒聲了 那咋辦呢,修一修唄 搜索了下問題,還挺簡單的 1 jiang@ryzen:~$ sudo apt install pavucontrol 打開 1 jiang@ryzen:~$ sudo pavucontrol 大概就是長這樣 基本上只要在 回放 和 ...
  • 出現問題: 最近打開系統之後沒聲兒,抽空解決以下,誰知道安裝的時候出現了這個問題,一看就是鎖被占了唄 直接重啟大法。。。。。不行,看來是鎖分配出問題了,找了個解鎖命令 不行,沒用。。。。 思考一下:這些被占用的目錄都是關於包安裝的,簡單的說,包安裝的第一步應該就是拿到目錄然後下載一些包的信息,然後下 ...
  • 1 前景回顧 1.1 進程調度 記憶體中保存了對每個進程的唯一描述, 並通過若幹結構與其他進程連接起來. 調度器 面對的情形就是這樣, 其任務是在程式之間共用CPU時間, 創造並行執行的錯覺, 該任務分為兩個不同的部分, 其中一個涉及 調度策略 , 另外一個涉及 上下文切換 . 內核必須提供一種方法, ...
  • mke2fs 在磁碟分區上創建ext2、ext3、ext4文件系統,預設情況下會創建ext2。此命令的適用範圍:RedHat、RHEL、Ubuntu、CentOS、SUSE、openSUSE、Fedora。 1、語法 mke2fs [選項] [設備] mke2fs [ -c | -l filenam ...
  • 1. 購買了VPS,CentOS系統,發現伺服器時間與北京時間往往不一致,存在時差。 2. 可以執行tzselect命令按提示更換時區,依次選擇5 Asia,9 China,1 Beijing Time。 3. 將 這行添加到/etc/profile(所有用戶生效)或者~/.bash_profile ...
  • 一。win10系統下c盤,program 文件下 軟體一般為32 或者 64位,但是現在win10系統有些C盤會顯示program x86 向這種情況的話我們的軟體預設安裝在這個盤的話可能會造成很多文件消失,但是功能依舊存在!!! 從文件所在位置可以看到安裝目錄部分文件,但是返回上一級則會消失(位數 ...
  • nbtstat -A ip 對方136到139其中一個埠開了的話,就可查看對方最近登陸的用戶名(03前的為用戶名)-註意:參數-A要大寫 tracert -參數 ip(或電腦名) 跟蹤路由(數據包),參數:“-w數字”用於設置超時間隔。 ping ip(或功能變數名稱) 向對方主機發送預設大小為32位元組 ...
  • 第1節 查看當前系統版本及內核 cat /etc/redhat-release (查看系統版本) CentOS Linux release 7.4.1708 (Core) uname -r (查看系統內核) 3.10.0-693.el7.x86_64 uname -a (查看當前操作系統) x86_ ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...