Installation and use of redis
Environment: CentOS 6.6 redis version: redis-3.0 (considering the characteristics of redis 3.0 in clustering and performance improvement, RC version is a candidate for the official version, and the official version will be released soon) installation directory: / usr / local / redis user: root package required for compilation and installation: # Yum install GCC TCL Download redis version 3.0 (the current version of redis-3.0.0-rc5.tar.gz is the latest version. Please choose the latest version yourself during installation) # CD / usr / local / SRC # WGet https://github.com/antirez/redis/archive/3.0.0-rc5.tar.gz Create installation directory: # MKDIR / usr / local / redis extract: # tar -zxvf 3.0 0-rc5. tar. gz# mv redis-3.0. 0-rc5 redis3. 0# cd redis3. 0 installation (use prefix to specify the installation directory): # make prefix = / usr / local / redis install after installation, you can see a bin directory under / usr / local / redis directory. In the bin directory is the command script of redis: redis benchmark redis check AOF redis check dump redis cli redis server configure redis as a service: follow the above steps, The redis startup script is: / usr / local / SRC / redis3 0/utils/redis_ init_ Script copy the startup script to / etc / RC d/init. D / directory and name it redis: # CP / usr / local / SRC / redis3 0/utils/redis_ init_ script /etc/rc. d/init. D / redis edit / etc / RC d/init. D / redis, modify the corresponding configuration so that it can be registered as a service: # VI / etc / RC d/init. d/redis#!/ bin/sh## Simple Redis init. d script conceived to work on Linux systems# as it does use of the /proc filesystem. REDISPORT=6379EXEC=/usr/local/bin/redis-serverCLIEXEC=/usr/local/bin/redis-cliPIDFILE=/var/run/redis_$ {REDISPORT}. pidCONF="/etc/redis/${REDISPORT}.conf"case "$1" in start) if [ -f $PIDFILE ] then echo "$PIDFILE exists,process is already running or crashed" else echo "Starting Redis server..." $ EXEC $CONF fi ;; stop) if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist,process is not running" else PID=$(cat $PIDFILE) echo "Stopping ..." $ CLIEXEC -p $REDISPORT shutdown while [ -x /proc/${PID} ] do echo "Waiting for Redis to shutdown ..." sleep 1 done echo "Redis stopped" fi ;; *) echo "Please use start or stop as first argument" ;; ESAC checks the above redis service script, pays attention to the attributes marked in orange, and prepares to make the following modifications: (1) add a line after the first line of the script as follows: #chkconfig: 2345 80 90 (if you do not add the above content, you will be prompted when registering the service: service redis does not support chkconfig) (2) the report port remains 6379 unchanged; (note that the port name will be related to the following configuration file name) (3) change exec = / usr / local / bin / redis server to exec = / usr / local / redis / bin / redis server (4) change cliexec = / usr / local / bin / redis cli to cliexec = / usr / local / redis / bin / redis cli (5) Configuration file settings: create the redis configuration file directory # MKDIR / usr / local / redis / conf and copy the redis configuration file / usr / local / SRC / redis3 0/redis. Conf to / usr / local / redis / conf directory and rename it to 6379 conf# cp /usr/local/src/redis3. 0/redis. conf /usr/local/redis/conf/6379. After conf has made the above preparations, adjust the conf attribute as follows: conf = "/ etc / redis / ${report}. Conf" is changed to conf = "/ usr / local / redis / conf / ${report}. Conf" (6) change the redis startup command and execute it in the background running mode: $exec $conf & # "&" is used to turn the service to the later running modified / etc / RC d/init. D / redis service script content: #/ bin/sh#chkconfig: 2345 80 90## Simple Redis init. d script conceived to work on Linux systems# as it does use of the /proc filesystem. REDISPORT=6379EXEC=/usr/local/redis/bin/redis-serverCLIEXEC=/usr/local/redis/bin/redis-cliPIDFILE=/var/run/redis_$ {REDISPORT}. pidCONF="/usr/local/redis/conf/${REDISPORT}.conf"case "$1" in start) if [ -f $PIDFILE ] then echo "$PIDFILE exists,process is already running or crashed" else echo "Starting Redis server..." $ EXEC $CONF & fi ;; stop) if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist,process is not running" else PID=$(cat $PIDFILE) echo "Stopping ..." $ CLIEXEC -p $REDISPORT shutdown while [ -x /proc/${PID} ] do echo "Waiting for Redis to shutdown ..." sleep 1 done echo "Redis stopped" fi ;; *) echo "Please use start or stop as first argument" ;; After ESAC completes the above configuration operations, redis can be registered as a service: # chkconfig -- add open the corresponding port in redis firewall # VI / etc / sysconfig / iptables add: - a input - M state -- state new - M TCP - P TCP -- dport 6379 - J accept restart firewall: # service iptables restart modify redis configuration file settings: # VI / usr / local / redis / conf / 6379 Conf: modify the configuration as follows: configure no to > configure yes pidfile / var / run / redis Change PID to > pidfile / var / run / redis_ 6379.pid start redis service # service redis start add redis to the environment variable: # VI / etc / profile add the following content at the end: ## redis envexport path = $path: / usr / local / redis / bin make the configuration effective: # source / etc / profile can now directly use redis CLI and other redis commands: turn off redis service # service redis stop by default, Redis can enable security authentication through / usr / local / redis / conf / 6379 The requirepass of conf specifies an authentication password. Tutorial demo address: https://github.com/leeSmall/RedisExample.git