本文档安装包为
redis-4.0.8.tar.gz
步骤1
- 上传
redis-4.0.8.tar.gz
到指定目录,当前目录为/home/dzqd/software
步骤2
解压包
tar -zxvf redis-4.0.8.tar.gz
编译
cd redis-4.0.8
make
cd src
make install
步骤3
创建服务目录
mkdir /usr/local/redis
mkdir /usr/local/redis/bin
mkdir /usr/local/redis/conf
复制文件
cd redis-4.0.8
cp redis.conf /usr/local/redis/conf
cp src/redis-benchmark /usr/local/redis/bin
cp src/redis-check-aof /usr/local/redis/bin
cp src/redis-cli /usr/local/redis/bin
cp src/redis-server /usr/local/redis/bin
步骤4
修改配置文件
redis.conf
# 注释掉,允许远程访问
#bind 127.0.0.1
# 关闭保护模式,允许远程访问
protected-mode no
# 启用守护进程
daemonize yes
# 密码
requirepass mi_newland
步骤5
配置为系统服务
目录
/etc/init.d/redis
#!/bin/sh
# chkconfig: 2345 90 10
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli
PIDFILE=/usr/local/redis/redis.pid
CONF="/usr/local/redis/conf/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
;;
*)
echo "Please use start or stop as first argument"
;;
esac
配置生效
chkconfig --add redis
启动
service redis start