CenterOS installation of Redis and startup Settings
- 2020-05-14 05:48:39
- OfStack
Details of installing Redis in CenterOS and startup Settings
From the official download the latest Redis for installation, website address: http: / / redis io/download
$ wget http://download.redis.io/releases/redis-3.2.3.tar.gz
$ tar xzf redis-3.2.3.tar.gz
$ cd redis-3.2.3
$ make
$ make install
Redis start
RedisServer /path/to/redis.conf
Redis off (default port is 6379)
RedisCli -p port -a Password shutdown
View the Reids process
ps -ef|grep redis
Set Redis to boot
1: configure the init script, save the code as Reids and put it in /etc/ init.d /
###########################
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
PATH=/usr/local/bin
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
#Redis password
PASSWORD=yourPassword
PIDFILE=/var/run/redis.pid
CONF="/usr/local/reids/conf/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 -a $PASSWORD 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
##############################
Matters needing attention:
1) the top comment means that the redis service must be started or shut down at runlevels 2, 3, 4, and 5, with a startup priority of 90 and a shutdown priority of 10.
2) if $'/r':command not found appears in the execution of the command, the problem is that line feed under Windows is different from line feed under linux, which can be converted through Nodepad++.
2: set script permissions
chmod +x /etc/init.d/redis
3: set to boot
sudo chkconfig redis on
4: method of use
service redis start # or /etc/init.d/redis start
service redis stop # or /etc/init.d/redis stop
Thank you for reading, I hope to help you, thank you for your support of this site!