一顿操作,下载安装,启动,删除安装包
#下载到local下
cd /usrl/local
wget http://download.redis.io/releases/redis-4.0.9.tar.gz
#解压安装包
tar xzf redis-4.0.9.tar.gz
cd redis-4.0.9
#编译安装
make
sudo make install
#使用默认配置启动redis
./src/redis-server ../redis.conf
#删除安装包
cd ..
rm redis-4.0.9.tar.gz
其他常用命令
停止redis
./src/redis-cli -h 127.0.0.1 -p 6379 shutdown
设置了密码停止
./src/redis-cli -a "密码" -h 127.0.0.1 -p 6379 shutdown
直接用默认文件启动,会出现界面,而且窗口不能关闭,换一种方式
#复制一份配置文件
cd /usr/local/redis-4.0.9
cp redis.conf ./use.conf
vim use.conf
将daemonize 配置成yes 作为守护进程运行
保存之后,指定配置文件启动
./src/redis-server ./use.conf
使用客户端连接redis,连接之后,如果有密码要加上后面那句
redis.cli -p 127.0.0.1 -h 6319
auth 密码
在redis-4.0.9下面发现了一个utils目录,进去一看发现有惊喜,里面有个redis_init_script
的脚本,里面定义了开启和关闭的脚本。稍微修改下
#!/bin/sh./src/redis-cli -h 127.0.0.1 -p 6379 shutdown
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
#CONF="/etc/redis/${REDISPORT}.conf"
CONF="/usr/local/redis-4.0.9/use.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 -a "123456" -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -a "123456" -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
然后将此文件复制到外层
cp redis_init_script ../redis.sh
接下来启动,停止,重启就变成下面这样了
由于每次连接redis去测试都要
redis -cli -a 密码 -h 127.0.0.1 -p 6379
,觉得比较麻烦,所以在创建了个连接脚本。
cd /
mkdir script
cd script
vim redis-connect.sh
编写脚本如下:
#!/bin/bash
cd /usr/local/redis-4.0.9
redis-cli -a 123456 -h 127.0.0.1 -p 6379
接下来就是自由发挥时间了。。。