Before installing the Redis service, each turn on and off need to go to the Redis directory to run the script, quite cumbersome, so try to register Redis as a system service, so you can easily do a variety of operations, the following is the specific registration service configuration:
Make Redis a service
1. Copy the Redis init script to the/ETC/RC.D/INIT.D directory
When Redis is installed by default by the above procedure, its service script is located at:
/usr/software/redis/redis-3.0.1/utils/redis_init_script
It must be copied to the/ETC/RC.D/INIT.D directory, and it is easily named Redis:
Cp/usr/software/redis/redis-3.0.1/utils/redis_init_script/etc/rc.d/init.d/redis
2. Copy the Redis configuration file to the/etc/redis/directory:
Mkdir/etc/redis
Cp/usr/software/redis/redis-3.0.1/redis.conf/etc/redis/6379.conf
In this way, the following 3 Redis service scripts require the specified conf to exist. By default, Redis does not have authentication enabled, and you can specify a verification password by turning on the requirepass of 6379.conf.
3. Change the service script for Redis
Vi/etc/rc.d/init.d/redis
#!/bin/sh
#chkconfig: 2345 8090
# simple Redis INIT.D script conceived to work on Linux systems
# as it does use of the/proc filesystem.
redisport=6379
Exec=/usr/software/redis/redis-3.0.1/src/redis-server
cliexec=/usr/software/redis/redis-3.0.1/src/redis-cli
Pidfile=/var/run/redis.pid
conf= "/etc/redis/6379.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 shutdown
While [-x/proc/${pid}]
Do
echo "Waiting for Redis to shutdown ..."
Sleep1
Done
echo "Redis stopped"
Fi
;;
*)
echo "Pleaseuse start or stop as first argument"
;;
Esac
Note: The above Red Standard section is the modified script:
1) The original document is not the content of the following line 2nd,
Reference #chkconfig:2345 80 90
2) Change the exec, cliexec, pidfile, conf parameters, set the corresponding directory values, as shown above and the previous installation is consistent.
3) Change the Redis Open command to run in the background:
$EXEC $CONF &
Notice that the "&" in the back is the meaning of moving the service to the back, or when the service is started, the Redis service will
Occupy the front desk, occupying the main user interface, resulting in other commands not being executed.
4. Change the service script for Redis
Once the above operation is complete, you can register the service:
Chkconfig--add Redis
$ service Redis Start
Starting Redis Server ...
$ PS-EF | grep Redis
Root 1269 1 009:59? 00:00:00/usr/software/redis/redis-3.0.1/src/redis-server *:6379
$ Service Redis Stop
Stopping ...
Redis stopped
1.1 Command Configuration
Add the directory of the Redis command to the system parameter path
1) Modify the profile file:
$ vi/etc/profile
In the last line add:
Exportpath= "$PATH:/usr/software/redis/redis-3.0.1/src"
2) Then apply this file:
$ ./etc/profile
3) This makes it possible to invoke the REDIS-CLI command directly, as follows:
$ REDIS-CLI
127.0.0.1:6379>