溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

怎樣進行redis環境搭建

發布時間:2021-10-29 09:31:52 來源:億速云 閱讀:132 作者:柒染 欄目:編程語言

怎樣進行redis環境搭建,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

因為工作環境中有redis,所以對redis進行了學習,當然首先就是從搭建環境開始,下面是我對于搭建redis環境的記錄。

系統是SuSE 11 sp2,

軟件環境如下所示:

linux-svnfile:/home/apps/redis # ls

redis-3.0.0.gem     ruby-1.9.2-p290.tar.gz  zlib-1.2.7.tar.gz

redis-3.0.0.tar.gz  rubygems-2.4.6.tgz

redis.conf          zlib-1.2.6.tar.gz

安裝基礎環境:

linux-svnfile:/home/apps/redis # tar -zxf zlib-1.2.6.tar.gz -C /usr/local/src

linux-svnfile:/usr/local/src/zlib-1.2.6 # ./configure --prefix=/usr/local/zlib

linux-svnfile:/usr/local/src/zlib-1.2.6 # make && make install

linux-svnfile:/home/apps/redis # tar -zxf ruby-1.9.2-p290.tar.gz -C /usr/local/src

linux-svnfile:/usr/local/src/ruby-1.9.2-p290 # ./configure --prefix=/usr/local/ruby

linux-svnfile:/usr/local/src/ruby-1.9.2-p290 # make && make install

linux-svnfile:/usr/local/ruby # ln -s /usr/local/ruby/bin/ruby /usr/local/bin

linux-svnfile:/home/apps/redis # tar xf rubygems-2.4.6.tgz -C /usr/local/src

linux-svnfile:/usr/local/src # mv rubygems-2.4.6 ../gem

linux-svnfile:/usr/local/gem # ruby setup.rb

linux-svnfile:/usr/local/gem # cp bin/gem /usr/local/bin/

linux-svnfile:/home/apps/redis # gem install -l redis-3.0.0.gem 

Successfully installed redis-3.0.0

Installing ri documentation for redis-3.0.0

Done installing documentation for redis after 0 seconds

1 gem installed

linux-svnfile:/home/apps/redis # tar -zxf redis-3.0.0.tar.gz -C /usr/local/src

linux-svnfile:/usr/local/src # mv redis-3.0.0 ../redis

linux-svnfile:/usr/local/redis # make

至此基礎環境搭建完成

下面進行集群的搭建

linux-svnfile:/usr/local/redis # cp src/redis-server /usr/local/bin/

linux-svnfile:/usr/local/redis # cp src/redis-cli /usr/local/bin/

linux-svnfile:/usr/local/redis # cp src/redis-trib.rb /usr/local/bin

linux-svnfile:/usr/local/redis # mkdir -p /usr/local/cluster/{7000..7005}

linux-svnfile:/usr/local/redis # vi redis.conf

daemonize yes

port 7000

cluster-enabled yes

cluster-config-file nodes.conf

cluster-node-timeout 5000

appendonly yes

linux-svnfile:/usr/local/redis # cp redis.conf ../cluster/7000

linux-svnfile:/usr/local/redis # cp redis.conf ../cluster/7001

linux-svnfile:/usr/local/redis # cp redis.conf ../cluster/7002

linux-svnfile:/usr/local/redis # cp redis.conf ../cluster/7003

linux-svnfile:/usr/local/redis # cp redis.conf ../cluster/7004

linux-svnfile:/usr/local/redis # cp redis.conf ../cluster/7005

這里需要注意的是文件名對應文件里端口的配置,例如7001文件下的port參數需要改為7001,其他一樣做修改。

linux-svnfile:/usr/local/redis # redis-server ../cluster/7000/redis.conf 

linux-svnfile:/usr/local/redis # redis-server ../cluster/7001/redis.conf 

linux-svnfile:/usr/local/redis # redis-server ../cluster/7002/redis.conf 

linux-svnfile:/usr/local/redis # redis-server ../cluster/7003/redis.conf 

linux-svnfile:/usr/local/redis # redis-server ../cluster/7004/redis.conf 

linux-svnfile:/usr/local/redis # redis-server ../cluster/7005/redis.conf 

linux-svnfile:/usr/local/redis # ps -ef | grep redis

root     15590     1  0 18:52 ?        00:00:00 redis-server *:7000 [cluster]    

linux-svnfile:/usr/local/redis # redis-trib.rb create --replicas 1 127.0.0.1:7000 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

>>> Creating cluster

Connecting to node 127.0.0.1:7000: OK

Connecting to node 127.0.0.1:7001: [ERR] Sorry, can't connect to node 127.0.0.1:7001

You have new mail in /var/mail/root

linux-svnfile:/usr/local/cluster/7000 # redis-server redis.conf 

linux-svnfile:/usr/local/cluster/7000 # cd ../7001

linux-svnfile:/usr/local/cluster/7001 # redis-server redis.conf 

linux-svnfile:/usr/local/cluster/7001 # cd ../7002

linux-svnfile:/usr/local/cluster/7002 # redis-server redis.conf 

linux-svnfile:/usr/local/cluster/7002 # cd ../7003

linux-svnfile:/usr/local/cluster/7003 # redis-server redis.conf 

linux-svnfile:/usr/local/cluster/7003 # cd ../7004

linux-svnfile:/usr/local/cluster/7004 # redis-server redis.conf 

linux-svnfile:/usr/local/cluster/7004 # cd ../7005

linux-svnfile:/usr/local/cluster/7005 # redis-server redis.conf 

linux-svnfile:/usr/local/cluster/7005 # ps -ef | grep redis

root     17575     1  0 20:05 ?        00:00:00 redis-server *:7000 [cluster]

root     17590     1  0 20:06 ?        00:00:00 redis-server *:7001 [cluster]

root     17604     1  0 20:06 ?        00:00:00 redis-server *:7002 [cluster]

root     17612     1  0 20:06 ?        00:00:00 redis-server *:7003 [cluster]

root     17616     1  0 20:06 ?        00:00:00 redis-server *:7004 [cluster]

root     17624     1  0 20:06 ?        00:00:00 redis-server *:7005 [cluster]

像是上面在啟動服務時需要注意切換到相應的配置文件的目錄下,不然相應端口的服務無法啟動,例如我之前在/usr/local/redis目錄下啟動后只有7000對應的服務啟動了。

linux-svnfile:/usr/local/redis # redis-server ../cluster/7000/redis.conf 

linux-svnfile:/usr/local/redis # redis-server ../cluster/7001/redis.conf 

linux-svnfile:/usr/local/redis # redis-server ../cluster/7002/redis.conf 

linux-svnfile:/usr/local/redis # redis-server ../cluster/7003/redis.conf 

linux-svnfile:/usr/local/redis # redis-server ../cluster/7004/redis.conf 

linux-svnfile:/usr/local/redis # redis-server ../cluster/7005/redis.conf 

linux-svnfile:/usr/local/redis # ps -ef | grep redis

root     15144 19064  0 18:37 pts/0    00:00:00 vi redis.conf

root     15590     1  0 18:52 ?        00:00:00 redis-server *:7000 [cluster]          

root     15616 19443  0 18:52 pts/1    00:00:00 grep redis

怎樣進行redis環境搭建

怎樣進行redis環境搭建

linux-svnfile:/usr/local/cluster #redis-cli -p 7000

127.0.0.1:7000>

怎樣進行redis環境搭建

怎樣進行redis環境搭建

刪除slave節點

怎樣進行redis環境搭建

怎樣進行redis環境搭建

刪除master節點

linux-svnfile:/usr/local/redis # redis-trib.rb reshard 127.0.0.1:7001

How many slots do you want to move (from 1 to 16384)? 5461 

What is the receiving node ID? 42929649e533ec8aad7cbb81f204f04c849d4bff

Please enter all the source node IDs.  

  Type 'all' to use all the nodes as source nodes for the hash slots.  

  Type 'done' once you entered all the source nodes IDs.  

Source node #1: 6fe9561e605b7ee85e67a2557f7fb641f482afb4 

Source node #2:done  

#Do you want to proceed with the proposed reshard plan (yes/no)? yes  

說明:

5461表示要刪除master所有的slot數量

What is the receiving node ID是指將7000的slot遷移的節點7001的node-id

Source node #1是指要刪除的master的node-id

下面可以看到7000的slot為0,而7001多了4561

怎樣進行redis環境搭建

在刪除master節點出現如下面所示的錯誤,是因為刪除master節點之前沒有刪除master節點的slave節點。

怎樣進行redis環境搭建

上面是在單臺機器上做的集群,下面展示兩臺機器上做集群,其實也很簡單。

參考之前的環境編譯源碼到另一臺機器

在兩臺機器上編輯配置文件

/usr/local/redis # vi redis.conf

daemonize yes

port 7000

cluster-enabled yes

cluster-config-file nodes.conf

cluster-node-timeout 5000

appendonly yes

cluster-config-file nodes-7001.conf

分別創建目錄和文件

linux-svnfile:/usr/local/redis # mkdir -p/usr/local/cluster/{7001..7003}

localhost:/usr/local/redis # mkdir -p/usr/local/cluster/{8001..8003}

linux-svnfile:/usr/local/redis # cpredis.conf ../cluster/7001

linux-svnfile:/usr/local/redis # cpredis.conf ../cluster/7002

linux-svnfile:/usr/local/redis # cpredis.conf ../cluster/7003

localhost:/usr/local/redis # cp redis.conf../cluster/8001

localhost:/usr/local/redis # cp redis.conf../cluster/8002

localhost:/usr/local/redis # cp redis.conf../cluster/8003

修改對應目錄的配置文件其中port 和cluster-config-file分別對應各自的目錄名,可使用sed命令做修改

sed -i "s/7001/7002/g"

啟動服務

怎樣進行redis環境搭建

怎樣進行redis環境搭建

怎樣進行redis環境搭建

怎樣進行redis環境搭建

怎樣進行redis環境搭建

關于怎樣進行redis環境搭建問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業資訊頻道了解更多相關知識。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女