centos7安装redis并配置
安装redis前的准备
- 关闭centos防火墙
service firewalld status # 查看防火墙状态
service stop firewalld.service # 关闭防火墙
service firewalld stop # 关闭防火墙
systemctl disable firewalld.service # 开机禁用防火墙
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
- 安装gcc
yum install gcc
- 更新gcc 防止编译失败 参考https://stackoverflow.com/questions/36327805/how-to-install-gcc-5-3-with-yum-on-centos-7-2
gcc -v #查看gcc版本
yum install centos-release-scl
yum install devtoolset-7-gcc*
enable devtoolset-7 bash
which gcc
gcc -v
安装redis 参考https://redis.io/download
- 准备新建安装redis的目录(我基本上把软件安装在opt目录下)
cd / # 进入根目录
cd opt/ # 进入opt目录下
mkdir redis # 新建redis目录
cd redis/ # 进入redis目录
- 下载redis 会把redis 下载在 /opt/redis 目录下
wget http://download.redis.io/releases/redis-6.0.4.tar.gz
- 安装
tar xzf redis-6.0.4.tar.gz # 解压
cd redis-6.0.4 # 进入解压后的目录
make MALLOC=libc # 编译并配置
cd src/ # 安装完后进入src目录
make install # 配置环境变量 就可以在任何目录通过命令启动redis了
- 启动redis
cd /opt/redis/redis-6.0.4
./src/redis-server redis.conf
- 关闭redis
CTRL + C
配置redis.conf文件
- 打开配置文件redis.conf
vim /opt/redis/redis-6.0.4/redis.conf
# 或
cd /opt/redis/redis-6.0.4
vim redis.conf
- 配置redis后台运行 将 daemonize no 改成 daemonize yes
… 省略的文本 …
################################# GENERAL #####################################
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
# daemonize no #更改前
daemonize yes #更改后
# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
… 省略的文本 …
- 配置redis protected-mode 将 protected-mode yes 改成 protected-mode no
… 省略的文本 …
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
# protected-mode yes #更改前
protected-mode no #更改后
# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379
# TCP listen() backlog.
… 省略的文本 …
- 配置redis 允许远程链接
… 省略的文本 …
IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# bind 127.0.0.1 #更改前
bind 0.0.0.0 #更改后
# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
# "bind" directive.
# 2) No password is configured.
… 省略的文本 …
- 启动redis后台运行
redis-server /opt/redis/redis-6.0.4/redis.conf
- 查看redis的进程
ps -ef|grep redis # 输入后会输出以下信息
root 37532 1 0 21:09 ? 00:00:00 redis-server 127.0.0.1:6379
root 37537 5304 0 21:09 pts/0 00:00:00 grep --color=auto redis
# 37532 为redis的进程id 每台机器可能会不一样
- 进入redis shell
redis-cli
- 关闭redis
kill -9 37532 # 37532 为redis的进程id
# 或
redis-cli shutdown
开发工具
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· DeepSeek 解答了困扰我五年的技术问题。时代确实变了!
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· 趁着过年的时候手搓了一个低代码框架
· 推荐一个DeepSeek 大模型的免费 API 项目!兼容OpenAI接口!