本篇文章給大家分享的是有關(guān)Linux CentOS 下安裝版本 redis 5.x 聚群操作手冊(cè) Red Hat Enterprise Linux Server release 7.1的示例分析 ,小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
成都創(chuàng)新互聯(lián)公司是專業(yè)的和碩網(wǎng)站建設(shè)公司,和碩接單;提供成都做網(wǎng)站、網(wǎng)站設(shè)計(jì)、外貿(mào)營(yíng)銷網(wǎng)站建設(shè),網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行和碩網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!
安裝環(huán)境
序號(hào) 項(xiàng)目 值 1 OS版本 Red Hat Enterprise Linux Server release 7.1 (Maipo) 2 內(nèi)核版本 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] 節(jié)點(diǎn)信息規(guī)劃 本來只準(zhǔn)備部署7001-7006 6個(gè)實(shí)例,但是redis集群提示最少需要3個(gè)主節(jié)點(diǎn),6個(gè)節(jié)點(diǎn)才能完成啟動(dòng),所以后面2個(gè)是后來加的。 注意:這里因?yàn)槭菧y(cè)試環(huán)境,所以將所有實(shí)例都放在了一臺(tái)機(jī)器上,生產(chǎn)建議主備節(jié)點(diǎn)不要放在一臺(tái)機(jī)器上 序號(hào) IP地址 端口 主備 節(jié)點(diǎn)配置文件 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 一、下載對(duì)應(yīng)的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 二、創(chuàng)建對(duì)應(yīng)的需要目錄; [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 三、創(chuàng)建目錄腳本如下: [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} 四、上傳配置文件到創(chuàng)建的etc目錄上,執(zhí)行修改腳本: (1).修改配置ip:將配置文件大寫的IP,轉(zhuǎn)換成對(duì)應(yīng)的服務(wù)器ip地址(127.0.0.1),具體到把個(gè)配置文件 sed -i "s/IP/ 127.0.0.1" /data/program/redis/etc/redis-7001.conf 或(linux 正規(guī)匹配所有文件) sed -i "s/IP/ 127.0.0.1" /data/program/redis/etc/redis-700*.conf (2).修改配置文件PORT:將配置文件大寫的PORT,轉(zhuǎn)換成對(duì)應(yīng)的redis啟動(dòng)服務(wù)端口7001,具體到把個(gè)配置文件 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 執(zhí)行編譯安裝命令: make test [root@localhost redis]# make test cd src && make test make[1]: Entering directory `/data/program/redis/src 最后看到的結(jié)果: 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 五、啟動(dòng)redis結(jié)點(diǎn)服務(wù)命令: [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結(jié)點(diǎn)服務(wù)是否正常啟動(dòng): [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 注:如果沒有看到進(jìn)程信息;請(qǐng)查看 [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 七、執(zhí)行結(jié)點(diǎn)實(shí)現(xiàn)聚群腳本: [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 注:如果還是舊片本,請(qǐng)參與centos7 rhel7安裝較高版本ruby2.2、2.3、2.4筆記執(zhí)行 (2).查看ruby軟件版本號(hào),如果低于ruby2.2,執(zhí)行面刪除 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軟件版本號(hào) [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 八、執(zhí)行redis 結(jié)點(diǎn)聚群腳本;結(jié)果如下:其中會(huì)提示輸入(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. 九、連接到對(duì)應(yīng)的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聚群結(jié)點(diǎn)分配信息命令(CLUSTER 區(qū)分大小寫 ):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> 十二、驗(yàn)證是否可用,測(cè)試用例 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 列出集群當(dāng)前已知的所有節(jié)點(diǎn)(node),以及這些節(jié)點(diǎn)的相關(guān)信息。 //節(jié)點(diǎn) CLUSTER MEET將 ip 和 port 所指定的節(jié)點(diǎn)添加到集群當(dāng)中,讓它成為集群的一份子。 CLUSTER FORGET 從集群中移除 node_id 指定的節(jié)點(diǎn)。 CLUSTER REPLICATE 將當(dāng)前節(jié)點(diǎn)設(shè)置為 node_id 指定的節(jié)點(diǎn)的從節(jié)點(diǎn)。 CLUSTER SAVECONFIG 將節(jié)點(diǎn)的配置文件保存到硬盤里面。 CLUSTER ADDSLOTS [slot ...] 將一個(gè)或多個(gè)槽(slot)指派(assign)給當(dāng)前節(jié)點(diǎn)。 CLUSTER DELSLOTS [slot ...] 移除一個(gè)或多個(gè)槽對(duì)當(dāng)前節(jié)點(diǎn)的指派。 CLUSTER FLUSHSLOTS 移除指派給當(dāng)前節(jié)點(diǎn)的所有槽,讓當(dāng)前節(jié)點(diǎn)變成一個(gè)沒有指派任何槽的節(jié)點(diǎn)。 CLUSTER SETSLOT NODE 將槽 slot 指派給 node_id 指定的節(jié)點(diǎn)。 CLUSTER SETSLOT MIGRATING 將本節(jié)點(diǎn)的槽 slot 遷移到 node_id 指定的節(jié)點(diǎn)中。 CLUSTER SETSLOT IMPORTING 從 node_id 指定的節(jié)點(diǎn)中導(dǎo)入槽 slot 到本節(jié)點(diǎn)。 CLUSTER SETSLOT STABLE 取消對(duì)槽 slot 的導(dǎo)入(import)或者遷移(migrate)。 //鍵 CLUSTER KEYSLOT 計(jì)算鍵 key 應(yīng)該被放置在哪個(gè)槽上。 CLUSTER COUNTKEYSINSLOT 返回槽 slot 目前包含的鍵值對(duì)數(shù)量。 CLUSTER GETKEYSINSLOT 返回 count 個(gè) slot 槽中的鍵。 //新增 CLUSTER SLAVES node-id 返回一個(gè)master節(jié)點(diǎn)的slaves 列表
以上就是Linux CentOS 下安裝版本 Redis 5.x 聚群操作手冊(cè) Red Hat Enterprise Linux Server release 7.1的示例分析,小編相信有部分知識(shí)點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見到或用到的。希望你能通過這篇文章學(xué)到更多知識(shí)。更多詳情敬請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。