源码安装redis初始化实例脚本

 1 #!/bin/bash -

 2 #Date: 2014-05-20

 3 #Auth: Jin

 4 

 5 version='2.8.7'

 6 progname='redis'

 7 pkgname="${progname}-${version}"

 8 pkgfilename="${pkgname}.tar.gz"

 9 installdir="/usr/local/${progname}"

10 logdir="/var/log/${progname}"

11 installbindir="${installdir}/bin"

12 installetcdir="${installdir}/etc"

13 datadir='/data/redis'

14 binfile='redis-server redis-cli redis-check-aof redis-check-dump redis-benchmark redis-sentinel'

15 

16 

17 function install_redis() {

18 test -f /etc/redhat-release &&  PKGM=yum || PKG=zypper

19 ${PKGM} install gcc wget

20 ### create base dir ###

21 mkdir -p ${datadir}

22 mkdir -p ${installbindir}

23 mkdir -p ${installetcdir}

24 ### down and copy bin ###

25 mkdir -p ~root/Downloads/ && cd ~root/Downloads/

26 test -f ${pkgfilename} || wget http://download.redis.io/releases/${pkgfilename} && tar -zxvf ${pkgfilename} && cd ${pkgname}

27 make MALLOC=libc && find ./src -perm 755 -exec cp {} ${installbindir}/  \;  

28 #for i in ${binfile};do

29 #    cp ${i} ${installbindir}/ && echo "Install $i OK"

30 #done

31 ###  config file ###

32 cp ./redis.conf ${installetcdir}/ &&  echo "Install redis.conf OK"

33 ### kernel option of ram is low ###a

34 #echo 'vm.overcommit_memory=1' >> /etc/sysctl.conf && sysctl -p /etc/sysctl.conf

35 }

36 

37 

38 function config_instance(){

39 if [ $# -eq 1 ];then

40         port=$1

41 else

42    echo 'Please give instance port!'

43    exit 1

44 fi

45 

46 grep -vE '^$|^#' ${installetcdir}/redis.conf > ${installetcdir}/${port}.conf

47 #set port number

48 sed -i /port/s/6379/${port}/ ${installetcdir}/${port}.conf

49 #enable daemonize

50 sed -i /daemonize/s/no/yes/ ${installetcdir}/${port}.conf

51 #set pid with port number

52 sed -i /pidfile/s/redis.pid/redis-${port}.pid/ ${installetcdir}/${port}.conf

53 #data

54 mkdir -p ${datadir}/${port}

55 sed -i "/dir/s/\.\//\/data\/redis\/${port}/" ${installetcdir}/${port}.conf

56 #set logfile with port number

57 #LOG非绝对路径,则放在数目录下

58 sed -i "/logfile/s/\"\"/${port}\.log/" ${installetcdir}/${port}.conf

59 ##start intance 

60 cd ${installdir} &&  ${installbindir}/redis-server ${installetcdir}/${port}.conf

61 }

62 

63 function uninstall_redis() {

64 rm -rf ${datadir} && echo "Clean ${datadir} OK"

65 rm -rf ${installdir} && echo "Clean ${installdir} OK"

66 }

67 

68 #main

69 if [ $# -ge 1 ];then

70         if [ $1 = 'install' ];then

71                 echo 'Install'

72                 install_redis

73         elif [ $1 = 'uninstall' ];then

74                 uninstall_redis

75         elif [ $1 = 'confinstance' ];then

76                 if [ $# -eq 2 ];then

77                         port=$2

78                         config_instance $port

79                 else

80                         echo "Please give a instance port!"

81                 fi

82         else

83                 echo "Usage: ${0} {install|uninstall|confinstance [portnumber]}"

84         fi

85 else

86         echo "Usage: ${0} {install|uninstall|confinstance [portnumber]}"

87 fi

 

你可能感兴趣的:(redis)