第一步:下载redis 包
1.进入/usr/(myRedis)自定义目录
2. wget http://download.redis.io/releases/redis-4.0.9.tar.gz
3.解压2步骤中下载的文件
tar -zxvf redis-4.0.9.tar.gz
4.进入解压后的文件
5.make && make install
(如果没有找到 生成的redis文件夹,用这个命令 生成一个 软连接 ln -s /usr/myRedis/redis-4.0.9/bin /usr/local/redis/)
6. cp /usr/myRedis/redis-4.0.9/redis.conf /usr/local/redis/
7.编辑redis下的redis.conf 配置项
修改四个配置:
daemonize yes #守护进程
appendonly yes #开启aof持久化
appendfsync everysec
bind 0.0.0.0 #开启远程访问 或者这里直接注释也行
requirepass 设置自己的密码,(你可以不设置)
8.重头戏来了 进入/etc/init.d/ 如果没有发现redis 就创建一个 redisd或redis都行(vim redisd)并将以下代码复制进去:
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis/bin/redis.conf"
AUTH="YU@song1314"
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
if [ "$?"="0" ]
then
echo "Redis is running..."
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$REDIS_CLI -a $ATUTH -p $REDISPORT SHUTDOWN
while [ -x ${PIDFILE} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/redisd {start|stop|restart|force-reload}" >&2
exit 1
esac
9.重新载入
systemctl daemon-reload
10.开机启动
systemctl enable redis
11.操作直接在/etc/init.d 目录下 运行./redisd start(stop,restart 等都可以进行启动,关闭,重启操作) 或者 直接systemctl start(stop,restart) redisd 也可以