安装包下载地址
下载安装包至安装目录
wget http://download.redis.io/releases/redis-5.0.7.tar.gz
解压安装包
tar -zxvf redis-5.0.7.tar.gz
编译
cd redis-5.0.7
make
cd src
make install
创建服务目录
mkdir /usr/local/redis
mkdir /usr/local/redis/bin
mkdir /usr/local/redis/conf
复制文件
cd redis-5.0.7
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
修改配置文件 redis.conf
# 注释掉,允许远程访问
#bind 127.0.0.1
# 关闭保护模式,允许远程访问
protected-mode no
# 启用守护进程
daemonize yes
# 密码
requirepass 123456
配置为系统服务
目录
/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