[root@gaojingbo ~]# wget http://download.redis.io/releases/redis-4.0.11.tar.gz
[root@gaojingbo ~]# tar xzf redis-4.0.11.tar.gz
[root@gaojingbo ~]# cd redis-4.0.11
[root@gaojingbo redis-4.0.11]# make
[root@gaojingbo redis-4.0.11]# echo $?
0
启动服务
[root@gaojingbo redis-4.0.11]# ./src/redis-server &
[root@gaojingbo redis-4.0.11]# ./src/redis-cli
127.0.0.1:6379>
设置服务启动脚本
[root@gaojingbo redis-4.0.11]# cd src/
[root@gaojingbo src]# vim /etc/init.d/redis
#!/bin/sh
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_6379.pid
[ $3 ] && IPH=$3 || IPH=`awk '/^bind [0-9].*/{print $2}' /etc/redis/6379.conf`
[ $2 ] && REDISPORT=$2 || REDISPORT=`awk '/^port [0-9]{4,8}/{print $2}' /etc/redis/6379.conf`
CONF="/etc/redis/6379.conf"
REDISPORT=${REDISPORT:-6379}
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 -h $IPH shutdown
rm -rf $PIDFILE
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi ;;
status)
PID=$(cat $PIDFILE)
if [ ! ${PID} ]
then
echo 'Redis is not running'
else
echo "Redis is running ($PID)"
fi;;
restart)
$0 stop
$0 start ;;
*)
echo "Please use start, stop, restart or status as first argument";;
esac
[root@gaojingbo src]# chmod +x /etc/init.d/redis
[root@gaojingbo src]# mkdir -p /etc/redis
[root@gaojingbo src]# cp /root/redis-4.0.11/redis.conf /etc/redis/6379.conf
[root@gaojingbo src]# chkconfig --add redis
[root@gaojingbo src]# chkconfig redis on
[root@gaojingbo src]# systemctl restart redis
[root@gaojingbo src]# systemctl status redis
● redis.service - LSB: start and stop redis_6379
Loaded: loaded (/etc/rc.d/init.d/redis; bad; vendor preset: disabled)
Active: active (exited) since Tue 2018-09-11 21:01:08 CST; 7s ago
Docs: man:systemd-sysv-generator(8)
安装redis
最新推荐文章于 2024-06-20 15:14:54 发布