Centos 7.5安装 Redis 5.0.0
1 我的环境
1.1 linux(腾讯云)
CentOS Linux release 7.5.1804 (Core)
1.2 Redis
Redis 5.0.0
2 下载
3 上传
3.1 使用xftp上传到指定目录,我的目录为
/app/tool
4 解压到安装目录
mkdir /usr/local/redis
tar zxf redis-5.0.0.tar.gz -C /usr/local/redis/
5 安装 gcc 依赖
yum -y install gcc
6 编译
6.1 进入redis解压目录
cd /usr/local/redis/redis-5.0.0
6.2 编译
make MALLOC=libc
7 安装
7.1 进入redis/src下
cd /usr/local/redis/redis-5.0.0/src
7.2 执行安装
make install
8 配置(后台启动,设置密码,外部访问)
8.1 修改配置文件
vim /usr/local/redis/redis-5.0.0/redis.conf
进入vim
输入 /
再按火车用来搜索关键字
比如如下命令会定位到文件中出现 bind
的位置并会将关键词用颜色区分。
/bind
8.2 后台启动
搜索 daemonize no
改为 daemonize yes
daemonize no
8.3 设置密码
搜索 requirepass foobared
添加 requirepass 你设置的密码
requirepass foobared
8.4 外部访问
搜索 bind 127.0.0.1
然后注释掉
# bind 127.0.0.1
记得开放6379
端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent
firewall-cmd --reload
9 启动,停止和重启
9.1 启动
- 在任意目录执行
redis-server /usr/local/redis/redis-5.0.0/redis.conf
- 启动成功界面和进程
ps aux | grep redis
- 连接redis
在任意目录下执行redis-cli
即可连接
redis -cli
auth 密码
9.2 停止
- 未设置密码时
redis-cli shutdown
- 设置密码后,执行以下命令
redis-cli -a 密码
- 再执行停止和退出连接
shutdown
not connected> exit
9.3 重启
一般重启都是杀掉进程,再启动redis,这里就介绍一下步骤,当然也可以执行上面的停止再启动
ps aux | grep redis
[root@VM_0_9_centos /]# ps aux | grep redis
root 29228 0.0 0.1 144004 2016 ? Ssl 14:22 0:00 redis-server *:6379
root 29259 0.0 0.0 112704 972 pts/2 S+ 14:22 0:00 grep --color=auto redis
kill -9 29228
ps aux | grep redis
[root@VM_0_9_centos /]# ps aux | grep redis
root 29538 0.0 0.0 112704 968 pts/2 S+ 14:25 0:00 grep --color=auto redis
10 开机启动(可以忽略)
10.1 复制redis服务文件 redis_init_script
cp /usr/local/redis/redis-5.0.0/utils/redis_init_script /etc/init.d/redis
10.2 在 etc
下创建 redis
文件夹
mkdir /etc/redis
10.3 复制redis配置文件 redis.conf
并重命名为6379.conf
cp /usr/local/redis/redis-5.0.0/redis.conf /etc/redis/
mv /etc/redis/redis.conf 6379.conf
10.3 修改redis服务文件
vim /etc/init.d/redis
- 在/etc/init.d/redis文件的头部添加下面两行注释代码,也就是在文件中#!/bin/sh的下方添加
# chkconfig: 2345 10 90
# description: Start and Stop redis
- 指定redis的安装路径和pid文件路径
REDISPORT=6379
EXEC=/usr/local/redis/redis-5.0.0/src/redis-server # 指定的执行路径
CLIEXEC=/usr/local/redis/redis-5.0.0/src/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf" # 这里就是上面重命名的配置文件
- 若设置了密码,则需要修改
stop
脚本
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -a 你的密码 -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
- 停止输出结果
Stopping ...
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Redis stopped
10.4 现在的redis命令
- 打开redis命令
service redis start
- 关闭redis命令
service redis stop
- 设为开机启动
chkconfig redis on
- 设为开机关闭
chkconfig redis off
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了