Redis的安装以及启动
2018-11-08 本文已影响0人
Okami_
安装
- 1.下载tar包
wget http://download.redis.io/releases/redis-5.0.0.tar.gz
- 2.解压
tar xvf redis-5.0.0.tar.gz
- 3.编译
# 进入到redis的目录, 执行指令make
okamideMBP:softwear root# cd redis-5.0.0
okamideMBP:redis-5.0.0 root# make
- 4.修改配置文件redis.conf
vi redis.conf
- 5.安装完成
启动
- 1.前台启动
# 进入到redis的src目录
cd /usr/local/softwear/redis/bin
# 执行脚本redis-server
redis-server
- 2.指定配置文件启动
redis-server ../redis.conf
- 2.后台启动
# 1.修改redis.conf,将daemonize 设置为yes
vi redis.conf
daemonize yes
- 3.开机启动
- 在redis的安装目录redis-5.0.0/utils下,存在一个脚本redis_init_script, 内容如下
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
#redis服务器监听的端口
REDISPORT=6379
#服务端所处位置
EXEC=/usr/local/bin/redis-server
#客户端位置
CLIEXEC=/usr/local/bin/redis-cli
#redis的PID文件位置,需要修改
PIDFILE=/var/run/redis_${REDISPORT}.pid
#redis的配置文件位置,需将${REDISPORT}修改为文件名
CONF="/etc/redis/${REDISPORT}.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
;;
*)
echo "Please use start or stop as first argument"
;;
esac
- 在/etc下创建redis目录,并把redis的脚本redis_init_script拷贝到/etc/init.d/redisd,拷贝redis的配置文件到/etc/redis/
mkdir /etc/redis
cp redis.conf /etc/redis/6379.conf
cp redis_init_script /etc/init.d/redisd
- 然后就可以直接使用service redisd start启动
#打开服务
service redisd start
#关闭服务
service redisd stop
- 设置开机
#设置为开机自启动服务器
chkconfig redisd on