按照如下操作即可(可以自定义目录)
mkdir /redis
cd /redis
wget http://download.redis.io/releases/redis-4.0.1.tar.gz
tar xzf redis-4.0.1.tar.gz
cd redis-4.0.1
make
cd redis-4.0.1 可以看见此目录下有一个redis.conf
我们将 redis.conf 修改为
mv redis.conf 6379.conf 好处是接下来我们的启动脚本中比较好指定配置文件
开启进程
./src/redis-server 6379.conf
指定端口号进行客户端的连接
./src/redis-cli -p 6379
*********************************************************************************************
设置开机启动 (utils 目录下的redis_init_script 为自带的启动脚本)
cp ./utils/redis_init_script /etc/init.d/redisd6379
vim /etc/init.d/redisd6379 (将之前脚本清空,将以下脚本加入redisd6379即可) 这只是6379 设置开机启动 如果想设置6380、6381 则需要复制多个脚本
#!/bin/sh
#chkconfig: 2345 90 10
#description: Redis is a persistent key-value database
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/redis/redis-4.0.1/src/redis-server #此目录根据安装路径设置
CLIEXEC=/redis/redis-4.0.1/src/redis-cli #此目录根据安装路径设置
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/redis/redis-4.0.1/${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
chkconfig redisd6379 on 设置开机自动启动
service redisd start 打开服务
service redisd stop 关闭服务