摘要:前言記得年方二八時候,數(shù)數(shù)還是數(shù)得過來的,如今年逾二十八,數(shù)都數(shù)不清了,前幾天在狗東哪里整了算法導論概率導論兩本教科書看看學學,也好在研究機器學習的時候有解惑的根本。
前言
記得年方二八時候,數(shù)數(shù)還是數(shù)得過來的,如今年逾二十八,數(shù)都數(shù)不清了,前幾天在狗東哪里整了《算法導論》、《概率導論》兩本教科書看看學學,也好在研究機器學習的時候有解惑的根本。redis-cluster正好成功的引起了我的興趣,就當著等書之前的休閑折騰
redis早前沒有現(xiàn)成的集群模塊,如今流行起來了,功能也越來越強大了,下面我就來部署一下,當然這中間也會遇到很多問題的。不過沒關(guān)系,有問題咱們解決即可
手動部署根據(jù)官網(wǎng)介紹,手動部署集群需要進行一下操作
cd /usr/local/redis mkdir -p cluster/7000 cp ./etc/redis.conf cluster/7000 vi cluster/7000/redis.conf
這里我們針對關(guān)鍵的地方修改即可,具體情況如下
port 7000 cluster-enabled yes cluster-config-file nodes-7000.conf cluster-node-timeout 5000 appendonly yes
修改完成后,復制
cp -r cluster/7000 cluster/7001 cp -r cluster/7000 cluster/7002 cp -r cluster/7000 cluster/7003 cp -r cluster/7000 cluster/7004 cp -r cluster/7000 cluster/7005
然后依次修改每個節(jié)點配置文件的端口號,修改好配置,最后啟動所有的節(jié)點
redis-server cluster/7000/redis.conf redis-server cluster/7001/redis.conf redis-server cluster/7002/redis.conf redis-server cluster/7003/redis.conf redis-server cluster/7004/redis.conf redis-server cluster/7005/redis.conf
這個時候雖然所有節(jié)點啟動了,但是還不能稱之為集群。下面我們要使用ruby的輔助工具redis-trib來將所有的節(jié)點聯(lián)系起來,這個工具就是我們的redis安裝源文件的src目錄下的redis-trib.rb文件,但是這個文件運行需要ruby版redis的驅(qū)動
yum install ruby gem install redis
安裝失敗,redis依賴的ruby版本必須要大于2.2.0,下面我們來手動安裝ruby2.4.2
先清理yum安裝的ruby
yum remove ruby
下面通過RVM(Ruby Version Manager)來安裝ruby
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E37D2BAF1CF37B13E2069D6956105BD0E739499BDB curl -sSL https://get.rvm.io | bash -s stable rvm install 2.4.2 gem install redis
安裝成功后
./src/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自動部署
以上是手動創(chuàng)建集群的方法,下面還有自動啟動節(jié)點,創(chuàng)建集群,停止集群的服務,文件在redis安裝目錄下,為utils/create-cluster/create-cluster
cp utils/create-cluster/create-cluster /etc/init.d/create-cluster vi /etc/init.d/create-cluster
修改PROT并添加ROOT=/usr/local/redis
#!/bin/bash # Settings PORT=6999 TIMEOUT=2000 NODES=6 REPLICAS=1 ROOT=/usr/local/redis # You may want to put the above config parameters into config.sh in order to # override the defaults without modifying this script. if [ -a config.sh ] then source "config.sh" fi # Computed vars ENDPORT=$((PORT+NODES)) if [ "$1" == "start" ] then while [ $((PORT < ENDPORT)) != "0" ]; do PORT=$((PORT+1)) echo "Starting $PORT" $ROOT/bin/redis-server --port $PORT --cluster-enabled yes --cluster-config-file nodes-${PORT}.conf --cluster-node-timeout $TIMEOUT --appendonly yes --appendfilename appendonly-${PORT}.aof --dbfilename dump-${PORT}.rdb --logfile ${PORT}.log --daemonize yes done exit 0 fi if [ "$1" == "create" ] then HOSTS="" while [ $((PORT < ENDPORT)) != "0" ]; do PORT=$((PORT+1)) HOSTS="$HOSTS 127.0.0.1:$PORT" done $ROOT/src/redis-trib.rb create --replicas $REPLICAS $HOSTS exit 0 fi if [ "$1" == "stop" ] then while [ $((PORT < ENDPORT)) != "0" ]; do PORT=$((PORT+1)) echo "Stopping $PORT" $ROOT/bin/redis-cli -p $PORT shutdown nosave done exit 0 fi if [ "$1" == "watch" ] then PORT=$((PORT+1)) while [ 1 ]; do clear date $ROOT/bin/redis-cli -p $PORT cluster nodes | head -30 sleep 1 done exit 0 fi if [ "$1" == "tail" ] then INSTANCE=$2 PORT=$((PORT+INSTANCE)) tail -f ${PORT}.log exit 0 fi if [ "$1" == "call" ] then while [ $((PORT < ENDPORT)) != "0" ]; do PORT=$((PORT+1)) $ROOT/bin/redis-cli -p $PORT $2 $3 $4 $5 $6 $7 $8 $9 done exit 0 fi if [ "$1" == "clean" ] then rm -rf *.log rm -rf appendonly*.aof rm -rf dump*.rdb rm -rf nodes*.conf exit 0 fi if [ "$1" == "clean-logs" ] then rm -rf *.log exit 0 fi echo "Usage: $0 [start|create|stop|watch|tail|clean]" echo "start -- Launch Redis Cluster instances." echo "create -- Create a cluster using redis-trib create." echo "stop -- Stop Redis Cluster instances." echo "watch -- Show CLUSTER NODES output (first 30 lines) of first node." echo "tail-- Run tail -f of instance at base port + ID." echo "clean -- Remove all instances data, logs, configs." echo "clean-logs -- Remove just instances logs."
啟動節(jié)點,創(chuàng)建集群就可以用一下命令來實現(xiàn)了
service create-cluster start service create-cluster create
停止集群
service create-cluster stop
還有watch、tail、clean、clean-logs命令,這里就不一一說明了,這個教程就寫到這吧
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://www.ezyhdfw.cn/yun/17656.html
摘要:上一篇文章已經(jīng)把單機版的搭建的過程介紹完了,接下來介紹集群版的搭建方法。搭建成功,下面這個圖片主要是講述了,誰誰誰分配了什么槽,占用了那些節(jié)點。終于把集群搭建好了,下面讓我們一起進行測試一下。 ##### 上一篇文章已經(jīng)把單機版的Redis搭建的過程介紹完了,接下來介紹Redis集群版的搭建方法。 首先我們回到local目錄在這個目錄里面創(chuàng)建一個redis-cluster目錄:mkdi...
摘要:綱要集群介紹集群搭建集群介紹額,這塊還是不廢話了看官網(wǎng)吧說的很清楚。 綱要: redis3.0集群介紹 redis3.0集群搭建 redis集群介紹 額,這塊還是不廢話了,看官網(wǎng)吧,說的很清楚。 redis集群搭建 下載并解壓redis安裝包: wget http://download.redis.io/rele... tar zxf redis-3.2.9.tar.gz && ...
閱讀 1771·2021-11-18 10:02
閱讀 1880·2021-09-04 16:40
閱讀 3401·2021-09-01 10:48
閱讀 1011·2019-08-30 15:55
閱讀 2035·2019-08-30 15:55
閱讀 1518·2019-08-30 13:05
閱讀 3173·2019-08-30 12:52
閱讀 1745·2019-08-30 11:24