下载
打开官网,进入下载页
https://redis.io/
找到需要的版本,获取到链接地址(点一下下载 或者 右键看下等)
wget直接下载到指定位置
解压缩
安装
进入到目录(cd)
执行 make 命令
make PREFIX=/usr/local/redis install
进入安装位置:
复制一个配置文件过来
创建启动脚本
启动脚本 传入端口号 形如
start.sh 6379 查找conf下6379的配置文件启动
start.sh
#!/bin/sh
if [ $# -ne 1 ]; then
echo "usage: $0 port"
exit -1;
fi
PORT=$1
#您可以在此处修改redis-server和conf的所在路径
REDIS_SERVER="./bin/redis-server"
REDIS_CLI="./bin/redis-cli"
REDIS_CONF="./conf/redis_$PORT.conf"
if [ ! -e $REDIS_SERVER ]; then
echo "$REDIS_SERVER does not exist!"
exit -1
fi
if [ ! -e $REDIS_CONF ]; then
echo "$REDIS_CONF does not exist!"
exit -1
fi
cmd="ps -ef | grep ${REDIS_SERVER} | grep -v grep | grep -v vim | grep -v defunct | grep '$PORT' | awk '{ print \$2 }'"
#echo $cmd
PID=$(eval ${cmd})
#echo $PID
if [ $PID"e" != "e" ]; then
echo "redis-server(port:$PORT) is running, can't start"
exit -1
else
$REDIS_SERVER $REDIS_CONF &
fi
startfail=1
for i in `seq 0 180`
do
PID=$(eval ${cmd})
#echo $PID
if [ $PID"e" != "e" ]; then
${REDIS_SERVER} --version
echo "Redis server(port:$PORT) is stared..."
startfail=0
break
fi
sleep 1
done
exit $startfail
stop.sh
#!/bin/sh
if [ $# -ne 1 ]; then
echo "usage: $0 port"
exit -1;
fi
PORT=$1
#您可以在此处修改redis-server的所在路径
REDIS_SERVER="./bin/redis-server"
cmd="ps -ef | grep ${REDIS_SERVER} | grep -v grep | grep -v vim | grep -v defunct | grep ${PORT} | awk '{ print \$2 }'"
#echo $cmd
PID=$(eval ${cmd})
if [ ${PID}"e" = "e" ]; then
echo "redis-server(port:$PORT) is not started"
exit -1
else
kill $PID
fi
stopfail=1
for i in `seq 0 30`
do
PID=$(eval ${cmd})
#echo $PID
if [ ${PID}"e" != "e" ]; then
echo "redis-server(port:$PORT) is still running, waiting to stop[${i}]..."
else
echo "redis-server(port:$PORT) is stoped"
stopfail=0
break
fi
sleep 1
done
exit $stopfail
restart.sh
#!/bin/sh
if [ $# -ne 1 ]; then
echo "usage: $0 port"
exit -1
fi
PORT=$1
./stop.sh $PORT
./start.sh $PORT
本地客户端测试成功
重新修改配置文件
去掉只有本机可以访问
默认是yes。不需要密码,修改为no
设置守护进程 修改为yes
设置密码
转载务必注明出处:程序员潇然,疯狂的字节X,https://crazybytex.com/thread-198-1-1.html |