[原创]redis 自动安装shell脚本 – 21运维
通知: .-...

[原创]redis 自动安装shell脚本

Nosql 21运维 2725浏览 0评论

偷懒到一定境界了,又吃多了写一个redis自动安装shell脚本。再说自己确实非常的懒,多次搞得事情都脚本来实现吧,手工安装太麻烦了。当然,也可以自己yum安装(yum安装的版本过低,一般就rpm安装了)。
平台:centos 6.x  64
redis版本:redis 2.8or 3.0
参数优化:未优化,需自己根据生产环境进行优化。

#!/bin/bash
#function:  Install  redis  for centos 6.x_64bit
#author:21yunwei
downloaddir=/usr/local/src

function menu(){
	echo "###############################################################"
	cat < <EOF
	Please choose  redis version  which  you want to install:
	1,Redis 2.8.24-5.el6.art.x86_64
	2,Redis 3.0.7-4.el6.art.x86_64
EOF
	echo "###############################################################"
}

function  checkroot(){
if [ $UID -ne  0 ]
  then
	echo "Please login as  root"
	exit;
fi
}

function  msgbox(){
if [ $? -eq 0 ] ;then
	echo "This step sucess" 
else 
	echo  "This step failed,please check"
	exit;
fi
}
function  check_env(){
echo  -e "checking  epel\n"
rpm  -qa | grep epel
if [ $? -eq 0 ]; then
        echo -e  "epel  has been installed\nInstall  required  libs:"
	yum install jemalloc -y >/dev/null
else
        echo  "epel does not install,now  install  epel"
        yum install  epel-release  -y > /dev/null
	echo  "Install  required  libs:"
	yum install jemalloc -y >/dev/null
fi
}

function  redis_version(){
read  -p  "please choose redis  version that you  want to install:" flag
}

function  redis_install(){

case $flag  in

1)
	version="redis-2.8.24-5.el6.art.x86_64"
	echo "Redis 2.8.X will be  install" && wget  -O ${downloaddir}/${version}.rpm  http://www6.atomicorp.com/channels/atomic/centos/6/x86_64/RPMS/${version}.rpm 
	rpm -ih ${downloaddir}/${version}.rpm
;;
2)
	version="redis-3.0.7-4.el6.art.x86_64"
	echo "Redis 3.0.X will be  install" && wget  -O ${downloaddir}/${version}.rpm   http://www6.atomicorp.com/channels/atomic/centos/6/x86_64/RPMS/${version}.rpm
	rpm -ih ${downloaddir}/${version}.rpm
;;
*)
echo "Please  input 1 or 2,other novalid"
redis_version
redis_install
esac
}
function  check_install_status(){
/etc/init.d/redis start
netstat   -tunlp | grep  6379
if [ $? -eq 0 ]; then
	echo  "Redis install sucess"
	chkconfig  redis  on
else
	echo  "Redis  install  failed,please  check"
	exit;
fi
}
function main(){
checkroot
check_env
menu
redis_version
redis_install
check_install_status
}
main


转载请注明:21运维 » [原创]redis 自动安装shell脚本

发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址