Automatic Redis installation and deployment
This article consists of four parts:
Description of the directory structure of the redis automatic installation script;
Redis automatic installation script content;
Description of the redis Operating System Service script;
The URL of the document referenced in this article.
Note: This article does not cover the redis memory distributor.
Part 1
Description of the directory structure of the Redis automatic installation script:
# Ls check that the current directory contains the following three files
-- Install_redis.sh # redis automatic installation script
-- Redis-2.8.9.tar.gz # redis installation package (requires make, make test, make install)
-- Redis_service_script # redis Operating System Service script (used to configure redis Service Startup and redis service management commands)
Part 2
########################### Start of the redis automatic installation script content (install_redis.sh) ######################
#! /Bin/bash
# Version: v1.0 by JiangYanguo on 2014-05-14
# Desc: auto make, make install and configure redis
REDIS_CONF = "/etc/redis. conf"
# Check whether the redis installation package exists
If ["'ls redis-* .tar.gz>/dev/null 2> & 1; echo $? '"-Ne 0]
Then
Echo "Error: redis * .tar.gz file doesn't exists ."
Exit
Else
REDIS_PACKAGE = "'LS-ltr redis-* .tar.gz | head-1 | awk' {print $ NF }''"
Fi
# Install redis, make, make test, make install
# Install redis
Echo "Info: install redis ..."
Tar zxf $ {REDIS_PACKAGE}
REDIS_DIR = "'LS-ltr | egrep '^ d' | awk' {print $ NF }''"
Cd $ {REDIS_DIR}
Pwd
Make
Make test
If ["$? "-Nt 0]; then
Echo "Some dependent packages are needed ."
Exit
Fi
Make install
Echo "Info: set $ {REDIS_CONF }..."
Cd ..
# Set the redis configuration file. The data directory is/home/redis.
# Set/etc/redis. conf
Cp redis. conf/etc/
Sed-I's/^ daemonize \ (. * \)/# daemonize \ 1/G' $ {REDIS_CONF}
Sed-I '2 adaemonize yes '$ {REDIS_CONF}
Sed-I's/^ dir \ (. * \)/# dir \ 1/G' $ {REDIS_CONF}
Sed-I '2 adir \/home \/redis \/'$ {REDIS_CONF}
# Set memory allocate method
["'Egrep 'vm. overcommit_memory = 1'/etc/sysctl. conf | wc-L' "-eq 0] & echo" vm. overcommit_memory = 1 ">/etc/sysctl. conf
/Sbin/sysctl-p
# Add redis user
Useradd redis
# Set redis data dir
Mkdir-p/home/redis/
Chown-R redis. redis/home/redis
# Setting the redis service to start automatically upon startup is also a redis Management Service
# Set redis service
Echo "Info: set redis service ..."
Cp redis_service_script/etc/init. d/redis
Chmod + x/etc/init. d/redis
Chkconfig -- add redis
Chkconfig redis on
#
Echo "Info: finish installing redis ."
Echo ""
########################## End of the redis automatic installation script (install_redis.sh) #####################################
Part 3
########################## Redis_service_script) ######################################## #
#! /Bin/bash
# Redis-Startup script for redis
# Chkconfig: 2345 85 152345 85 15
# Description: startup script fZ restart? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> cipher + CiAgIHRoZW48YnI + cipher/cipher + CiAgIHRoZW48YnI + cipher + CiMjIHN0b3A8YnI + region + region + CiAgZmk8YnI + region + CiAgc3RhcnQ8YnI + region + Cn08YnI + region + CiAgZmk8YnI + Cn08YnI + region = = "grep redis-server | wc-L '"
If [-f $ PIDFILE] & ["$ {REDIS_SERVER_COUNT}"-gt 0]
Then
Echo "Info: redis is running ."
Elif [! -F $ PIDFILE]
Then
Echo "$ PIDFILE does not exist, process is not running"
Elif ["$ {REDIS_SERVER_COUNT}"-eq 0]
Then
Echo "Redis is not listening any port ."
Fi
}
Case "$1" in
Start)
Start
;;
Stop)
Stop
;;
Restart)
Restart
;;
Info)
Info
;;
Status)
Status
;;
*)
Echo "Usage: $0 {start | stop | restart | info | status }"
Esac
########################## Redis_service_script) ######################################## #
Part 4
Link for reference:
Redis installation: http://www.cnblogs.com/zhuhongbao/archive/2013/06/04/3117997.html
Redis installation: http://blog.chinaunix.net/uid-790245-id-3766268.html
CallSend SMSAdd to SkypeYou'll need Skype CreditFree via Skype