In Linux, when a program is configured as a service, you can use service commands to manage system services such as start (start), ( stop stop), restart (restart), and so on. The Redis default is not configured as a system service after installation, this article describes the methods that are Redis configured as services.
- Copying
redis_init_script files
- Edit
redis File
- Registering System Services
rc.localand service Service
1. Copying
redis_init_scriptFile
Copy the files to the utils/redis_init_script /etc/rc.d/init.d/ directory and rename them as redis :
CP Utils/redis_init_script/etc/rc.d/init.d/redis
Note: The above command needs to be executed in the Redis root directory of the source code. The redis_init_script file is a Redis provided initialization script that can be Reids源码/utils found under the directory.
2. Editing
redisFile
To edit a /etc/rc.d/init.d/redis file:
In the second line of the file, add:
# chkconfig:2345 80 90
And will take the following line ( start under node):
$EXEC $CONF
Modified to:
$EXEC $CONF &
Note: The & service will be run in the background, not add this symbol redis will be displayed in the foreground, and affect the start of other services.
Confirm the installation directory
The following two lines in the file are the Redis default directories for the installation. If the actual installation directory does not match the next two lines, modify it to the actual installation directory.
Exec=/usr/local/redis/bin/redis-server CLIEXEC=/USR/LOCAL/REDIS/BIN/REDIS-CLI
Copying conf files
The file has the following line:
conf= "/etc/redis/${redisport}.conf"
The row represents the Redis location of the configuration file redis.conf and is ${REDISPORT} .conf named for the Redis run port.
The file location should be the same as the actual location, for example, after installing Redis, I redis.conf placed the file in a /etc/redis.conf location, so modify it as follows:
conf= "/etc/redis.conf"
Of course, you can also not modify this line, you need to create and /etc/redis copy the configuration file to this directory. Execute the following two commands, respectively:
MKDIR/ETC/REDISCP redis.conf/etc/redis/6379.conf
3. Registering System Services
Register the system service using the chkconfig command. The Registration redis Service command is as follows:
Start the redis service:
Service Redis Start
The configuration is complete and the service can now be service managed by command redis .
4.
rc.localAnd
serviceService
In another article, I used rc.local the way to add Redis the boot up. It should be noted at this point that you should first remove the rc.local Redis boot configuration in and stop and Redis then service start the service by naming it redis .
A system service configured to a rc.d directory whose start priority is higher than rc.local the level of service, and the user can flexibly choose between the two according to their needs.
For more information on "Linux program startup priority" Please refer to: Précis-writers Linux boot script execution sequence and program run level
Article turned from: http://itbilu.com/linux/management/NkbXG9kol.html
Turn: Redis configured as Service system services