#!/bin/sh # chkconfig: 2345 10 90 # description: Start and Stop redis REDISPORT=6379 EXEC=/usr/local/redis/src/redis-server CLIEXEC=/usr/local/redis/src/redis-cli PIDFILE=/var/run/redis_$ { REDISPORT } .pid CONF="/etc/redis.conf" case"$1"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 is not running" else PID=$(cat$PIDFILE) echo"Stopping ..." $CLIEXEC -p $REDISPORT shutdown while [ -x /proc/$ { PID } ] do echo"Waiting for Redis to shutdown ..." sleep 1 done echo"Redis stopped" fi; ; restart) "$0" stop sleep 3 "$0" start; ; *) echo"Please use start or stop or restart as first argument"; ; esac
[root@localhost ~]# service redis start [root@localhost ~]# service redis restart [root@localhost ~]# service redis stop
13. 远程访问
在/etc/redis.conf文件中修改:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
################################## NETWORK ##################################### # By default, if no "bind" configuration directive is specified, Redis listens # for connections from all the network interfaces available on the server. # It is possible to listen to just one or multiple selected interfaces using # the "bind" configuration directive, followed by one or more IP addresses. # # Examples: # # bind 192.168.1.100 10.0.0.1 # bind 127.0.0.1 ::1
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the # internet, binding to all the interfaces is dangerous and will expose the # instance to everybody on the internet. So by default we uncomment the # following bind directive, that will force Redis to listen only into # the IPv4 loopback interface address (this means Redis will be able to # accept connections only from clients running into the same computer it # is running). # # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES # JUST COMMENT THE FOLLOWING LINE. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # bind 127.0.0.1 bind 0.0.0.0