The installation method of Redis database under Linux and automatic Start script sharing _ruby topic

Source: Internet
Author: User
Tags download redis redis syslog touch install redis

Install Redis

(1) Download Redis

wget http://redis.googlecode.com/files/redis-2.2.11.tar.gz
tar 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.conf
vi/etc/redis.conf

Note Modify the following:

Daemonize Yes
loglevel warning
logfile/var/log/redis.log
maxmemory 2GB

(self-discretion is not to open the virtual memory option)

(4) Set up Redis-server to start the service automatically

Download the startup script (gist.github.com, search Redis init.d) and simply Modify

(At a minimum, you need to modify Redis, Redis_conf_file)

Vi/etc/init.d/redisctl
chmod 755 redisctl
cp/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/s90redisctl
chkconfig--add redisctl

(5) After reboot can test redis-server whether normal boot

' Redis-cli set foo Bar redis-cli get
foo

Redis Automatic startup script

"Ruby #!/bin/sh # Redis-this script starts and stops Redis-server Daemon # chkconfig:2345 On:redis is a persistent key-value database # processname:redis-server # config:/etc/redis.conf # config:/etc/sysconfi
G/redis # Pidfile:/var/run/redis.pid # Source function library. .
/etc/rc.d/init.d/functions # Source Networking configuration. .
/etc/sysconfig/network # Check that networking are up. ["$NETWORKING" = "no"] && exit 0 redis= "/usr/local/bin/redis-server" prog=$ (basename $redis) redis_conf_file= " /etc/redis.conf "[-f/etc/sysconfig/redis] &&.  /etc/sysconfig/redis Lockfile=/var/lock/subsys/redis Start () {[x $redis] | | Exit 5 [f $REDIS _conf_file] | |
 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 $pro
 G-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 "$" in start Rh_status_q && exit 0 $; Stop) rh_status_q | |
 Exit 0 $;;
 Restart|configtest) $ retval=$? echo [$retval-eq 0] && rm-f $lockfile return $retval} restart () {Stop start} reload () {echo-n $ "Re
 Loading $prog: "Killproc $redis-hup retval=$?" 

echo} force_reload () {restart} rh_status () {Status $prog} rh_status_q () {rh_status >/dev/null 2>&1}
 Case "$" in start Rh_status_q && exit 0 $; Stop) rh_status_q | |
 Exit 0 $;;
 Restart|configtest) $ retval=$? echo [$retval-eq 0] && rm-f $lockfile return $retval} restart () {Stop start} reload () {echo-n $ "Re
 Loading $prog: "Killproc $redis-hup retval=$?" echo} foRce_reload () {restart} rh_status () {Status $prog} rh_status_q () {rh_status >/dev/null 2>&1} case "
 "In Start" Rh_status_q && exit 0 $; Stop) rh_status_q | |
 Exit 0 $;;
 Restart|configtest) $;; Reload) Rh_status_q | |
 Exit 7 $;;
 Force-reload) force_reload;;
 status) Rh_status;; Condrestart|try-restart) rh_status_q | |
 Exit 0;;

 * echo $ "Usage: $ {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" Exit 2 Esac

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-pe Rsistent Key-value DB # description:redis-server-persistent Key-value db ### end INIT INFO Daemon=/usr/local/bin/redi S-server daemon_args=/etc/redis.conf name=redis-server desc=redis-server pidfile=/var/run/redis.pid test-x $DAEMON | | Exit 0 Test-x $DAEMONBOOTSTRAP | | Exit 0 set-e case "on Start" Echo-n "Starting $DESC:" Touch $PIDFILE # chown Redis:redis $PIDFILE if Start-sto 
 P-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 th
 En 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;;
 ESAC Exit 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.