简介: 明天再写,上脚本

#!/bin/bash
#------------------------------------------------------------------------------------------------------------------#
#| Some people die at the age of 25 and don't bury themselves in the earth until they are 75 |#
#------------------------------------------------------------------------------------------------------------------#
#| $$$$ $$ $$ $$$$$$ $$ $$ $$$$$$ $$ $$$$$$ $$$$$$ |#
#| $$ $$ $$ $$ $$ $$ $$ $$ $$ $$ $$ |#
#| $$ $$$$$$$ $$$$$ $$ $$ $ $$ $$$$$$ $$ $$$$$ $$$$$ |#
#| $$ $$ $$ $$ $$ $ $ $$ $$ $$ $$ $$ |#
#| $$$$ $$ $$ $$$$$$ $$ $$ $$$$$ $$ $$$$$$ $$$$$$ $$$$$$ |#
#------------------------------------------------------------------------------------------------------------------#
onversion="4.0.3"
offversion=`basename redis-*.tar.gz .tar.gz | awk -F '-' '{print$2}'`
installdir=$(cd `dirname $0`; pwd)
cluster_name="redis-cluster"
port1="7001"
port2="7002"
confile1="redis-${port1}.conf"
confile2="redis-${port2}.conf"
nodes1="nodes-${port1}.conf"
nodes2="nodes-${port2}.conf"
logfile1="redis-${port1}.logs"
logfile2="redis-${port2}.logs" function initize(){
installdir=$(cd `dirname $0`; pwd)
} function checkroot(){
if [ $UID -ne 0 ]
then
echo "|----------------------------------------------------------------------------------------------------------------|"
echo "|------------------------------------------[权限不足...请切换至root用户]-----------------------------------------|"
echo "|----------------------------------------------------------------------------------------------------------------|"
exit;
fi
} function judge(){
echo
offfile=`ls | grep redis-*.tar.gz`
if [[ "$offfile" != "" ]]
then
echo "|----------------------------------------------------------------------------------------------------------------|"
echo "|--------------------------------------------------[发现离线包]--------------------------------------------------|"
echo "|----------------------------------------------------------------------------------------------------------------|"
/usr/bin/sleep 3
offinstall
else
echo "|----------------------------------------------------------------------------------------------------------------|"
echo "|-------------------------------------------------[未发现离线包]-------------------------------------------------|"
echo "|--------------------------------------------[开始判断是否连接外网安装]------------------------------------------|"
/usr/bin/sleep 3
network
fi
} function offinstall(){
echo "|----------------------------------------------------------------------------------------------------------------|"
echo "|--------------------------------------------------[离线包安装中]------------------------------------------------|"
echo "|----------------------------------------------------------------------------------------------------------------|"
tar -zxvf redis-${offversion}.tar.gz >/dev/null 2>&1
redis="redis-${offversion}"
cd ${redis}/src && make >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo "编译出错"
else
echo "|----------------------------------------------------------------------------------------------------------------|"
echo "|--------------------------------------------------[编译完成]----------------------------------------------------|"
echo "|----------------------------------------------------------------------------------------------------------------|"
/usr/bin/sleep 3
intend
fi
} function network(){
httpcode=`curl -I -m 10 -o /dev/null -s -w %{http_code}'\n' http://www.baidu.com`
net1=$(echo $httpcode | grep "200")
if [[ "$net1" != "" ]]
then
echo "|----------------------------------------------------------------------------------------------------------------|"
echo "|-----------------------------------------------------[联网]-----------------------------------------------------|"
echo "|-------------------------------------------------[准备联网安装]-------------------------------------------------|"
echo "|----------------------------------------------------------------------------------------------------------------|"
/usr/bin/sleep 3
online
else
echo "|----------------------------------------------------------------------------------------------------------------|"
echo "|-------------------------------------------[未联网,无离线安装包,准备退出]---------------------------------------|"
echo "|----------------------------------------------------------------------------------------------------------------|"
/usr/bin/sleep 3
exit;
fi
}
function online(){
wget_v=`which wget`
wget_vv=$(echo $wget_v | grep wget)
if [[ "$wget_vv" != "" ]]
then
echo "|----------------------------------------------------------------------------------------------------------------|"
echo "|--------------------------------------`wget -V |head -n 1`---------------------------------------|"
echo "|----------------------------------------------------------------------------------------------------------------|"
wget http://download.redis.io/releases/redis-${onversion}.tar.gz
installon
else
echo "|----------------------------------------------------------------------------------------------------------------|"
echo "|----------------------------------------[检测到wget没有安装, 准备安装wget]---------------------------------------|"
echo "|----------------------------------------------------------------------------------------------------------------|"
yum install wget -y
echo "|----------------------------------------------------------------------------------------------------------------|"
echo "|--------------------------------------`wget -V |head -n 1`---------------------------------------|"
echo "|----------------------------------------------------------------------------------------------------------------|"
wget http://download.redis.io/releases/redis-${onversion}.tar.gz
installon
fi
} function installon(){
echo "|----------------------------------------------------------------------------------------------------------------|"
echo "|--------------------------------------------------[在线包安装中]------------------------------------------------|"
echo "|----------------------------------------------------------------------------------------------------------------|"
tar -zxvf redis-${onversion}.tar.gz >/dev/null 2>&1
redis="redis-${onversion}"
cd ${redis}/src && make >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo "编译出错"
else
echo "|----------------------------------------------------------------------------------------------------------------|"
echo "|----------------------------------------------------[编译完成]--------------------------------------------------|"
echo "|----------------------------------------------------------------------------------------------------------------|"
/usr/bin/sleep 3
intend
fi
} function intend(){
echo "|----------------------------------------------------------------------------------------------------------------|"
echo "|-------------------------------------------------[开始迁移文件]-------------------------------------------------|"
echo "|----------------------------------------------------------------------------------------------------------------|"
mkdir -p ${installdir}/${cluster_name}/{logs,nodes,conf,bin}
cp redis-cli redis-server ${installdir}/${cluster_name}/bin
cp redis-trib.rb ${installdir}/${cluster_name}
cp ../redis.conf ${installdir}/${cluster_name}/conf/${confile1}
cp ../redis.conf ${installdir}/${cluster_name}/conf/${confile2}
echo "|----------------------------------------------------------------------------------------------------------------|"
echo "|-------------------------------------------------[数据迁移完成]-------------------------------------------------|"
echo "|----------------------------------------------------------------------------------------------------------------|"
/usr/bin/sleep 2
echo "|----------------------------------------------------------------------------------------------------------------|"
echo "|-------------------------------------------------[清理多余文件]-------------------------------------------------|"
echo "|----------------------------------------------------------------------------------------------------------------|"
#finish
/usr/bin/sleep 2
echo "|----------------------------------------------------------------------------------------------------------------|"
echo "|-------------------------------------------------[配置快捷启动]-------------------------------------------------|"
echo "|----------------------------------------------------------------------------------------------------------------|"
service
/usr/bin/sleep 2
echo "|----------------------------------------------------------------------------------------------------------------|"
echo "|-------------------------------------------------[修改配置文件]-------------------------------------------------|"
echo "|----------------------------------------------------------------------------------------------------------------|"
configfile
/usr/bin/sleep 3
echo "|****************************************************************************************************************|"
echo "| WW WW EEEEEEE LL CCCCC OOOOOO MM MM EEEEEEE |"
echo "| WW WWWW WW EE LL CC OO OO MMMM MMMM EE |"
echo "| WW WW WW WW EEEEE LL CC OO OO MM MM MM MM EEEEE |"
echo "| WW W W WW EE LL CC OO OO MM M M MM EE |"
echo "| WW WW EEEEEEE LLLLLL CCCCC OOOOOO MM MMM MM EEEEEEE |"
echo "|****************************************************************************************************************|"
}
function finish(){
echo
rm -rf ${installdir}/redis-*
}
function service(){
cd ${installdir}/${cluster_name}
echo "./bin/redis-server conf/${confile1}" > start.sh
echo "./bin/redis-server conf/${confile2}" >> start.sh
chmod +x start.sh
}
function configfile(){
cd ${installdir}/${cluster_name}
pathdir=`pwd`
cd ${installdir}/${cluster_name}/conf
#后台
sed -i 's/daemonize no/daemonize yes/' ${confile1} && sed -i 's/daemonize no/daemonize yes/' ${confile2}
#端口
sed -i 's/port 6379/port 7001/' ${confile1} && sed -i 's/port 6379/port 7002/' ${confile2}
#日志输出文件
logpath && logpath2
#开启集群
sed -i 's/# cluster-enabled yes/cluster-enabled yes/' ${confile1} && sed -i 's/# cluster-enabled yes/cluster-enabled yes/' ${confile2}
#集群数据文件
clusterconf && clusterconf2
}
function logpath(){
cd ${installdir}/${cluster_name}
pathdir=`pwd`
cd ${installdir}/${cluster_name}/conf
logfileold=`cat "${confile1}" | grep logfile | awk -F '"' '{print$2}'`
logfilenew=${pathdir}/logs/${logfile1}
if [ ! $logfileold ];then
echo "is null"
echo "start add data"
sed -i 's/logfile ""/logfile "judgement"/' ${confile1}
logfileold=`cat "${confile1}" | grep logfile | awk -F '"' '{print$2}'`
if [ ! $logfileold ];then
echo "is null"
else
echo "not null"
sed -i "s|$logfileold|$logfilenew|g" ${confile1}
fi
sed -i "s|$logfileold|$logfilenew|g" ${confile1}
else
echo "not null"
echo "start add data"
sed -i "s|$logfileold|$logfilenew|g" ${confile1}
fi
}
function logpath2(){
cd ${installdir}/${cluster_name}
pathdir=`pwd`
cd ${installdir}/${cluster_name}/conf
logfileold=`cat "${confile2}" | grep logfile | awk -F '"' '{print$2}'`
logfilenew=${pathdir}/logs/${logfile2}
if [ ! $logfileold ];then
echo "is null"
echo "start add data"
sed -i 's/logfile ""/logfile "judgement"/' ${confile2}
logfileold=`cat "${confile2}" | grep logfile | awk -F '"' '{print$2}'`
if [ ! $logfileold ];then
echo "is null"
else
echo "not null"
sed -i "s|$logfileold|$logfilenew|g" ${confile2}
fi
sed -i "s|$logfileold|$logfilenew|g" ${confile2}
else
echo "not null"
echo "start add data"
sed -i "s|$logfileold|$logfilenew|g" ${confile2}
fi
}
function clusterconf(){
cd ${installdir}/${cluster_name}
pathdir=`pwd`
cd ${installdir}/${cluster_name}/conf clusternumber=`cat -n ${confile1} | grep cluster-config-file | awk '{print$1}' | head -n 1`
clusterconfnew="cluster-config-file ${pathdir}/nodes/${nodes1}"
clusterNM=`cat -n ${confile1} | grep cluster-config-file | grep -v '#' | wc -l`
if [ ${clusterNM} -ge 1 ];then
number=`cat -n ${confile1} | grep cluster-config-file | grep -v '#' | awk '{print$1}' | head -n 1`
sed -i "${number}d" ${confile1}
else
sed -i "${clusternumber}i ${clusterconfnew}" ${confile1}
fi
}
function clusterconf2(){
cd ${installdir}/${cluster_name}
pathdir=`pwd`
cd ${installdir}/${cluster_name}/conf clusternumber=`cat -n ${confile2} | grep cluster-config-file | awk '{print$1}' | head -n 1`
clusterconfnew="cluster-config-file ${pathdir}/nodes/${nodes2}"
clusterNM=`cat -n ${confile2} | grep cluster-config-file | grep -v '#' | wc -l`
if [ ${clusterNM} -ge 1 ];then
number=`cat -n ${confile2} | grep cluster-config-file | grep -v '#' | awk '{print$1}' | head -n 1`
sed -i "${number}d" ${confile2}
else
sed -i "${clusternumber}i ${clusterconfnew}" ${confile2}
fi
}
function main(){
checkroot
judge
}
main

  

shell脚本一键安装redis集群的更多相关文章

  1. shell脚本一键安装redis集群[最终版]

    直接上shell了. #!/bin/bash #---------------------------------------------------------------------------- ...

  2. 编写shell脚本一键启动zookeeper集群!!

    踩了一个多小时坑终于解决了: 这里分享给大家,更主要的目的是记住这些坑,避免以后重复走!!! 首先,这里采用ssh秘钥方式进行集群主机之间免密登录执行启动命令 这里简单说下原理: 通过ssh去另外一台 ...

  3. shell脚本一键安装redis

    支持识别离线包和联网安装,自动修改使用后台运行模式,离线安装的方法是,将离线包和脚本放在同一个文件夹, 它会先识别有没有离线包, 有离线包就先安装离线包, 没有离线包就安装进行判断机器是否能联网, 能 ...

  4. liunx contos 7.4 安装redis集群

    前前后后安装了几次redis集群,基本上每次安装都会采坑,耗时伤神. 安装redis依赖gcc环境,安装前先检查liunx上面有没有安装GCC 命令:gcc -v 上传redis-4.0.1.tar. ...

  5. 从零开始安装Redis 集群(Linux CenOS7)

    从零开始安装Redis 集群(Linux CenOS7) 使用ISO安装CentOS7虚拟机 配置静态IP(参考Mac VMware Fusion CentOS7配置静态IP) 安装vim [root ...

  6. centos7.0 安装redis集群

    生产环境下redis基本上都是用的集群,毕竟单机版随时都可能挂掉,风险太大.这里我就来搭建一个基本的redis集群,功能够用但是还需要完善,当然如果有钱可以去阿里云买云数据库Redis版的,那个还是很 ...

  7. Centos 6.4上面用Shell脚本一键安装vsftpd

    Centos 6.4上面用Shell脚本一键安装vsftpd install.sh #!/bin/bash if [ `uname -m` == "x86_64" ];then m ...

  8. Centos 6.4上面用Shell脚本一键安装mysql 5.6.15

    Centos 6.4上面用Shell脚本一键安装mysql 5.6.15  #!/bin/bash if [ `uname -m` == "x86_64" ];then machi ...

  9. 安装完Ubuntu后通过shell脚本一键安装软件

    安装完Ubuntu后通过shell脚本一键安装软件 以下代码中#是单行注释 :<<! ! 是多行注释. 运行的时候需要把多行注释去掉. 比如把以下代码保存为install.sh, 那么在终 ...

随机推荐

  1. [转]记解决一次“HTTP Error 400. The request URL is invalid”的错误

    今天将图片服务切到使用了cdn的机器上面去,然后就部分图片报如下图错误“HTTP Error 400. The request URL is invalid” 看到这种错误信息,一般的开发者心中可能会 ...

  2. Elasticsearch集群管理工具head插件安装

    Elasticsearch-head是一个elasticsearch的集群管理工具,它是完全由html5编写的独立网页程序,你可以通过插件把它集成到es.或直接下载源码,在本地打开index.html ...

  3. Github Issues

    快捷键r

  4. Pygame模块,功能表

    Pygame有很多的模块,下面是一张一览表: 模块名 功能 pygame.cdrom 访问光驱 pygame.cursors 加载光标 pygame.display 访问显示设备 pygame.dra ...

  5. Oracle推进SCN系列:使用oradebug在mount状态下推进SCN

    环境:RHEL 6.5(x86-64) + Oracle 11.2.0.4 声明:推进SCN属于非常规恢复范畴,不建议非专业人员操作,否则后果自负. 需求:我这里演示下推进SCN 10W数量级,实际需 ...

  6. sqli-labs(十七)

    第五十四关: 这关大概意思就是尝试次数不能多于十次,必须十次之类查询处特点的key. 第一次:输入单引号报错 第二次:输入双引号不报错 说明后台是单引号进行的拼凑 第三步:这里应该是判断列,用orde ...

  7. web前端 ajax请求报415/400错

    一.当使用jQuery 的ajax发送请求时 1.请求路劲没有出错并且不存在跨域,出现415错误 解决方法:在ajax请求中加上contentType: 'application/json', $.a ...

  8. Installing IIS 8 on Windows Server 2012微软官方安装指导

    from: https://www.iis.net/learn/get-started/whats-new-in-iis-8/installing-iis-8-on-windows-server-20 ...

  9. nat123学习笔记

    1.NAT123内网映射端口 在无内网路由管理员权限的情况下,需要将内网web应用暴露到公网访问,此时需要用到花生壳或者nat123(两个应用都不是免费的,其中花生壳可以8元认证,以后免费使用,nat ...

  10. CSS尺寸与补白属性-----margin和padding

       margin margin:[ <length> | <percentage> | auto ]{1,4}  为元素设置所有四个方向(上右下左)的外边距 auto:水平( ...