1. 程式人生 > >redis-cluster無備節點,安裝指令碼

redis-cluster無備節點,安裝指令碼

#!/bin/bash

#安裝gcc
yum -y install gcc
#安裝RVM所需的程式包
yum -y install gcc-c++ patch readline readline-devel zlib zlib-devel
yum -y install libyaml-devel libffi-devel openssl-devel make
yum -y install bzip2 autoconf automake libtool bison iconv-devel sqlite-devel
#安裝RVM
curl -sSL https://rvm.io/mpapis.asc | gpg --import -
curl -L get.rvm.io | bash -s stable #設定RVM環境 source /etc/profile.d/rvm.sh rvm reload #驗證依賴 rvm requirements run #安裝ruby rvm install 2.2.4 rvm use 2.2.4 --default ruby --version cd /usr/local/src #下載redis curl http://download.redis.io/releases/redis-4.0.9.tar.gz -o redis-4.0.9.tar.gz tar -zxvf redis-4.0.9.tar.gz cd redis
-4.0.9 #curl http://download.redis.io/releases/redis-3.2.8.tar.gz -o redis-3.2.8.tar.gz #tar -zxvf redis-3.2.8.tar.gz #cd redis-3.2.8 #安裝到指定目錄中(make 報錯請 make MALLOC=libc) make MALLOC=libc PREFIX=/usr/local/redis install cp src/redis-trib.rb /usr/local/redis/bin/ #配置環境變數 echo 'export PATH="$PATH:/usr/local/redis/bin"
' >> /etc/profile tail -1 /etc/profile . /etc/profile yum -y install ruby-devel rubygems rpm-build #gem這個命令來安裝redis介面 gem install redis #建立需要資料夾 mkdir -p /usr/local/redis/{etc,data,logs} mkdir -p /usr/local/redis/data/{6379,7379,8379} #拷貝配置檔案、啟動項檔案 cp redis.conf /usr/local/redis/etc/6379.conf cp utils/redis_init_script /etc/init.d/redis_6379 #redis配置檔案 cd /usr/local/redis/etc #後臺執行 sed -i 's/daemonize no/daemonize yes/' 6379.conf #日誌檔案地址 sed -i 's/logfile ""/logfile \/usr\/local\/redis\/logs\/redis_6379.log/' 6379.conf #資料檔案地址 sed -i 's/dir .\//dir \/usr\/local\/redis\/data\/6379/' 6379.conf #192.168.1.100 為當前機器IP sed -i 's/bind 127.0.0.1/bind 192.168.100.146 127.0.0.1/' 6379.conf #開啟cluster sed -i 's/# cluster-enabled yes/cluster-enabled yes/' 6379.conf sed -i 's/# cluster-config-file nodes-6379.conf/cluster-config-file \/usr\/local\/redis\/etc\/nodes-6379.conf/' 6379.conf sed -i 's/# cluster-node-timeout 15000/cluster-node-timeout 3000/' 6379.conf sed -i 's/appendonly no/appendonly yes/' 6379.conf cp 6379.conf 7379.conf sed -i 's/6379/7379/' 7379.conf cp 6379.conf 8379.conf sed -i 's/6379/8379/' 8379.conf #redis啟動項 cd /etc/init.d #sed '2c # chkconfig: 2345 90 10' 6379.conf #多行用\n sed '1a 第一\n第二' ab sed -i '1a # chkconfig: 2345 90 10' redis_6379 sed -i 's/\/usr\/local\/bin/\/usr\/local\/redis\/bin/' redis_6379 sed -i 's/\/etc\/redis/\/usr\/local\/redis\/etc/' redis_6379 cp redis_6379 redis_7379 sed -i 's/6379/7379/' redis_7379 cp redis_6379 redis_8379 sed -i 's/6379/8379/' redis_8379 #新增啟動項 chkconfig --list chkconfig redis_6379 on chkconfig redis_7379 on chkconfig redis_8379 on chkconfig --list service redis_6379 start service redis_7379 start service redis_8379 start echo 'cluster 配置' redis-trib.rb create --replicas 0 192.168.1.100:6379 192.168.1.100:7379 192.168.1.100:8379


#StackExchange.Redis連線redis-cluster版本
#https://github.com/StackExchange/StackExchange.Redis/issues/672