redis-cluster无备节点,安装脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

 





以上是关于redis-cluster无备节点,安装脚本的主要内容,如果未能解决你的问题,请参考以下文章

Redis-cluster安装

redis-cluster安装配置

centos6.x redis-cluster集群离线安装

docker-compose搭建redis-cluster集群

redis集群

redis之cluster(集群)