Redis configured as a service startup

Source: Internet
Author: User
Tags redis sleep iptables redis server

There are many ways to configure Redis to boot
But read the official script, or use the official (own shell level or self-knowledge ...)
1. Copy the script into the system directory

Cp/redis/utils/redis_init_script/etc/rc.d/init.d/redis

2. Modify the Script
Vim/etc/rc.d/init.d/redis

#!/bin/sh # # Simple Redis INIT.D script conceived to work on the Linux systems # as it does use of the/proc filesystem. redisport=6379 Exec=/usr/local/bin/redis-server cliexec=/usr/local/bin/redis-cli PIDFILE=/var/run/redis_${
                Redisport}.pid conf= "/etc/redis/${redisport}.conf" case "$" 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 was not running " Else pid=$ (cat $PIDFILE) echo "Stopping ..." $CLIEXEC-P $REDISPORT s Hutdown while [-x/proc/${pid}] does echo "Waiting for Redis to Shutdo
     WN ... "Sleep 1 done echo" Redis stopped   fi;;
*) echo "Please use Start or stop as first argument";; Esac

1). In #!/bin/sh add #chkconfig:2345 80 90, (if not added, when registering the service: Service Redis does not chkconfig)
2). The Redisport configures
3 according to its own environment configuration. Exec=/usr/local/bin/redis-server changed to Exec=redis/src/redis-server
4) in its own environment. CLIEXEC=/USR/LOCAL/BIN/REDIS-CLI changed to CLIEXEC=REDIS/SRC/REDIS-CLI
5) in its own environment. Conf=/etc/redis/{redisport}.conf "changed to CONF=REDIS/REDIS.CONF &NBSP in its own environment;
6). Pidfile=/var/run/redis_{redisport}.conf "changed to own environment under conf=redis/redis.conf 6). Pidfile=/var/run/redis_{redisport}.pid changed to the configuration under its own environment (redis.conf: Pidfile/var/run/redis_6379.pid)
7). In $exec $ CONF followed by & $EXEC $CONF &
Modified file

#!/bin/sh #chkconfig: 2345 # # Simple Redis INIT.D script conceived to work in Linux systems # as it does use of the

/proc filesystem. redisport=6377 Exec=/home/software/redis/src/redis-server cliexec=/home/software/redis/src/redis-cli PIDFILE=/
        Home/data/redis/run/redis.pid conf= "/home/software/redis/redis.conf" case "$" 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 was not running " Else pid=$ (cat $PIDFILE) echo "Stopping ..." $CLIEXEC-P $REDISPORT s Hutdown while [-x/proc/${pid}] does echo "Waiting for Redis to Shutdo
             WN ... "Sleep 1   Done echo "Redis stopped" FI;;
*) echo "Please use Start or stop as first argument";;
 Esac

3. Registration service:
chkconfig--add Redis
[4]. Firewall configuration
Add configuration: Echo '-A input-m State--state new-m tcp-p TCP--dport 6 379-j ACCEPT ' >>/etc/sysconfig/iptables
Restart: service iptables restart
[5]. Start Services
Servicing Redis start [6]. Test
Reboot
Ps-ef | grep redis

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.