文章目录
CentOS7安装部署Redis7
一、前言
- Linux 发行版:CentOS-7-x86_64-DVD-1804.iso
- Redis 版本:7.0.12
Redis Download:https://redis.io/download/
Redis Tag:https://github.com/redis/redis/tags
Redis入门和使用实践v2018:https://blog.csdn.net/u011424614/article/details/100170313
[Windows] Redis使用记录:https://blog.csdn.net/u011424614/article/details/101531772
CentOS基础操作命令:https://blog.csdn.net/u011424614/article/details/94555916
二、正文
1.安装部署
1)编译安装
- 创建安装目录
cmd
mkdir /opt/redis
cd /opt/redis
- 下载
cmd
wget https://github.com/redis/redis/archive/7.0.12.tar.gz
- 解压
cmd
tar -zxvf 7.0.12.tar.gz
- 安装依赖软件包
cmd
yum -y install gcc automake autoconf libtool make
- 编译和安装 Redis
cmd
cd /opt/redis/redis-7.0.12
#-- 编译
make
#-- 安装
#-- 备用 make install PrREFIX=[安装位置目录]
make install
- 编译和安装后的目录:redis-7.0.12/src
2)修改配置
- 编辑
redis.conf
cmd
cd /opt/redis/redis-7.0.12
vim redis.conf
- 远程访问:注释 127.0.0.1 和 禁用保护模式
conf
# bind 127.0.0.1 -::1
protected-mode no
- 以守护进程(后台运行)的方式启动
conf
daemonize yes
3)启动
- 启动
cmd
cd /opt/redis/redis-7.0.12
./src/redis-server redis.conf
- 查找正在运行的 Redis 进程
cmd
ps -ef | grep redis
- 客户端连接
cmd
cd /opt/redis/redis-7.0.12
./src/redis-cli
- 测试
cmd
set name jotax
get name
2.开机自启动
- 新建
redis-server.service
cmd
vim /etc/systemd/system/redis-server.service
- 写入内容
cmd
[Unit]
Description=The redis-server Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/var/run/redis_6379.pid
ExecStart=/opt/redis/redis-7.0.12/src/redis-server /opt/redis/redis-7.0.12/redis.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
- 启动服务,并设置开机自启动
cmd
systemctl daemon-reload
systemctl start redis-server.service
systemctl enable redis-server.service
- 查询 Redis 进程状态
cmd
systemctl status redis-server.service