![](https://i-blog.csdnimg.cn/blog_migrate/f84c647591f3b3670b2191debf318eb6.png)
1、安装依赖包
yum install -y gcc
2、下载安装包
wget http://download.redis.io/releases/redis-5.0.3.tar.gz
3、解压安装包-我这里是/data目录
tar -zxvf redis-5.0.3.tar.gz
4、切换到目录
cd redis-5.0.3
5、编译
make
6、安装-可指定目录-我这里是/data目录
make install PREFIX=/data/redis
7、拷贝并修改配置文件
cp /data/redis-5.0.3/redis.conf /data/redis/bin/
把 daemonize no 改为 daemonize yes,表示支持后台运行redis。
# 日志路径自定义
logfile "/data/redis/logs/redis.log"
#设置redis密码-我设置的123456
requirepass 123456
8、启动和停止redis -当前目录/data/redis/bin/
启动服务:./redis-server redis.conf
停止服务:ps -ef|grep redis 拿到redis进程号,redis默认端口6379,一眼可以区分redis进程。
kill -9 redis进程号
--------------------------------------------------------------------------------
设置redis开启启动、注册服务-没兴趣就算了
--------------------------------------------------------------------------------
1、开机启动 -添加一个redis脚本
vim /etc/init.d/redis
内容:
#!/bin/bash
# chkconfig: 2345 10 90
# description: Start and Stop redis
# path路径
PATH=$PATH
# redis IP
REDISIP=192.168.100.107
# redis 端口
REDISPORT=6379
# redis server、client路径
EXEC=/data/redis/bin/redis-server
REDIS_CLI=/data/redis/bin/redis-cli
# redis 进程号
PIDFILE=/var/run/redis_6379.pid
# redis 配置文件路径
CONF="/data/redis/bin/redis.conf"
# start 、stop、restart
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 exists, process is not running."
else
PID=$(cat $PIDFILE)
echo "Stopping..."
$REDIS_CLI -h $REDISIP -p $REDISPORT SHUTDOWN
sleep 2
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/redis {start|stop|restart|force-reload}" >&2
exit 1
esac
2、给脚本一个755权限
chmod 755 /etc/init.d/redis
3、设置redis开机启动
chkconfig redis on
4、查看开机启动情况- 2345为on正常
chkconfig --list
5、测试命令
# redis状态
systemctl status redis
# 启动redis
systemctl start redis
# 停止redis
systemctl stop redis
# 重启redis
systemctl restart redis