Detailed CENTOS7 Configure the Redis and boot from _redis

Source: Internet
Author: User
Tags redis sleep redis server

This article mainly introduces the CENTOS7 configuration Redis and boot, with a certain reference value, interested in the small partners can refer to.

Recently in doing homework need to use the Redis cache, because each restart the server needs to restart the Redis, it is annoying, so there is this blog, good, nonsense don't say much.

There are only two steps:

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

2. Write the boot from boot script

The basic principle is:

When the system boots up, it will load the script below the/etc/init.d/, usually each script file will customize the implementation of the program, if you want to start the new program, just add a custom launcher script in the directory, and then set the appropriate rules.

If here we create a new Redis script under/etc/init.d/, it will be loaded to execute the script at boot up.

Vim/etc/init.d/redis

Add the content to the script:

# chkconfig:2345 #redis服务必须在运行级2, 3,4,5 is started or closed, the priority is 90, the priority of the shutdown is 10. # Description:start and Stop redis path=/usr/local/bin:/sbin:/usr/bin:/bin export PATH redisport=6379 #端口号, which is the default if you When the installation is not the default port number, you need to modify the location of the Exec=/usr/local/redis/bin/redis-server #redis-server startup script, and if you forget you can find the redis_cli=/by finding or Whereis
USR/REDISBIN/REDIS-CLI #redis-CLI The location of the client startup script, if you forget, you can find Pidfile=/run/redis.pid #这个也可以用find或whereis找到  
        conf= "/usr/local/redis/etc/redis.conf" #redis. conf configuration file location, if you forget you can use Find or whereis found 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, the process 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 shut  
    Down ... "Sleep 1 did 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

Save exit after writing

To set executable permissions:

chmod 755 Redis

To start the test:

/etc/init.d/redis start

Startup success prompts you with the following information:

Starting Redis server ...
Redis is running ...

To use the REDIS-CLI test:

[Root@localhost ~]#/usr/local/redis/bin/redis-cli
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> Get foo
"bar"
127.0.0.1:6379> exit

To set the power-on self boot:

Chkconfig Redis on

Shutdown reboot test:

Reboot

After the boot can be used REDIS-CLI test, or with Ps-ef | grep Redis See if Redis is running

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.