摘要:前言記得年方二八時(shí)候,數(shù)數(shù)還是數(shù)得過來的,如今年逾二十八,數(shù)都數(shù)不清了,前幾天在狗東哪里整了算法導(dǎo)論概率導(dǎo)論兩本教科書看看學(xué)學(xué),也好在研究機(jī)器學(xué)習(xí)的時(shí)候有解惑的根本。
前言
記得年方二八時(shí)候,數(shù)數(shù)還是數(shù)得過來的,如今年逾二十八,數(shù)都數(shù)不清了,前幾天在狗東哪里整了《算法導(dǎo)論》、《概率導(dǎo)論》兩本教科書看看學(xué)學(xué),也好在研究機(jī)器學(xué)習(xí)的時(shí)候有解惑的根本。redis-cluster正好成功的引起了我的興趣,就當(dāng)著等書之前的休閑折騰
redis早前沒有現(xiàn)成的集群模塊,如今流行起來了,功能也越來越強(qiáng)大了,下面我就來部署一下,當(dāng)然這中間也會(huì)遇到很多問題的。不過沒關(guān)系,有問題咱們解決即可
手動(dòng)部署根據(jù)官網(wǎng)介紹,手動(dòng)部署集群需要進(jìn)行一下操作
cd /usr/local/redis mkdir -p cluster/7000 cp ./etc/redis.conf cluster/7000 vi cluster/7000/redis.conf
這里我們針對(duì)關(guān)鍵的地方修改即可,具體情況如下
port 7000 cluster-enabled yes cluster-config-file nodes-7000.conf cluster-node-timeout 5000 appendonly yes
修改完成后,復(fù)制
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
然后依次修改每個(gè)節(jié)點(diǎn)配置文件的端口號(hào),修改好配置,最后啟動(dòng)所有的節(jié)點(diǎn)
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
這個(gè)時(shí)候雖然所有節(jié)點(diǎn)啟動(dòng)了,但是還不能稱之為集群。下面我們要使用ruby的輔助工具redis-trib來將所有的節(jié)點(diǎn)聯(lián)系起來,這個(gè)工具就是我們的redis安裝源文件的src目錄下的redis-trib.rb文件,但是這個(gè)文件運(yùn)行需要ruby版redis的驅(qū)動(dòng)
yum install ruby gem install redis
安裝失敗,redis依賴的ruby版本必須要大于2.2.0,下面我們來手動(dòng)安裝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自動(dòng)部署
以上是手動(dòng)創(chuàng)建集群的方法,下面還有自動(dòng)啟動(dòng)節(jié)點(diǎn),創(chuàng)建集群,停止集群的服務(wù),文件在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."
啟動(dòng)節(jié)點(diǎn),創(chuàng)建集群就可以用一下命令來實(shí)現(xiàn)了
service create-cluster start service create-cluster create
停止集群
service create-cluster stop
還有watch、tail、clean、clean-logs命令,這里就不一一說明了,這個(gè)教程就寫到這吧
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://specialneedsforspecialkids.com/yun/17656.html
摘要:上一篇文章已經(jīng)把單機(jī)版的搭建的過程介紹完了,接下來介紹集群版的搭建方法。搭建成功,下面這個(gè)圖片主要是講述了,誰誰誰分配了什么槽,占用了那些節(jié)點(diǎn)。終于把集群搭建好了,下面讓我們一起進(jìn)行測(cè)試一下。 ##### 上一篇文章已經(jīng)把單機(jī)版的Redis搭建的過程介紹完了,接下來介紹Redis集群版的搭建方法。 首先我們回到local目錄在這個(gè)目錄里面創(chuàng)建一個(gè)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 && ...
閱讀 1523·2021-11-18 10:02
閱讀 1666·2021-09-04 16:40
閱讀 3175·2021-09-01 10:48
閱讀 876·2019-08-30 15:55
閱讀 1854·2019-08-30 15:55
閱讀 1372·2019-08-30 13:05
閱讀 3016·2019-08-30 12:52
閱讀 1628·2019-08-30 11:24