要配置Redis集群的自啟動,可以按照以下步驟進(jìn)行操作:
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
mkdir /etc/redis
cp redis.conf /etc/redis/redis-7000.conf
cp redis.conf /etc/redis/redis-7001.conf
cp redis.conf /etc/redis/redis-7002.conf
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
其中,cluster-enabled
設(shè)置為yes
啟用集群模式,cluster-config-file
指定集群配置文件的路徑和名稱,cluster-node-timeout
設(shè)置節(jié)點(diǎn)之間的超時(shí)時(shí)間。
/etc/init.d/
目錄下創(chuàng)建一個(gè)啟動腳本,例如redis-cluster
,并添加以下內(nèi)容:#!/bin/sh
# chkconfig: 2345 90 10
# description: Redis cluster startup script
REDIS_HOME=/usr/local/redis
CONF_DIR=/etc/redis
PORTS="7000 7001 7002"
case "$1" in
start)
for port in $PORTS; do
$REDIS_HOME/src/redis-server $CONF_DIR/redis-$port.conf
done
;;
stop)
for port in $PORTS; do
$REDIS_HOME/src/redis-cli -p $port shutdown
done
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac
exit 0
chmod +x /etc/init.d/redis-cluster
chkconfig --add redis-cluster
service redis-cluster start
現(xiàn)在,Redis集群將會在系統(tǒng)啟動時(shí)自動啟動??梢允褂靡韵旅顏頇z查Redis集群的運(yùn)行狀態(tài):
redis-cli -c -p 7000 cluster nodes
注意:在配置自啟動之前,請確保已經(jīng)正確配置了Redis集群,并且節(jié)點(diǎn)之間能夠正常通信。