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

#!/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) 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}/redis/{logs,nodes,conf,bin}
cp redis-cli redis-server ${installdir}/redis/bin
cp redis-trib.rb ${installdir}/redis
cp ../redis.conf ${installdir}/redis/conf
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 2
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}/redis && echo "./bin/redis-server conf/redis.conf" > start.sh
chmod +x start.sh
}
function configfile(){
cd ${installdir}/redis/conf
#后台
sed -i 's/daemonize no/daemonize yes/' redis.conf
#端口
sed -i 's/port 6379/port 7000/' redis.conf
#日志输出文件
sed -i 's/logfile ""/logfile "\/usr\/local\/src\/redis\/logs\/redis.logs"/' redis.conf
}
function main(){
checkroot
judge
}
main

离线安装的效果

在线安装的效果

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

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

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

  2. shell脚本一键安装redis集群

    简介: 明天再写,上脚本 #!/bin/bash #-------------------------------------------------------------------------- ...

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

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

  4. 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 ...

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

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

  6. shell脚本一键安装mysql5.7.x

    使用脚本一键安装mysql5.7.x,初始化数据库.启动数据库---- mysql版本号:源代码mysql5.7.10 linux版本号:centos6.5 x86_64 #!/bin/bash GR ...

  7. shell脚本一键安装mysql5.7.x(免安装版)

    使用脚本一键安装mysql5.7.x,初始化数据库,启动数据库---- mysql版本:源码mysql5.7.10 linux版本:centos6.5 x86_64 #!/bin/bash GROUP ...

  8. Shell脚本一键安装LNMP环境

    https://sourceforge.net/projects/opensourcefile/files/ Nginx是一款高性能的HTTP和反向代理服务器.Nginx在反向代理,Rewrite规则 ...

  9. shell脚本一键安装jdk

    直接上shell #!/bin/bash #offline jdk install ipath="/usr/local" installpath=$(cd `dirname $0` ...

随机推荐

  1. jenkins 关联 钉钉机器人

    注意:Jenkins URL配置中需要在最后添加"/",要不然会导致拼接的Url出错,这里填写有问题会导致无法从钉钉中跳转到Jenkins任务

  2. iOS UI基础-9.0 UITableView基础

    在iOS中,要实现表格数据展示,最常用的做法就是使用UITableView.UITableView继承自UIScrollView,因此支持垂直滚动,而且性能极佳. UITableView有两种样式: ...

  3. 27.给input边框和背景颜色设置全透明

    给input边框和背景颜色设置全透明,但是里面的字不会消失 1.让背景颜色变透明(二选一) background-color:rgba(0,0,0,0); background:rgba(0,0,0, ...

  4. 第六天实验详解——dedecms通过xss漏洞写马

    第六天实验详解 **XSS跨站攻击的分类** XSS漏洞类型主要分为持久型和非持久型两种: 1. 非持久型XSS漏洞一般存在于URL参数中,需要访问黑客构造好的特定URL才能触发漏洞. 2. 持久型X ...

  5. UVALi 3263 That Nice Euler Circuit(几何)

    That Nice Euler Circuit [题目链接]That Nice Euler Circuit [题目类型]几何 &题解: 蓝书P260 要用欧拉定理:V+F=E+2 V是顶点数; ...

  6. notepad使用列选

    列选有两种方法: 1.按住ALT + 鼠标从某点按住开始向下或向上拖动. 2.按住ALT+SHIFT+上下方向键. 列编辑: 1.ALT+C 2.插入相同文本还是自增数字

  7. kali linux android木马(内网+外网)

    1,内网木马 先生成一个小马 msfpayload -p android/meterpreter/reverse_tcp LHOST=192.168.8.104 LPORT=5555 R > a ...

  8. python random函数

    .random模块方法说明 random.random()函数是这个模块中最常用的方法了,它会生成一个随机的浮点数,范围是在0.0~1.0之间. random.uniform()正好弥补了上面函数的不 ...

  9. steam pipeGUI

    SteamPipe GUI 工具 如果您运行的是 Windows,并且更喜欢使用 GUI 工具来帮助生成配置文件并上传您的生成版本,您可以使用 Steamworks SDK 的工具文件夹中的 Stea ...

  10. html5-盒子模型

    /*div{background: green;width: 60%;padding-top: 10px;padding-right: 20px;padding-bottom: 30px;paddin ...