How to install the Redis database in Linux and share with the automatic STARTUP script, linuxredis

Source: Internet
Author: User
Tags download redis

How to install the Redis database in Linux and share with the automatic STARTUP script, linuxredis

Install Redis

(1) download Redis

wget http://redis.googlecode.com/files/redis-2.2.11.tar.gztar xzvf redis-2.2.11.tar.gz

(2) Compile and install Redis

make && make install

(3) copy and modify the configuration file

cp redis.conf /etc/redis.confvi /etc/redis.conf

Note:

daemonize yesloglevel warninglogfile /var/log/redis.logmaxmemory 2GB

(Do not activate the Virtual Memory option at your discretion)

(4) set Redis-Server to automatically start the service

Download the startup script (gist.github.com, search for redis init. d) online and modify it

(At least modify redis and REDIS_CONF_FILE)

vi /etc/init.d/redisctlchmod 755 redisctlcp /etc/init.d/redisctl /etc/rc.d/init.d/redisctl \&& ln -s /etc/init.d/redisctl /etc/rc.d/rc2.d/S90redisctl && ln -s /etc/init.d/redisctl /etc/rc.d/rc3.d/S90redisctl \&& ln -s /etc/init.d/redisctl /etc/rc.d/rc4.d/S90redisctl && ln -s /etc/init.d/mongod /etc/rc.d/rc5.d/S90redisctlchkconfig --add redisctl

(5) After restarting, you can test whether the redis-server is started normally.

```redis-cli set foo Barredis-cli get foo

Redis Automatic startup script

```ruby#!/bin/sh## redis - this script starts and stops the redis-server daemon## chkconfig: 2345 90 10 # description: Redis is a persistent key-value database# processname: redis-server# config: /etc/redis.conf# config: /etc/sysconfig/redis# pidfile: /var/run/redis.pid# Source function library.. /etc/rc.d/init.d/functions# Source networking configuration.. /etc/sysconfig/network# Check that networking is up.[ "$NETWORKING" = "no" ] && exit 0redis="/usr/local/bin/redis-server"prog=$(basename $redis)REDIS_CONF_FILE="/etc/redis.conf"[ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redislockfile=/var/lock/subsys/redisstart() { [ -x $redis ] || exit 5 [ -f $REDIS_CONF_FILE ] || exit 6 echo -n $"Starting $prog: " daemon $redis $REDIS_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval}stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval}restart() { stop start}reload() { echo -n $"Reloading $prog: " killproc $redis -HUP RETVAL=$? echo}force_reload() { restart}rh_status() { status $prog}rh_status_q() { rh_status >/dev/null 2>&1}case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval}restart() { stop start}reload() { echo -n $"Reloading $prog: " killproc $redis -HUP RETVAL=$? echo}force_reload() { restart}rh_status() { status $prog}rh_status_q() { rh_status >/dev/null 2>&1}case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval}restart() { stop start}reload() { echo -n $"Reloading $prog: " killproc $redis -HUP RETVAL=$? echo}force_reload() { restart}rh_status() { status $prog}rh_status_q() { rh_status >/dev/null 2>&1}case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0  ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" exit 2esac

Redis Automatic startup script

Remember to modify:

(1)-chuid group: user

(2) ln/etc/init. d/redisctl/etc/rc2.d/redisctl, repeat rc3, rc4, rc5

STARTUP script:

#! /bin/sh### BEGIN INIT INFO# Provides:  redis-server# Required-Start: $syslog# Required-Stop: $syslog# Should-Start:  $local_fs# Should-Stop:  $local_fs# Default-Start: 2 3 4 5# Default-Stop:  0 1 6# Short-Description: redis-server - Persistent key-value db# Description:  redis-server - Persistent key-value db### END INIT INFODAEMON=/usr/local/bin/redis-serverDAEMON_ARGS=/etc/redis.confNAME=redis-serverDESC=redis-serverPIDFILE=/var/run/redis.pidtest -x $DAEMON || exit 0test -x $DAEMONBOOTSTRAP || exit 0set -ecase "$1" in start) echo -n "Starting $DESC: " touch $PIDFILE # chown redis:redis $PIDFILE if start-stop-daemon —start —quiet —umask 007 —pidfile $PIDFILE —chuid redis:redis —exec $DAEMON — $DAEMON_ARGS then  echo "$NAME." else  echo "failed" fi ;; stop) echo -n "Stopping $DESC: " if start-stop-daemon —stop —retry 10 —quiet —oknodo —pidfile $PIDFILE —exec $DAEMON then  echo "$NAME." else  echo "failed" fi rm -f $PIDFILE ;; restart|force-reload) ${0} stop ${0} start ;; *) echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload}" >&2 exit 1 ;;esacexit 0

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.