Redis boot background automatic start 1, first download and install Centos install Redis and configure boot 1234567 wgethttp: redis.googlecode.comfilesredis-2.2.13.tar.gztar-zxfredis-2.2.13.tar.gz cdredis-2.2.13makesudomakeinstallcpredis.confetcin
Redis boot background automatic start 1, first download and install Centos install Redis and configure boot 1 2 3 4 5 6 7 wgethttp: // redis .googlecode.com/files/redis-2. 2.13. tar. gz tar-zxfredis-2.2.13. tar. gz cd redis-2.2.13 make sudo make install cp redis. conf/etc in
Redis automatically starts when it is started
1. First download and installInstall Redis in Centos and configure startup
1 2 3 4 5 6 7 |
wget http://redis.googlecode.com/files/redis-2.2.13.tar.gz
tar -zxf redis-2.2.13.tar.gz
cd redis-2.2.13
make
sudo make install
cp redis.conf /etc
|
During the install, The redis command will be copied to/usr/local/bin.
2. Create a user and log directory
Before starting Redis for the first time, we recommend that you create a separate user for Redis and create a new data and log folder.
1 2 3 4 5 |
sudo useradd redis
sudo mkdir -p /var/lib/redis
sudo mkdir -p /var/log/redis
sudo chown redis.redis /var/lib/redis # Put the db file here and modify redis. conf
sudo chown redis.redis /var/log/redis
|
3. Configure the init script
In fact, many startup scripts written by foreigners on github, but most of them are ubuntu. For Centos, there is also a copy
Https://gist.github.com/1335694
My modifications are as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# Chkconfig: 2345 90 10 # Description: Redis is a persistent key-value database PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis.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
if [ "$?"="0" ]
then
echo "Redis is running..."
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$REDIS_CLI -p $REDISPORT SHUTDOWN
while [ -x ${PIDFILE} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
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 the above Code as redis and put it under/etc/init. d /.
1 |
chmod +x /etc/init.d/redis
|
In fact, when a service is started, it also calls redis-server. If you want it to run as a daemon in the background
Modify redis. conf to change "daemonize no" to "daemonize yes ".
4. Set the startup Service
1 |
sudo chkconfig redis on
|
5. Start and Stop redis
Start:
1 |
service redis start # Or/etc/init. d/redis start
|
Stop:
1 |
service redis stop # Or/etc/init. d/redis stop
|
6. Test redis
1 2 3 4 5 6 |
redis-cli
redis 127.0.0.1:6379> set foo 123
OK
redis 127.0.0.1:6379> get foo
"123"
redis 127.0.0.1:6379> exit
|
Original article address: Automatic startup (switch) in the background of redis startup. Thank you for sharing it with the original author.