redis快取伺服器叢集搭建
阿新 • • 發佈:2018-11-02
一、安裝redis
1.下載redis
[[email protected] ~]# wget http://download.redis.io/releases/redis-4.0.11.tar.gz
2.安裝編譯
[[email protected] ~]# tar xf redis-4.0.11.tar.gz -C /usr/local/ [[email protected] ~]# cd /usr/local/redis-4.0.11/ [[email protected] redis-4.0.11]# make [[email protected] local]# ln -s /usr/local/redis-4.0.11/ /usr/local/redis
3.建立目錄
[[email protected] ~]# mkdir /redis-server-cluster [[email protected] redis-server-cluster]# mkdir 700{0..5} [[email protected] redis-server-cluster]# cp /usr/local/redis/src/redis-server 7000/ [[email protected] redis-server-cluster]# cp /usr/local/redis/redis.conf 7000/ [[email protected]redis-server-cluster]# vim 7000/redis.conf port 7000 //每個節點的埠號 bind 10.30.162.73 //繫結的機器IP cluster-enabled yes //啟動叢集模式 cluster-config-file nodes-7001.conf cluster-node-timeout 5000 appendonly yes #將配置檔案拷貝到7000-7005,更改埠號,並且將cluster-config-file 更改 [[email protected] redis-server-cluster]# cp 7000/redis.conf 7001 7002 7003 7004 7005
4.啟動各個節點,並測試
[[email protected] redis-server-cluster]# ./7001/redis-server 7001/redis.conf & //每個節點都需要啟動
[[email protected] redis-server-cluster]# ps axu | grep redis root 21647 0.0 1.0 151456 10060 pts/1 Rl 14:44 0:00 ./7001/redis-server 10.30.162.75:7001 [cluster] root 21655 0.0 1.0 151456 10060 pts/1 Rl 14:44 0:00 ./7003/redis-server 10.30.162.75:7003 [cluster] root 21665 0.0 1.0 151456 10060 pts/1 Rl 14:44 0:00 ./7002/redis-server 10.30.162.75:7002 [cluster] root 21675 0.0 1.0 147360 10064 pts/1 Rl 14:45 0:00 ./7000/redis-server 10.30.162.75:7000 [cluster] root 21797 0.0 1.0 151456 10060 pts/1 Sl 14:47 0:00 ./7004/redis-server 10.30.162.75:7004 [cluster] root 21807 0.0 1.0 147360 10064 pts/1 Sl 14:47 0:00 ./7005/redis-server 10.30.162.75:7005 [cluster] root 21815 0.0 0.0 112704 968 pts/1 R+ 14:47 0:00 grep --color=auto redis
二、安裝Ruby
1.安裝基本包
[[email protected] ~]# yum -y install ruby
2.安裝redis的Ruby介面程式
[[email protected] ~]# gem install redis Fetching: redis-4.0.3.gem (100%) ERROR: Error installing redis: redis requires Ruby version >= 2.2.2. [[email protected] ~]# ruby -v ruby 2.0.0p648 (2015-12-16) [x86_64-linux] //當前版本為2.0.0,要成功安裝Ruby介面程式,版本要大於2.2.2 [[email protected] ~]# gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB [[email protected] ~]# curl -L get.rvm.io | bash -s stable [[email protected] ~]# find / -name rvm -print [[email protected] ~]# source /usr/local/rvm/scripts/rvm #刪除舊版本 [[email protected] ~]# rvm remove 2.0.0 #檢視rvm庫中ruby的版本 [[email protected] ~]# rvm list known [[email protected] ~]# rvm install 2.5.1 #檢視版本 [[email protected] ~]# ruby -v ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] #設定預設版本 [[email protected] ~]# rvm use 2.5.1 --default #再次安裝redis的Ruby介面程式 [[email protected] ~]# gem install redis [[email protected] src]# ./redis-trib.rb create --replicas 1 10.30.162.73:7000 10.30.162.73:7001 10.30.162.73:7002 10.30.162.73:7003 10.30.162.73:7004 10.30.162.73:7005 "出現下述即成功" [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.
3.測試
[[email protected] src]# ./redis-cli -h 10.30.162.73 -p 7001 10.30.162.73: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:2 cluster_stats_messages_ping_sent:283 cluster_stats_messages_pong_sent:286 cluster_stats_messages_meet_sent:2 cluster_stats_messages_sent:571 cluster_stats_messages_ping_received:283 cluster_stats_messages_pong_received:285 cluster_stats_messages_meet_received:3 cluster_stats_messages_received:571 10.30.162.73:7001> cluster node (error) ERR Wrong CLUSTER subcommand or number of arguments 10.30.162.73:7001> cluster nodes 6df6da2e003bcc5c76455d6f8d335f49cf910524 10.30.162.73:[email protected] slave 1626d805cb2a4c9a1561743fcda33ce6f84674b8 0 1541141615000 6 connected 4a4f8b6e6bddc0840527f488088736c9bc4b07e8 10.30.162.73:[email protected] slave cc37a7951e8a8be9d2d23d2325564d3b9ed439c0 0 1541141615448 4 connected 1626d805cb2a4c9a1561743fcda33ce6f84674b8 10.30.162.73:[email protected] master - 0 1541141616455 3 connected 10923-16383 891b582ecd16e542b9ce3f243b51eddd84b61eae 10.30.162.73:[email protected] myself,master - 0 1541141614000 2 connected 5461-10922 cc37a7951e8a8be9d2d23d2325564d3b9ed439c0 10.30.162.73:[email protected] master - 0 1541141615549 1 connected 0-5460 2e019cbeb4fd91b965e2dc7d07bf7a4f2e78f596 10.30.162.73:[email protected] slave 891b582ecd16e542b9ce3f243b51eddd84b61eae 0 1541141615000 5 connected