1. 程式人生 > >新菜,redis叢集安裝,單機,6節點,3主3從

新菜,redis叢集安裝,單機,6節點,3主3從

# 2、解壓、編譯、安裝
# 編譯需要用到gcc,自己可用:rpm -qa | grep gcc ,檢視是否安裝gcc,沒有自行百度補腦
# 解壓
tar -zxvf redis-3.0.0.tar.gz -C /usr/local/
# 重新命名(如果嫌名字太長,可重新命名,我這裡就改一下)
mv /usr/local/redis-3.0.0 /usr/local/redis3.0
cd /usr/local/redis3.0

# 編譯
make
# 未make install時,/usr/local/redis3.0/src/目錄下沒有redis-cli、redis-server 等啟動指令碼
cd /usr/local/redis3.0/src/
# 安裝
make install

# 是否安裝成功,可觀察/usr/local/redis3.0/src/目錄下redis-cli、redis-server 等指令碼

# 3、為了方便操作,同時不影響原始檔,這裡進行以下操作
mkdir -p /usr/local/redis/bin
mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server /usr/local/redis/bin

# 4、建立redis-cluster資料夾,並在下面建立6個資料夾(一般叢集最少6個,3主3從)
mkdir -p /usr/local/redis-cluster
cd /usr/local/redis-cluster
mkdir 7001 7002 7003 7004 7005 7006


# 5、將/usr/local/redis3.0/redis.conf配置檔案分別copy到700*檔案下,分別進行修改
cp /usr/local/redis3.0/redis.conf /usr/local/redis-cluster/7001
vi /usr/local/redis-cluster/7001/redis.conf

# 修改如下,#後面為說明,不用加:
daemonize yes                                      # 後臺啟動
port 7001                                             # 埠
bind 192.168.18.133                              
# 伺服器IP
dir /usr/local/redis-cluster/7001/      # 資料存放位置,每個節點路徑不一樣
cluster-enabled yes                              # 啟動叢集模式
cluster-config-file nodes-7001.conf     # 名稱最好與埠一致
cluster-node-timeout 5000                  # 5000毫秒
appendonly yes                                    

# 其他700*資料夾,可簡單操作,sed不懂可自行百度補腦
sed 's/7001/7002/g' /usr/local/redis-cluster/7001/redis.conf > /usr/local/redis-cluster/7002/redis.conf
sed 's/7001/7003/g' /usr/local/redis-cluster/7001/redis.conf > /usr/local/redis-cluster/7003/redis.conf
sed 's/7001/7004/g' /usr/local/redis-cluster/7001/redis.conf > /usr/local/redis-cluster/7004/redis.conf
sed 's/7001/7005/g' /usr/local/redis-cluster/7001/redis.conf > /usr/local/redis-cluster/7005/redis.conf
sed 's/7001/7006/g' /usr/local/redis-cluster/7001/redis.conf > /usr/local/redis-cluster/7006/redis.conf

# 6、由於redis使用到ruby命令,先需安裝ruby
yum install ruby             # 存在依賴,按y
yum install rubygems     # 存在依賴,按y
gem install redis            # 安裝redis和ruby介面

# yum安裝能不成功需要手動下載,FTP手動上傳,本地yum可自行百度補腦
# gem官網可能被防,在天朝,你懂的,以下是下載地址
# https://rubygems.global.ssl.fastly.net/gems/redis-3.2.1.gem
# yum install -l ./redis-3.2.1.gem

# 7、啟動6個redis
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/7001/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/7002/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/7003/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/7004/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/7005/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/7006/redis.conf


# 檢視是否啟動完成
ps -ef | grep redis