一、安装
1. 官方推荐方式安装
redis官网链接https://redis.io/download
wget http://download.redis.io/releases/redis-5.0.5.tar.gz -c (-c后边跟要下载到的文件夹)
2. 解压 & 编译
解压,首先cd到[解压]目录,执行make
tar xzf redis-5.0.5.tar.gz
cd redis-5.0.5
make
二、设置开机启动
注意:复制时请把把中文注释去掉,不然会报错
#!/bin/sh
# chkconfig: 2345 10 90
# description: Start and Stop redis
REDISPORT=6379 # 默认端口
EXEC=/usr/local/redis-5.0.5/src/redis-server # 更换路径
CLIEXEC=/usr/local/redis-5.0.5/src/redis-cli # 更换路径
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis-5.0.5/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
授权设置
chmod 777 /etc/init.d/redis
设置开机启动 on换成off是关闭
chkconfig redis on
启动redis服务 start换成stop是关闭服务
service redis start
启动后,重新打开一个ssh,测试下redis数据库
cd到安装目录下
[root@instance redis-5.0.5] src/redis-cli
127.0.0.1:6379> set name xiaoming
OK
127.0.0.1:6379> get name
"xiaoming"
127.0.0.1:6379>
如果我的文章帮助了您,请在右上角为我点个赞,谢谢!