CENTOS7 Configuration Redis Boot

Source: Internet
Author: User
Tags redis redis version redis server

One: Introduction to the principle

Take a look at what the current system has set up from the boot program:

[Root@localhost init.d]# chkconfig--list


Note:this output shows SYSV services only and does not include native
SYSTEMD Services. SYSV configuration data might is overridden by native
SYSTEMD configuration.


If you are want to list SYSTEMD services use ' Systemctl list-unit-files '.
To-to-services enabled on particular target
' Systemctl list-dependencies [target] '.


Netconsole 0:off1:off 2:off3:off 4:off5:off 6:off
Network 0:off1:off 2:on3:on 4:on5:on 6:off

[Root@localhost init.d]# ls/etc/init.d/-LRT
Total 40
-rwxr-xr-x. 1 root root 6470 2015 network
-rwxr-xr-x. 1 root root 2989 2015 netconsole
-rw-r--r--. 1 root root 13430 2015 functions
-rw-r--r--. 1 Root 1160 Mar 6 2015 README
-rw-r--r--. 1 root Nov 05:43 Dump.rdb

From the above you can see that the system has been set up from the boot program has network and Netconsole, the new boot from the program, the basic principle is:

When the system boots up, it will load the script below/etc/init.d/, usually each script file will customize the launch of the implementation program, if you want to boot the new program, simply add a custom launcher script to the directory, and then set the appropriate rules (as I did in/etc/ Init.d/creates a new Redis script that will load the script when it starts up; Of course, it's just a way to boot.


II: Practice

Less nonsense, direct to step:

1, set the redis.conf daemonize to Yes to ensure that the daemon is turned on.

2, write the boot from the start script

Vi/etc/init.d/redis

The script reads as follows:

# chkconfig:2345
# Description:start and Stop redis
  
path=/usr/local/bin:/sbin:/usr/bin:/bin   
redisport=6379
Exec=/usr/local/redis-3.0.0-beta5/src/redis-server
REDIS_CLI=/USR/LOCAL/REDIS-3.0.0-BETA5/SRC/REDIS-CLI
Pidfile=/var/run/redis.pid
conf= "/usr/local/redis-3.0.0-beta5/redis.conf"
Auth= "1234" case "," "in Start" if [-f $PIDFILE] Then  
                echo "$PIDFILE exists, process is already running or crashed."    
                else echo "Starting Redis server ..." $EXEC $CONF fi If ["$?"   
                = "0"] then echo "Redis is running ..." fi   
        ;; STOP) if [!-F $PIDFILE] then echo "$PIDFILE exists, PR  
                Ocess is not running. "  
                       Else pid=$ (cat $PIDFILE) echo "Stopping ..."   
                       $REDIS _cli-p $REDISPORT SHUTDOWN sleep 2 While [-X $PIDFILE] Do echo ' waiting for Redis to SHutdown ... "Sleep 1 do echo" Redis   
        Stopped "FI;;   
        restart|force-reload) ${0} stop ${0} start;;   
*) echo "Usage:/etc/init.d/redis {start|stop|restart|force-reload}" >&2 exit 1 Esac

3. Save and Exit VI after writing

4, set permissions

chmod 755 Redis

5. Start test

/etc/init.d/redis start

Startup success prompts you with the following information:

Starting Redis server ...
2358:m Nov 05:34:16.991 * Increased maximum number of open files to 10032 (it is originally set to 1024).                  _._                                                     &N Bsp        _.-' __ '-._                       &NBS P                            _.-'     '.   ' _.   '-._           Redis 2.9.54 (00000000/0) bit  .-'.-'.   ' ' \/   _.,_ '-._                         &N Bsp            (    '     &nbsp,      .-'  | ',    )     Running in stand alone mode  | '-._ '-...-' __...-. '-._| ' ` _.-'|     port:6379  |     '-._   '. _    /    _.-'    |     pid:2358   '-._     '-._   '-./ _.-'    _.-'                                     | '-._ '-._   &N BSP; '-.__.-'    _.-' _.-' |                                   &NB sp;|     '-._ '-._        _.-' _.-'    |           Http://redis.io           '-._     '-._ '-.__.-' _.-' & nbsp   _.-'                                     | '-._ '-._     '-.__.-'    _.-' _.-' |                                   |     '-._ '-._        _.-' _.-'    |                                   &NB Sp  '-._     '-._ '-.__.-' _.-'    _.-'                                          '-._     '-.__.-'    _.-'                                   &NB Sp              '-._        _.-'           &N Bsp                                  &NBS P           '-.__.-'     &nbsp                                   &NB Sp      2358:m Nov 05:34:16.993 # Server started, Redis version 2.9.54 2358:m-Nov 05:34:16.993 # Warni NG Overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ' vm.overcommit_memory = 1 ' to/etc/sysctl.conf and then reboot or run the command ' Sysctl vm.overcom
Mit_memory=1 ' for this to take effect. 2358:m Nov 05:34:16.993 * The server is now ready to accept connections on port 6379

To use the REDIS-CLI test:

[Best_husband@localhost src]$/usr/local/redis-3.0.0-beta5/src/redis-cli
127.0.0.1:6379> set name Usbdrivers
OK
127.0.0.1:6379> get name
"Usbdrivers"
127.0.0.1:6379> quit
[best_husband@localhost src]$

6, set the boot from start

Chkconfig Redis on

7, Shutdown restart test

Reboot

Then you can use the REDIS-CLI test.


Description: I initially tested in the/etc/init.d/redis script file did not add the first two lines, and then execute the chkconfig redis on times wrong: service Redis does not support

The following two lines of comments must be placed in the comments in front of the/etc/init.d/redis file:

# chkconfig:2345 90 10

# Description:redis is a persistent key-value database

The comment above means that the Redis service must be started or closed under Run level 2,3,4,5, the priority of the boot is 90, and the priority of the shutdown is 10.

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.