redisshell

每次创建redis主从和哨兵服务,文件夹要复制好几个,配置文件改一大堆.繁琐还容易出错,就想通过shell脚本自动帮我配置好端口以及文件,下面就是脚本内容:

redis-tool.sh

#!/bin/bash
redis_port=6379
sentinel_port=26379
ip=127.0.0.1 function config()
{
rm -rf $1
cp -rf $2 $1
cd $1
touch $1.conf
echo "$3" > $1.conf
cd ../
} function cre_redis_conf()
{
redis_conf="
# 启动端口
port ${redis_port}
# 守护进程模式
daemonize yes
#关闭保护模式
protected-mode no
"
config redis-${redis_port} $1 "${redis_conf}"
} function cre_sentinel_conf()
{
sentinel_conf="
#sentinel端口
port ${sentinel_port}
#工作路径,注意路径不要和主重复
dir `pwd`/sentinel-${sentinel_port}
# 守护进程模式
daemonize yes
#关闭保护模式
protected-mode no
# 指明日志文件名
logfile ./sentinel-${sentinel_port}.log
#哨兵监控的master,主从配置一样,这里只用输入redis主节点的ip/port和法定人数。
sentinel monitor mymaster ${ip} 6379 1
# master或slave多长时间(默认30秒)不能使用后标记为s_down状态。
sentinel down-after-milliseconds mymaster 3000
#若sentinel在该配置值内未能完成failover操作(即故障时master/slave自动切换),则认为本次failover失败。
sentinel failover-timeout mymaster 18000
#设置master和slaves验证密码
sentinel auth-pass mymaster 123456
#指定了在执行故障转移时, 最多可以有多少个从服务器同时对新的主服务器进行同步
sentinel parallel-syncs mymaster 1
"
config sentinel-${sentinel_port} $1 "${sentinel_conf}"
} function init()
{
echo "redis文件夹名称:"
read path
echo "创建redis服务数:"
read num
echo "ip地址:"
read local_ip
ip=$local_ip
for((i=0;i<$num;i++));
do
cre_redis_conf $path
cre_sentinel_conf $path
((redis_port++))
((sentinel_port++))
done
echo "创建完成!"
}
init
# init 4 redis-3.5.2

使用时

  1. 将脚本放在编译完成后的redis文件夹的同级目录中

chmod +x redis-tool.sh授权为可执行文件

  1. 执行脚本依次输入redis文件夹/需要多少个服务/本机ip
./redis-tool.sh
redis文件夹名称:
redis-3.2.8
创建redis服务数:
3
ip地址:
192.168.37.220
创建完成!

文件夹目录如下:

生成文件详情:

停止redis集群脚本

#!/bin/bash
pid_name="redis"
echo "杀死的进程名称:" $pid_name pids=$(ps -ef|grep $pid_name|grep -v grep|awk '{print $2}') echo "pid列表:" $pids #反转字符串
reversal_str=''
for word in $pids
do
reversal_str="$word $reversal_str"
done #循环杀死pid
for item in $reversal_str
do
echo "杀死进程pid=" $item
kill -9 $item
done

最新文章

  1. Eclipse 导入外部项目无法识别为web项目并且无法在部署到tomcat下
  2. Processing Images
  3. pelican-python install
  4. Linux文件描述符与打开文件之间的区别(转载)
  5. (转)SoftReference
  6. Arcgis Desktop 9.3 安装
  7. Android_通过ContentObserver监听短信数据变化
  8. IT行业,需要经常锻炼,开篇从本钱开始
  9. C编译: makefile基础
  10. java工厂设计模式初步
  11. ECMAScript简介以及es6新增语法
  12. 【BZOJ】1969: [Ahoi2005]LANE 航线规划
  13. 基于.NET平台的Ocelot网关框架教程汇总
  14. 手把手设计MyBatis
  15. 作为JavaScript开发人员,这些必备的VS Code插件你都用过吗?
  16. Asp.Net WebApi 使用OWIN架构后,出现 “没有 OWIN 身份验证管理器与此请求相关联(No OWIN authentication manager is associated with the request)” 异常的解决办法
  17. springMVC--annotation
  18. RabbitMQ和kafka从几个角度简单的对比
  19. window无法启动mongodb服务:系统找不到指定的文件错误的解决方法
  20. wpgcms---碎片管理的使用

热门文章

  1. opencv源码学习: getGaussianKernel( 高斯核);
  2. opencv: 排序
  3. 【 强大的Mac/iOS开发工具】AppCode for Mac 2017.3
  4. 【.NET】using 语句中使用的类型必须可隐式转换为&quot;System.IDisposable&quot;
  5. 【JS】JS格式化文件大小 单位:Bytes、KB、MB、GB
  6. Java 微信公众号迁移
  7. Hadoop记录-NameNode优化
  8. VirtualBox下安装Ubuntu Server 16.04
  9. linux 内核模块makefile通用模板
  10. elasticsearch 通过HTTP RESTful API 操作数据