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.
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:
To start the test:
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:
Shutdown reboot test:
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.