centos6.x redis-cluster叢集離線安裝

來源:互聯網
上載者:User

標籤:tool   三台   cluster   檔案   ref   查看   source   check   append   

一、環境準備:

系統OS: CentOS6.8叢集環境:三台主機9個節點軟體版本:redis-4.0.11.tar.gzredis cluster節點資訊:redis01172.16.8.13:7000172.16.8.13:7001172.16.8.13:7002redis02172.16.8.14:7003172.16.8.14:7004172.16.8.14:7005redis03172.16.8.15:7006172.16.8.15:7007172.16.8.15:7008

二、redis安裝及配置
安裝所需的包
#yum install -y gcc g++ make gcc-c++ kernel-devel automake autoconf libtool make wget tcl vim ruby rubygems unzip
yum -y install zlib zlib-devel openssl openssl-devel gcc gcc-c++

百度雲 連結:https://pan.baidu.com/s/1L9KdpWieYlr5K1qPRMuK_w 密碼:t8ru
離線安裝ruby
下載ruby-2.4.4並上傳至伺服器
https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.1.tar.gz
把包放到改目錄下
tar -xvf ruby-2.4.4.tar.gz?
cd ruby-2.4.4
./configure --prefix=/usr/local/ruby
echo $?
make && make install
echo "PATH=$PATH:/usr/local/ruby/bin" >> /etc/profile
source /etc/profile
which ruby
/usr/bin/ruby
rm -rf /usr/bin/ruby
ln -s /usr/local/ruby/bin/ruby /usr/bin/ruby

[[email protected] ruby-2.4.4]# ruby -v
ruby 2.4.4p296 (2018-03-28 revision 63013) [x86_64-linux]

離線安裝rubygems
下載rubygems-2.7.6.tgz並上傳至伺服器
https://rubygems.org/rubygems/rubygems-2.7.6.tgz
tar -xvf rubygems-2.7.6.tgz
chown -R root.root rubygems-2.7.6
mv rubygems-2.7.6 /usr/local/
cd /usr/local/rubygems-2.7.6/
ruby setup.rb?
echo "PATH=$PATH:/usr/local/rubygems-2.7.6" >> /etc/profile
source /etc/profile
查看目前的版本

[[email protected] tools]# gem -v2.7.6-------------------------------------------------------------------------------------------------------------------

離線配置rubygems的redisapi
下載redis的gem並上傳至伺服器
https://rubygems.org/downloads/redis-3.3.0.gem
下載新的版本
https://rubygems.org/downloads/redis-4.0.2.gem

gem install -l redis-3.3.0.gem

[[email protected] tools]# gem list redis*** LOCAL GEMS ***redis (3.3.0)如果安裝是舊的版本卸載gem uninstal redis

安裝

gem install -l redis-4.0.2.gem[[email protected] tools]# gem list redis*** LOCAL GEMS ***redis (4.0.2)

離線安裝tcl

下載tcl8並上傳至伺服器https://sourceforge.net/projects/tcl/files/Tcl/8.6.0/unzip tcl868-src.zip?cd tcl8.6.8/unix/./configure --prefix=/usr/local/tclecho $?makeecho $?make installecho $?make install-private-headersln -v -sf tclsh8.6 /usr/local/tcl/bin/tclshchmod -v 755 /usr/local/tcl/lib/libtcl8.6.soecho "PATH=$PATH:/usr/local/tcl/bin" >> /etc/profilesource /etc/profile

建立使用者

useradd qasuserecho devops | passwd --stdin qasuser

下載redis安裝包
http://download.redis.io/releases/redis-4.0.11.tar.gz

安裝及配置

tar -xvf redis-4.0.11.tar.gz -C /appchown -R qasuser.qasuser /app/redis-4.0.11cd /app/redis-4.0.11------------------------------------------------------------------------------------------------------------如果因為上次編譯失敗,有殘留的檔案,做法如下:[[email protected] redis-4.0.11]$make distclean------------------------------------------------------------------------------------------------------------
[[email protected] redis-4.0.11]$ make

查看是否編譯是否成功

[[email protected] redis-4.0.11]$ echo $?0

節點1上執行(172.16.8.13)

su - qasusermkdir /app/redis-4.0.11/redis-clustercd /app/redis-4.0.11/redis-clustermkdir {7000,7001,7002}cat <<EOF>./7000/redis.confport 7000bind 172.16.8.13daemonize yespidfile /var/run/redis_7000.pidcluster-enabled yescluster-config-file nodes_7000.confcluster-node-timeout 10100appendonly yesEOFcat <<EOF>./7001/redis.confport 7001bind 172.16.8.13daemonize yespidfile /var/run/redis_7001.pidcluster-enabled yescluster-config-file nodes_7001.confcluster-node-timeout 10100appendonly yesEOFcat <<EOF>./7002/redis.confport 7002bind 172.16.8.13daemonize yespidfile /var/run/redis_7002.pidcluster-enabled yescluster-config-file nodes_7002.confcluster-node-timeout 10100appendonly yesEOF
for((i=0;i<=2;i++)); do /app/redis-4.0.11/src/redis-server /app/redis-4.0.11/redis-cluster/700$i/redis.conf; done[email protected] redis-cluster]$ ps -ef | grep redis-serverqasuser ? ?9742 ? ? ?1 ?0 Sep04 ? ? ? ? ?00:02:51 /app/redis-4.0.11/src/redis-server 172.16.8.13:7000 [cluster] ? ? ? ? ? ? ? ? ? ??qasuser ? ?9747 ? ? ?1 ?0 Sep04 ? ? ? ? ?00:02:51 /app/redis-4.0.11/src/redis-server 172.16.8.13:7001 [cluster] ? ? ? ? ? ? ? ? ? ??qasuser ? ?9749 ? ? ?1 ?0 Sep04 ? ? ? ? ?00:02:51 /app/redis-4.0.11/src/redis-server 172.16.8.13:7002 [cluster] ? ? ? ? ? ? ? ? ? ??qasuser ?104976 104464 ?0 13:54 pts/1 ? ?00:00:00 grep redis-server

節點2上執行(172.16.8.14)

su - qasusermkdir /app/redis-4.0.11/redis-clustercd /app/redis-4.0.11/redis-clustermkdir {7003,7004,7005}cat <<EOF>./7003/redis.confport 7003bind 172.16.8.14daemonize yespidfile /var/run/redis_7003.pidcluster-enabled yescluster-config-file nodes_7003.confcluster-node-timeout 10100appendonly yesEOFcat <<EOF>./7004/redis.confport 7004bind 172.16.8.14daemonize yespidfile /var/run/redis_7004.pidcluster-enabled yescluster-config-file nodes_7004.confcluster-node-timeout 10100appendonly yesEOFcat <<EOF>./7005/redis.confport 7005bind 172.16.8.14daemonize yespidfile /var/run/redis_7005.pidcluster-enabled yescluster-config-file nodes_7005.confcluster-node-timeout 10100appendonly yesEOFfor((i=3;i<=5;i++)); do /app/redis-4.0.11/src/redis-server /app/redis-4.0.11/redis-cluster/700$i/redis.conf; done[[email protected]t redis-cluster]$ ps -ef | grep redis-serverqasuser ? 48130 ? ? ?1 ?0 11:20 ? ? ? ? ?00:00:18 /app/redis-4.0.11/src/redis-server 172.16.8.14:7003 [cluster] ? ? ? ? ? ? ? ? ? ??qasuser ? 48132 ? ? ?1 ?0 11:20 ? ? ? ? ?00:00:18 /app/redis-4.0.11/src/redis-server 172.16.8.14:7004 [cluster] ? ? ? ? ? ? ? ? ? ??qasuser ? 48134 ? ? ?1 ?0 11:20 ? ? ? ? ?00:00:18 /app/redis-4.0.11/src/redis-server 172.16.8.14:7005 [cluster] ? ? ? ? ? ? ? ? ? ??qasuser ? 48768 ?48593 ?0 13:56 pts/0 ? ?00:00:00 grep redis-server

節點3上執行(172.16.8.15)

su - qasusermkdir /app/redis-4.0.11/redis-clustercd /app/redis-4.0.11/redis-clustermkdir {7006,7007,7008}cat <<EOF>./7006/redis.confport 7006bind 172.16.8.15daemonize yespidfile /var/run/redis_7006.pidcluster-enabled yescluster-config-file nodes_7006.confcluster-node-timeout 10100appendonly yesEOFcat <<EOF>./7007/redis.confport 7007bind 172.16.8.15daemonize yespidfile /var/run/redis_7007.pidcluster-enabled yescluster-config-file nodes_7007.confcluster-node-timeout 10100appendonly yesEOFcat <<EOF>./7008/redis.confport 7008bind 172.16.8.15daemonize yespidfile /var/run/redis_7008.pidcluster-enabled yescluster-config-file nodes_7008.confcluster-node-timeout 10100appendonly yesEOFfor((i=6;i<=8;i++)); do /app/redis-4.0.11/src/redis-server /app/redis-4.0.11/redis-cluster/700$i/redis.conf; done[[email protected] redis-cluster]$ ps -ef | grep redis-serverqasuser ? 48101 ? ? ?1 ?0 11:24 ? ? ? ? ?00:00:18 /app/redis-4.0.11/src/redis-server 172.16.8.15:7006 [cluster] ? ? ? ? ? ? ? ? ? ??qasuser ? 48103 ? ? ?1 ?0 11:24 ? ? ? ? ?00:00:18 /app/redis-4.0.11/src/redis-server 172.16.8.15:7007 [cluster] ? ? ? ? ? ? ? ? ? ??qasuser ? 48105 ? ? ?1 ?0 11:24 ? ? ? ? ?00:00:18 /app/redis-4.0.11/src/redis-server 172.16.8.15:7008 [cluster] ? ? ? ? ? ? ? ? ? ??qasuser ? 48548 ?48361 ?0 13:57 pts/0 ? ?00:00:00 grep redis-server
redis.conf的配置說明:port 7000 ? ? ? ? ? ? ? ? ? ? ? ? ? ?配置叢集的連接埠,分別第一組7000、7001、7002,第一組7003、7004、7005,第一組7006、7007、7008bind 原生IP ? ? ? ? ? ? ? ? ? ? ? ?這裡的預設配置是127.0.0.1改為內網ip。daemonsize yes ? ? ? ? ? ? ? ? ? ? ? 允許redis在後台運行pidfile ?/var/run/redis_7000.pid ? ? 改成和連接埠一致cluster-enabled ?yes ? ? ? ? ? ? ? ? 開啟叢集 把注釋去掉cluster-config-file node_7000.conf ? 叢集的配置,和連接埠一致cluster-node-timeout ?15000 ? ? ? ? ?請求逾時,預設為15秒appendonly ?yes ? ? ? ? ? ? ? ? ? ? ?aof日誌開啟,有需要就開啟,每一次寫操作都會記錄一條日誌。

建立叢集

/app/redis-4.0.11/src/redis-trib.rb create --replicas 1 172.16.8.13:7000 172.16.8.13:7001 172.16.8.13:7002 172.16.8.14:7003 172.16.8.14:7004 172.16.8.14:7005 172.16.8.15:7006 172.16.8.15:7007 172.16.8.15:7008[[email protected] redis-cluster]$ /app/redis-4.0.11/src/redis-trib.rb create --replicas 1 172.16.8.13:7000 172.16.8.13:7001 172.16.8.13:7002 172.16.8.14:7003 172.16.8.14:7004 172.16.8.14:7005 172.16.8.15:7006 172.16.8.15:7007 172.16.8.15:7008>>> Creating cluster/usr/local/ruby/lib/ruby/gems/2.4.0/gems/redis-3.3.0/lib/redis/client.rb:459: warning: constant ::Fixnum is deprecated>>> Performing hash slots allocation on 9 nodes...Using 4 masters:172.16.8.13:7000172.16.8.14:7003172.16.8.15:7006172.16.8.13:7001Adding replica 172.16.8.15:7007 to 172.16.8.13:7000Adding replica 172.16.8.13:7002 to 172.16.8.14:7003Adding replica 172.16.8.14:7005 to 172.16.8.15:7006Adding replica 172.16.8.15:7008 to 172.16.8.13:7001Adding replica 172.16.8.14:7004 to 172.16.8.13:7000M: 6a4175a51250ed6a88b6caaf1667d055c6f226cd 172.16.8.13:7000? ?slots:0-4095 (4096 slots) masterM: 3eeeb535acd80c239a09797cad611cb51ef76845 172.16.8.13:7001? ?slots:12288-16383 (4096 slots) masterS: a63a2751d14ff5ba19bdb2ace3eab3a2617f0b87 172.16.8.13:7002? ?replicates ecd312c581df995c352c67fc89f8a72993109df4M: ecd312c581df995c352c67fc89f8a72993109df4 172.16.8.14:7003? ?slots:4096-8191 (4096 slots) masterS: b7e4c7cf7da64114967a8a69acaa3aa4f809173f 172.16.8.14:7004? ?replicates 6a4175a51250ed6a88b6caaf1667d055c6f226cdS: 9a5700fd232689579cb48f810162ed0a27c28948 172.16.8.14:7005? ?replicates 3f9239d43ad592947c7c842de7cce1814ab159d5M: 3f9239d43ad592947c7c842de7cce1814ab159d5 172.16.8.15:7006? ?slots:8192-12287 (4096 slots) masterS: a5ec006d814acce1bf18b77a767291f407fbb7fe 172.16.8.15:7007? ?replicates 6a4175a51250ed6a88b6caaf1667d055c6f226cdS: 95016481a4df1c9fbbc3c34e1e434627b266d144 172.16.8.15:7008? ?replicates 3eeeb535acd80c239a09797cad611cb51ef76845Can 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 clusterWaiting for the cluster to join........>>> Performing Cluster Check (using node 172.16.8.13:7000)M: 6a4175a51250ed6a88b6caaf1667d055c6f226cd 172.16.8.13:7000? ?slots:0-4095 (4096 slots) master? ?2 additional replica(s)M: 3f9239d43ad592947c7c842de7cce1814ab159d5 172.16.8.15:7006? ?slots:8192-12287 (4096 slots) master? ?1 additional replica(s)S: a63a2751d14ff5ba19bdb2ace3eab3a2617f0b87 172.16.8.13:7002? ?slots: (0 slots) slave? ?replicates ecd312c581df995c352c67fc89f8a72993109df4M: 3eeeb535acd80c239a09797cad611cb51ef76845 172.16.8.13:7001? ?slots:12288-16383 (4096 slots) master? ?1 additional replica(s)S: 95016481a4df1c9fbbc3c34e1e434627b266d144 172.16.8.15:7008? ?slots: (0 slots) slave? ?replicates 3eeeb535acd80c239a09797cad611cb51ef76845S: 9a5700fd232689579cb48f810162ed0a27c28948 172.16.8.14:7005? ?slots: (0 slots) slave? ?replicates 3f9239d43ad592947c7c842de7cce1814ab159d5S: b7e4c7cf7da64114967a8a69acaa3aa4f809173f 172.16.8.14:7004? ?slots: (0 slots) slave? ?replicates 6a4175a51250ed6a88b6caaf1667d055c6f226cdM: ecd312c581df995c352c67fc89f8a72993109df4 172.16.8.14:7003? ?slots:4096-8191 (4096 slots) master? ?1 additional replica(s)S: a5ec006d814acce1bf18b77a767291f407fbb7fe 172.16.8.15:7007? ?slots: (0 slots) slave? ?replicates 6a4175a51250ed6a88b6caaf1667d055c6f226cd[OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered.

叢集驗證

/app/redis-4.0.11/src/redis-cli -h 172.16.8.13 -c -p 7000[[email protected] ~]$ /app/redis-4.0.11/src/redis-cli -h 172.16.8.13 -c -p 7000172.16.8.14:7003> set name qas?OK172.16.8.14:7003> get name"qas"/app/redis-4.0.11/src/redis-cli -h 172.16.8.14 -c -p 7004[[email protected] redis-cluster]$ /app/redis-4.0.11/src/redis-cli -h 172.16.8.14 -c -p 7004172.16.8.14:7004> get name-> Redirected to slot [5798] located at 172.16.8.14:7003"qas"/app/redis-4.0.11/src/redis-cli -h 172.16.8.15 -c -p 7008[[email protected] redis-cluster]$ /app/redis-4.0.11/src/redis-cli -h 172.16.8.15 -c -p 7008172.16.8.15:7008> get name-> Redirected to slot [5798] located at 172.16.8.14:7003"qas"----------------------------------------------------------------------------------------------------------------------------/app/redis-4.0.11/src/redis-trib.rb check 172.16.8.13:7000[[email protected] ~]$ /app/redis-4.0.11/src/redis-trib.rb check 172.16.8.13:7000/usr/local/ruby/lib/ruby/gems/2.4.0/gems/redis-3.3.0/lib/redis/client.rb:459: warning: constant ::Fixnum is deprecated>>> Performing Cluster Check (using node 172.16.8.13:7000)M: 6a4175a51250ed6a88b6caaf1667d055c6f226cd 172.16.8.13:7000? ?slots:0-4095 (4096 slots) master? ?2 additional replica(s)M: 3f9239d43ad592947c7c842de7cce1814ab159d5 172.16.8.15:7006? ?slots:8192-12287 (4096 slots) master? ?1 additional replica(s)S: a63a2751d14ff5ba19bdb2ace3eab3a2617f0b87 172.16.8.13:7002? ?slots: (0 slots) slave? ?replicates ecd312c581df995c352c67fc89f8a72993109df4M: 3eeeb535acd80c239a09797cad611cb51ef76845 172.16.8.13:7001? ?slots:12288-16383 (4096 slots) master? ?1 additional replica(s)S: 95016481a4df1c9fbbc3c34e1e434627b266d144 172.16.8.15:7008? ?slots: (0 slots) slave? ?replicates 3eeeb535acd80c239a09797cad611cb51ef76845S: 9a5700fd232689579cb48f810162ed0a27c28948 172.16.8.14:7005? ?slots: (0 slots) slave? ?replicates 3f9239d43ad592947c7c842de7cce1814ab159d5S: b7e4c7cf7da64114967a8a69acaa3aa4f809173f 172.16.8.14:7004? ?slots: (0 slots) slave? ?replicates 6a4175a51250ed6a88b6caaf1667d055c6f226cdM: ecd312c581df995c352c67fc89f8a72993109df4 172.16.8.14:7003? ?slots:4096-8191 (4096 slots) master? ?1 additional replica(s)S: a5ec006d814acce1bf18b77a767291f407fbb7fe 172.16.8.15:7007? ?slots: (0 slots) slave? ?replicates 6a4175a51250ed6a88b6caaf1667d055c6f226cd[OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered.

列出叢集節點

/app/redis-4.0.11/src/redis-cli -h 172.16.8.13 -c -p 7000[[email protected] ~]$ /app/redis-4.0.11/src/redis-cli -h 172.16.8.13 -c -p 7000172.16.8.13:7000> cluster nodes3f9239d43ad592947c7c842de7cce1814ab159d5 172.16.8.15:[email protected] master - 0 1536205999000 7 connected 8192-12287a63a2751d14ff5ba19bdb2ace3eab3a2617f0b87 172.16.8.13:[email protected] slave ecd312c581df995c352c67fc89f8a72993109df4 0 1536205998105 4 connected3eeeb535acd80c239a09797cad611cb51ef76845 172.16.8.13:[email protected] master - 0 1536205999000 2 connected 12288-1638395016481a4df1c9fbbc3c34e1e434627b266d144 172.16.8.15:[email protected] slave 3eeeb535acd80c239a09797cad611cb51ef76845 0 1536205999000 9 connected9a5700fd232689579cb48f810162ed0a27c28948 172.16.8.14:[email protected] slave 3f9239d43ad592947c7c842de7cce1814ab159d5 0 1536206000136 7 connected6a4175a51250ed6a88b6caaf1667d055c6f226cd 172.16.8.13:[email protected] myself,master - 0 1536205997000 1 connected 0-4095b7e4c7cf7da64114967a8a69acaa3aa4f809173f 172.16.8.14:[email protected] slave 6a4175a51250ed6a88b6caaf1667d055c6f226cd 0 1536205999121 5 connectedecd312c581df995c352c67fc89f8a72993109df4 172.16.8.14:[email protected] master - 0 1536205997000 4 connected 4096-8191a5ec006d814acce1bf18b77a767291f407fbb7fe 172.16.8.15:[email protected] slave 6a4175a51250ed6a88b6caaf1667d055c6f226cd 0 1536206001139 8 connected

叢集資訊

172.16.8.13:7000> ?cluster infocluster_state:okcluster_slots_assigned:16384cluster_slots_ok:16384cluster_slots_pfail:0cluster_slots_fail:0cluster_known_nodes:9cluster_size:4cluster_current_epoch:9cluster_my_epoch:1cluster_stats_messages_ping_sent:1443cluster_stats_messages_pong_sent:1494cluster_stats_messages_sent:2937cluster_stats_messages_ping_received:1486cluster_stats_messages_pong_received:1443cluster_stats_messages_meet_received:8cluster_stats_messages_received:2937

關閉叢集
推薦做法:

[[email protected] redis-cluster]$ pkill redis[[email protected] redis-cluster]$ pkill redis[[email protected] redis-cluster]$ pkill redis

??
或者迴圈節點逐個關閉

[[email protected] redis-cluster]$ for((i=0;i<=2;i++)); do /app/redis-4.0.11/src/redis-cli -c -h 172.16.8.13 -p 700$i shutdown; done[[email protected] redis-cluster]$ for((i=3;i<=5;i++)); do /app/redis-4.0.11/src/redis-cli -c -h 172.16.8.14 -p 700$i shutdown; done[[email protected] redis-cluster]$ for((i=6;i<=8;i++)); do /app/redis-4.0.11/src/redis-cli -c -h 172.16.8.15 -p 700$i shutdown; done

問題解決:

/usr/local/ruby/lib/ruby/gems/2.4.0/gems/redis-3.3.0/lib/redis/client.rb:459: warning: constant ::Fixnum is deprecated是因為 版本過低導致 ?gem 升級redis-4.0.2.gem步驟如下:gem uninstal redisgem install -l redis-4.0.2.gem

centos6.x redis-cluster叢集離線安裝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.