Chinaunix首页 | 论坛 | 博客
  • 博客访问: 61352
  • 博文数量: 8
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 60
  • 用 户 组: 普通用户
  • 注册时间: 2014-09-02 11:26
文章分类

全部博文(8)

文章存档

2015年(3)

2014年(5)

我的朋友

分类: LINUX

2015-07-02 12:08:06

#!/usr/bin/env bash
# des: install redis cluster
# name: install_redis_cluster.sh
TAR_HOME=/usr/local/src
TAR_BAR="redis-3.0.2.tar.gz"
cd $TAR_HOME
yum -y install ruby rubygems
# gem安装redis组件
# 官方地址  可能需要翻墙才能下载;或者直接gem install redis;不过gem的官方源也可能用不了
curl 172.16.35.138/package/redis/redis-3.2.1.gem.tar.gz -O
tar zxf redis-3.2.1.gem.tar.gz
gem install -l redis-3.2.1.gem
#
if [ ! -e "${TAR_BAR}" ]
then
    curl -O 172.16.35.138/package/redis/${TAR_BAR}
fi
#
tar zxf ${TAR_BAR}
cd redis-3.0.2
make
if [ $? -ne 0 ]
then
    exit  1
fi
cd ..
#
mv redis-3.0.2 /home/redis-cluster
cd /home/redis-cluster
mkdir -p 707{1,2,3}/{conf,aof,logs}
mkdir /var/run/redis
mkdir bin/
find src/ -perm 755 -exec cp -rf {} bin/ \;
cp src/redis-trib.rb bin/

# 01
cp redis.conf 7071/conf/
sed -i '/^daemonize/s/no/yes/' 7071/conf/redis.conf
sed -i '/^timeout/s/0/300/' 7071/conf/redis.conf
sed -i '/^port/s/6379/7071/g' 7071/conf/redis.conf
sed -i '/^pidfile/s/^/#/;/^#pidfile/a\pidfile /var/run/redis/7071.pid' 7071/conf/redis.conf
sed -i '/logfile/s#'\"\"'#"/home/redis-cluster/7071/logs/7071.log"#' 7071/conf/redis.conf
sed -i '/^dir/s#.*#dir /home/redis-cluster/7071/aof/#' 7071/conf/redis.conf
# cluster 
sed -i '/cluster-enabled/s/^#//' 7071/conf/redis.conf
sed -i '/cluster-config-file/a\cluster-config-file /home/redis-cluster/7071/conf/nodes-7071.conf' 7071/conf/redis.conf
sed -i '/cluster-node-timeout/a\cluster-node-timeout 5000' 7071/conf/redis.conf
sed -i '/^appendonly/s/no/yes/' 7071/conf/redis.conf

# 02
cp redis.conf 7072/conf/
sed -i '/^daemonize/s/no/yes/' 7072/conf/redis.conf
sed -i '/^timeout/s/0/300/' 7072/conf/redis.conf
sed -i '/^port/s/6379/7072/g' 7072/conf/redis.conf
sed -i '/^pidfile/s/^/#/;/^#pidfile/a\pidfile /var/run/redis/7072.pid' 7072/conf/redis.conf
sed -i '/logfile/s#'\"\"'#"/home/redis-cluster/7072/logs/7072.log"#' 7072/conf/redis.conf
sed -i '/^dir/s#.*#dir /home/redis-cluster/7072/aof/#' 7072/conf/redis.conf
# cluster 
sed -i '/cluster-enabled/s/^#//' 7072/conf/redis.conf
sed -i '/cluster-config-file/a\cluster-config-file /home/redis-cluster/7072/conf/nodes-7072.conf' 7072/conf/redis.conf
sed -i '/cluster-node-timeout/a\cluster-node-timeout 5000' 7072/conf/redis.conf
sed -i '/^appendonly/s/no/yes/' 7072/conf/redis.conf

# 03
cp redis.conf 7073/conf/
sed -i '/^daemonize/s/no/yes/' 7073/conf/redis.conf
sed -i '/^timeout/s/0/300/' 7073/conf/redis.conf
sed -i '/^port/s/6379/7073/g' 7073/conf/redis.conf
sed -i '/^pidfile/s/^/#/;/^#pidfile/a\pidfile /var/run/redis/7073.pid' 7073/conf/redis.conf
sed -i '/logfile/s#'\"\"'#"/home/redis-cluster/7073/logs/7073.log"#' 7073/conf/redis.conf
sed -i '/^dir/s#.*#dir /home/redis-cluster/7073/aof/#' 7073/conf/redis.conf
#cluster 
sed -i '/cluster-enabled/s/^#//' 7073/conf/redis.conf
sed -i '/cluster-config-file/a\cluster-config-file /home/redis-cluster/7073/conf/nodes-7073.conf' 7073/conf/redis.conf
sed -i '/cluster-node-timeout/a\cluster-node-timeout 5000' 7073/conf/redis.conf
sed -i '/^appendonly/s/no/yes/' 7073/conf/redis.conf


#启动服务
/home/redis-cluster/bin/redis-server /home/redis-cluster/7071/conf/redis.conf 
/home/redis-cluster/bin/redis-server /home/redis-cluster/7072/conf/redis.conf 
/home/redis-cluster/bin/redis-server /home/redis-cluster/7073/conf/redis.conf 


# 下面需要手动操作
# 创建集群操作,添加主节点
redis-trib.rb create --replicas 0 172.16.35.102:7071 172.16.35.136:7071 172.16.35.152:7071

#为集群中的主节点添加从节点 
redis-trib.rb add-node --slave --master-id d7d09fd3290bb06386347e5f755cd16750628aab 172.16.35.136:7072 172.16.35.102:7071

#   添加从节点
redis-trib.rb add-node --slave --master-id d7d09fd3290bb06386347e5f755cd16750628aab 172.16.35.152:7073 172.16.35.102:7071

redis-trib.rb add-node --slave --master-id a5cb9f8c3ac90fdb62e1ba6a1369b39ada74830a 172.16.35.152:7072 172.16.35.136:7071

redis-trib.rb add-node --slave --master-id a5cb9f8c3ac90fdb62e1ba6a1369b39ada74830a 172.16.35.102:7073 172.16.35.136:7071

redis-trib.rb add-node --slave --master-id b7dc70b86afe2b96f9f769b9509ff66c3c83c9d5 172.16.35.102:7072 172.16.35.152:7071

redis-trib.rb add-node --slave --master-id b7dc70b86afe2b96f9f769b9509ff66c3c83c9d5 172.16.35.136:7073 172.16.35.152:7071


阅读(1797) | 评论(0) | 转发(0) |
0

上一篇:linux下ulimit命令详解

下一篇:mongodb cluster

给主人留下些什么吧!~~