您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關Linux CentOS 下安裝版本 Redis 5.x 聚群操作手冊 Red Hat Enterprise Linux Server release 7.1的示例分析 ,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
安裝環境
序號 項目 值 1 OS版本 Red Hat Enterprise Linux Server release 7.1 (Maipo) 2 內核版本 3.10.0-229.el7.x86_64 3 Redis redis-5.0.4 4 Ruby ruby 2.3.4p301 (2017-03-30 revision 58214) [x86_64-linux] 節點信息規劃 本來只準備部署7001-7006 6個實例,但是redis集群提示最少需要3個主節點,6個節點才能完成啟動,所以后面2個是后來加的。 注意:這里因為是測試環境,所以將所有實例都放在了一臺機器上,生產建議主備節點不要放在一臺機器上 序號 IP地址 端口 主備 節點配置文件 1 192.168.9.216 7001 主 /data/program/redis/etc/redis-7001.conf 2 192.168.9.216 7002 主 /data/program/redis/etc/redis-7002.conf 3 192.168.9.216 7003 主 /data/program/redis/etc/redis-7003.conf 4 192.168.9.216 7004 備 /data/program/redis/etc/redis-7004.conf 5 192.168.9.216 7005 備 /data/program/redis/etc/redis-7005.conf 6 192.168.9.216 7006 備 /data/program/redis/etc/redis-7006.conf 一、下載對應的redis 安裝包,并且解壓和安裝 [root@elk01 opt]# wget http://download.redis.io/releases/redis-5.0.4.tar.gz --2017-10-26 09:33:23-- http://download.redis.io/releases/redis-5.0.4.tar.gz Resolving download.redis.io (download.redis.io)... 109.74.203.151 Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 1711660 (1.6M) [application/x-gzip] Saving to: ‘redis-5.0.4.tar.gz’ 100%[======================================================>] 1,711,660 426KB/s in 3.9s 2017-10-26 09:33:28 (426 KB/s) - ‘redis-5.0.4.tar.gz’ saved [1711660/1711660] [root@elk01 program]# ll redis-5.0.4.tar.gz -rw-r--r-- 1 root root 1711660 Jul 24 21:59 redis-5.0.4.tar.gz [root@CentOS program]# mv redis-5.0.4 redis 二、創建對應的需要目錄; [root@elk01 program]# cd redis [suven@CentOS redis]$ ll total 268 -rw-rw-r--. 1 suven suven 99445 Mar 18 12:21 00-RELEASENOTES -rw-rw-r--. 1 suven suven 53 Mar 18 12:21 BUGS -rw-rw-r--. 1 suven suven 1894 Mar 18 12:21 CONTRIBUTING -rw-rw-r--. 1 suven suven 1487 Mar 18 12:21 COPYING drwxr-xr-x. 8 root root 4096 Mar 26 00:01 data drwxrwxr-x. 6 suven suven 4096 Mar 25 23:12 deps drwxr-xr-x. 2 root root 4096 Mar 25 23:57 etc -rw-rw-r--. 1 suven suven 11 Mar 18 12:21 INSTALL drwxr-xr-x. 2 root root 4096 Mar 26 00:02 logs -rw-rw-r--. 1 suven suven 151 Mar 18 12:21 Makefile -rw-rw-r--. 1 suven suven 4223 Mar 18 12:21 MANIFESTO -rw-rw-r--. 1 suven suven 20555 Mar 18 12:21 README.md -rw-rw-r--. 1 suven suven 62155 Mar 18 12:21 redis.conf -rwxrwxr-x. 1 suven suven 275 Mar 18 12:21 runtest -rwxrwxr-x. 1 suven suven 280 Mar 18 12:21 runtest-cluster -rwxrwxr-x. 1 suven suven 281 Mar 18 12:21 runtest-sentinel -rw-rw-r--. 1 suven suven 9710 Mar 18 12:21 sentinel.conf drwxrwxr-x. 3 suven suven 4096 Mar 25 23:45 src -rw-r--r--. 1 root root 0 Mar 25 23:59 stdout drwxrwxr-x. 10 suven suven 4096 Mar 18 12:21 tests drwxrwxr-x. 8 suven suven 4096 Mar 18 12:21 utils 三、創建目錄腳本如下: [root@CentOS redis]# mkdir -p /data/program/redis/etc [root@CentOS redis]# mkdir -p /data/program/redis/logs [root@CentOS redis]# mkdir -p /data/program/redis/run [root@CentOS redis]# mkdir -p /data/program/redis/data [root@CentOS redis]# mkdir -p /data/program/redis/data/{7001,7002,7003,7004,7005,7006} 四、上傳配置文件到創建的etc目錄上,執行修改腳本: (1).修改配置ip:將配置文件大寫的IP,轉換成對應的服務器ip地址(127.0.0.1),具體到把個配置文件 sed -i "s/IP/ 127.0.0.1" /data/program/redis/etc/redis-7001.conf 或(linux 正規匹配所有文件) sed -i "s/IP/ 127.0.0.1" /data/program/redis/etc/redis-700*.conf (2).修改配置文件PORT:將配置文件大寫的PORT,轉換成對應的redis啟動服務端口7001,具體到把個配置文件 sed -i "s/PORT/ 7001" /data/program/redis/etc/redis-7001.conf sed -i "s/PORT/ 7002" /data/program/redis/etc/redis-7002.conf sed -i "s/PORT/ 7003" /data/program/redis/etc/redis-7003.conf sed -i "s/PORT/ 7004" /data/program/redis/etc/redis-7004.conf sed -i "s/PORT/ 7005" /data/program/redis/etc/redis-7005.conf sed -i "s/PORT/ 7006" /data/program/redis/etc/redis-7006.conf 執行編譯安裝命令: make test [root@localhost redis]# make test cd src && make test make[1]: Entering directory `/data/program/redis/src 最后看到的結果: Hint: It's a good idea to run 'make test' ;) INSTALL install INSTALL install INSTALL install INSTALL install INSTALL install make[1]: Leaving directory `/data/program/redis/src' 備注:分分鐘搞定Redis編譯安裝 1. 依賴包安裝 yum -y install cpp binutils glibc glibc-kernheaders glibc-common glibc-devel gcc make gcc-c++ libstdc++-devel tcl 五、啟動redis結點服務命令: [root@CentOS redis] cd /data/program/redis/ [root@CentOS redis] src/redis-server etc/redis-7001.conf [root@CentOS redis] src/redis-server etc/redis-7002.conf [root@CentOS redis] src/redis-server etc/redis-7003.conf [root@CentOS redis] src/redis-server etc/redis-7004.conf [root@CentOS redis] src/redis-server etc/redis-7005.conf [root@CentOS redis] src/redis-server etc/redis-7006.conf 六、查看redis結點服務是否正常啟動: [suven@CentOS etc]$ ps -ef | grep redis root 7470 1 0 00:01 ? 00:00:14 /data/program/redis/src/redis-server 10.211.55.5:7001 [cluster] root 8377 1 0 00:01 ? 00:00:14 /data/program/redis/src/redis-server 10.211.55.5:7002 [cluster] root 8591 1 0 00:01 ? 00:00:14 /data/program/redis/src/redis-server 10.211.55.5:7003 [cluster] root 9597 1 0 00:02 ? 00:00:14 /data/program/redis/src/redis-server 10.211.55.5:7004 [cluster] root 9816 1 0 00:02 ? 00:00:14 /data/program/redis/src/redis-server 10.211.55.5:7005 [cluster] root 10031 1 0 00:02 ? 00:00:14 /data/program/redis/src/redis-server 10.211.55.5:7006 [cluster] suven 19158 9380 0 04:04 pts/0 00:00:00 grep --color=auto redis 注:如果沒有看到進程信息;請查看 [root@CentOS redis]$ tail -200f logs/redis7001.log 910:C 25 Mar 2019 23:59:35.959 # Can't chdir to '/data/program/redis/data/7001': No such file or directory 7469:C 26 Mar 2019 00:01:32.452 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 7469:C 26 Mar 2019 00:01:32.452 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=7469, just started 7469:C 26 Mar 2019 00:01:32.452 # Configuration loaded 7470:M 26 Mar 2019 00:01:32.454 * No cluster configuration found, I'm 63243f121eb2e90ea3da9d6c7931b577c313e1a0 7470:M 26 Mar 2019 00:01:32.456 * Running mode=cluster, port=7001. 7470:M 26 Mar 2019 00:01:32.456 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 7470:M 26 Mar 2019 00:01:32.456 # Server initialized 七、執行結點實現聚群腳本: [root@CentOS redis] src/redis-trib.rb create --replicas 1 10.211.55.5:7001 10.211.55.5:7002 10.211.55.5:7003 10.211.55.5:7004 10.211.55.5:7005 10.211.55.5:7006 src/redis-cli --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 --cluster-replicas 1 (1).注: 需要安裝ruby2.2.2以上版本,卸載老版本ruby2.0.0 [root@elk01 ~]# ruby -v ruby 2.0.0p648 (2015-12-16) [x86_64-linux] [root@elk01 ~]# rpm -qa | grep ruby ruby-libs-2.0.0.648-29.el7.x86_64 rubygem-bigdecimal-1.2.0-29.el7.x86_64 rubygems-2.0.14.1-29.el7.noarch rubygem-psych-2.0.0-29.el7.x86_64 rubygem-json-1.7.7-29.el7.x86_64 ruby-irb-2.0.0.648-29.el7.noarch rubygem-io-console-0.4.2-29.el7.x86_64 ruby-2.0.0.648-29.el7.x86_64 rubygem-rdoc-4.0.0-29.el7.noarch [root@elk01 ~]# yum erase ruby 注:如果還是舊片本,請參與centos7 rhel7安裝較高版本ruby2.2、2.3、2.4筆記執行 (2).查看ruby軟件版本號,如果低于ruby2.2,執行面刪除 ruby -v rpm -qa | grep ruby (3).重新安裝ruby2.4版本腳本 yum install -y gcc* openssl* wget yum install centos-release-scl-rh yum install rh-ruby24 -y scl enable rh-ruby24 bash (4).查看ruby軟件版本號 [root@localhost redis]# ruby -v ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux] [root@localhost redis]# yum install rubygems [root@localhost redis]# gem install redis 八、執行redis 結點聚群腳本;結果如下:其中會提示輸入(yes/no),輸入yes 即可; [root@CentOS redis]# redis-cli --cluster create 10.211.55.5:7001 10.211.55.5:7002 10.211.55.5:7003 10.211.55.5:7004 10.211.55.5:7005 10.211.55.5:7006 --cluster-replicas 1 >>> Performing hash slots allocation on 6 nodes... Master[0] -> Slots 0 - 5460 Master[1] -> Slots 5461 - 10922 Master[2] -> Slots 10923 - 16383 Adding replica 10.211.55.5:7005 to 10.211.55.5:7001 Adding replica 10.211.55.5:7006 to 10.211.55.5:7002 Adding replica 10.211.55.5:7004 to 10.211.55.5:7003 >>> Trying to optimize slaves allocation for anti-affinity [WARNING] Some slaves are in the same host as their master M: 63243f121eb2e90ea3da9d6c7931b577c313e1a0 10.211.55.5:7001 slots:[0-5460] (5461 slots) master M: 53692efbc07d2279f267dbba441a06121ea1042f 10.211.55.5:7002 slots:[5461-10922] (5462 slots) master M: 4665614f463a77ee12f9afd680e96b7af69c9889 10.211.55.5:7003 slots:[10923-16383] (5461 slots) master S: baa658b4068c5125057e885ead90c985c308b9ae 10.211.55.5:7004 replicates 53692efbc07d2279f267dbba441a06121ea1042f S: 1a30085728c4d20c7528be2a2faa8d769b5456d1 10.211.55.5:7005 replicates 4665614f463a77ee12f9afd680e96b7af69c9889 S: e3e9c6e39f9969cc202cd90f045c2acb6b12b427 10.211.55.5:7006 replicates 63243f121eb2e90ea3da9d6c7931b577c313e1a0 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 10.211.55.5:7001) M: 63243f121eb2e90ea3da9d6c7931b577c313e1a0 10.211.55.5:7001 slots:[0-5460] (5461 slots) master 1 additional replica(s) S: e3e9c6e39f9969cc202cd90f045c2acb6b12b427 10.211.55.5:7006 slots: (0 slots) slave replicates 63243f121eb2e90ea3da9d6c7931b577c313e1a0 M: 4665614f463a77ee12f9afd680e96b7af69c9889 10.211.55.5:7003 slots:[10923-16383] (5461 slots) master 1 additional replica(s) M: 53692efbc07d2279f267dbba441a06121ea1042f 10.211.55.5:7002 slots:[5461-10922] (5462 slots) master 1 additional replica(s) S: 1a30085728c4d20c7528be2a2faa8d769b5456d1 10.211.55.5:7005 slots: (0 slots) slave replicates 4665614f463a77ee12f9afd680e96b7af69c9889 S: baa658b4068c5125057e885ead90c985c308b9ae 10.211.55.5:7004 slots: (0 slots) slave replicates 53692efbc07d2279f267dbba441a06121ea1042f [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. 九、連接到對應的redis 聚群腳本: 一定要 -c [root@CentOS redis]# src/redis-cli -c -h 10.211.55.5 -p 7001 10.211.55.5:7001> 十、查看redis聚群信息命令:CLUSTER info 10.211.55.5:7001> CLUSTER info cluster_state:ok cluster_slots_assigned:16384 cluster_slots_ok:16384 cluster_slots_pfail:0 cluster_slots_fail:0 cluster_known_nodes:6 cluster_size:3 cluster_current_epoch:6 cluster_my_epoch:1 cluster_stats_messages_ping_sent:385 cluster_stats_messages_pong_sent:385 cluster_stats_messages_sent:770 cluster_stats_messages_ping_received:380 cluster_stats_messages_pong_received:385 cluster_stats_messages_meet_received:5 cluster_stats_messages_received:770 十一、查看redis聚群結點分配信息命令(CLUSTER 區分大小寫 ):CLUSTER nodes 10.211.55.5:7001> CLUSTER nodes e3e9c6e39f9969cc202cd90f045c2acb6b12b427 10.211.55.5:7006@17006 slave 63243f121eb2e90ea3da9d6c7931b577c313e1a0 0 1553588727578 6 connected 4665614f463a77ee12f9afd680e96b7af69c9889 10.211.55.5:7003@17003 master - 0 1553588728081 3 connected 10923-16383 53692efbc07d2279f267dbba441a06121ea1042f 10.211.55.5:7002@17002 master - 0 1553588726573 2 connected 5461-10922 1a30085728c4d20c7528be2a2faa8d769b5456d1 10.211.55.5:7005@17005 slave 4665614f463a77ee12f9afd680e96b7af69c9889 0 1553588726000 5 connected baa658b4068c5125057e885ead90c985c308b9ae 10.211.55.5:7004@17004 slave 53692efbc07d2279f267dbba441a06121ea1042f 0 1553588728000 4 connected 63243f121eb2e90ea3da9d6c7931b577c313e1a0 10.211.55.5:7001@17001 myself,master - 0 1553588727000 1 connected 0-5460 10.211.55.5:7001> 十二、驗證是否可用,測試用例 10.211.55.5:7001> set keytest testvalue OK 10.211.55.5:7001> get keytest "testvalue" 10.211.55.5:7001> CLUSTER INFO 打印集群的信息 CLUSTER NODES 列出集群當前已知的所有節點(node),以及這些節點的相關信息。 //節點 CLUSTER MEET <ip> <port> 將 ip 和 port 所指定的節點添加到集群當中,讓它成為集群的一份子。 CLUSTER FORGET <node_id> 從集群中移除 node_id 指定的節點。 CLUSTER REPLICATE <node_id> 將當前節點設置為 node_id 指定的節點的從節點。 CLUSTER SAVECONFIG 將節點的配置文件保存到硬盤里面。 CLUSTER ADDSLOTS <slot> [slot ...] 將一個或多個槽(slot)指派(assign)給當前節點。 CLUSTER DELSLOTS <slot> [slot ...] 移除一個或多個槽對當前節點的指派。 CLUSTER FLUSHSLOTS 移除指派給當前節點的所有槽,讓當前節點變成一個沒有指派任何槽的節點。 CLUSTER SETSLOT <slot> NODE <node_id> 將槽 slot 指派給 node_id 指定的節點。 CLUSTER SETSLOT <slot> MIGRATING <node_id> 將本節點的槽 slot 遷移到 node_id 指定的節點中。 CLUSTER SETSLOT <slot> IMPORTING <node_id> 從 node_id 指定的節點中導入槽 slot 到本節點。 CLUSTER SETSLOT <slot> STABLE 取消對槽 slot 的導入(import)或者遷移(migrate)。 //鍵 CLUSTER KEYSLOT <key> 計算鍵 key 應該被放置在哪個槽上。 CLUSTER COUNTKEYSINSLOT <slot> 返回槽 slot 目前包含的鍵值對數量。 CLUSTER GETKEYSINSLOT <slot> <count> 返回 count 個 slot 槽中的鍵。 //新增 CLUSTER SLAVES node-id 返回一個master節點的slaves 列表
以上就是Linux CentOS 下安裝版本 Redis 5.x 聚群操作手冊 Red Hat Enterprise Linux Server release 7.1的示例分析,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。