Linux 下 redis 集群部署

目录

[1. redis下载](#1. redis下载)

[2. 环境准备](#2. 环境准备)

[3. redis部署](#3. redis部署)

[3.1 修改系统配置文件](#3.1 修改系统配置文件)

[3.2 开放端口](#3.2 开放端口)

[3.3 安装 redis](#3.3 安装 redis)

[3.4 验证](#3.4 验证)


本文将以三台服务器为例,介绍在 linux 系统下redis的部署方式。

1. redis下载

下载地址:Index of /releases/

选择需要的介质下载,这里以 redis-5.0.14.tar.gz 为例

2. 环境准备

部署redis 需要有gcc 环境 ,所以首先进行gcc 环境验证。出现以下信息说明已存在gcc 环境。

复制代码
[root@localhost ~]# gcc -v 

3. redis部署

注:以下操作三台机器均需要修改

3.1 修改系统配置文件

(1)编辑 hosts 文件

vi /etc/hosts

添加如下内容

ip(第一台机器) redis1

ip(第二台机器) redis2

ip(第三台机器) redis3

3.2 开放端口

redis 默认需要开通节点 6379 和 6380 端口

(1)查看防火墙状态

systemctl status firewalld

(2)开放端口

firewall-cmd --zone=public --add-port=6379/tcp --permanent

firewall-cmd --zone=public --add-port=6380/tcp --permanent

(3)防火墙重新加载配置

firewall-cmd --reload

(4) 查看防火墙所有开放的端口

firewall-cmd --zone=public --list-ports

3.3 安装 redis

(1) 解压

上传 redis 介质( redis-5.0.14.tar.gz)到 /opt 目录

解压到当前目录下

tar zxfv redis-5.0.14.tar.gz

(2) 编译安装

cd redis-5.0.14

make && make install PREFIX=/usr/local/redis

(3)创建数据目录

mkdir -p /data/redis/6379

mkdir -p /data/redis/6380

(4) 创建 redis.conf 配置文件

touch /data/redis/6379/redis.conf

vi /data/redis/6379/redis.conf

复制代码
#端口
port 6379
#非保护模式
protected-mode no
#后台运行
daemonize yes
#启用集群模式
cluster-enabled yes
#超时时间
cluster-node-timeout 5000
appendonly yes
pidfile  /var/run/redis_6379.pid
cluster-config-file nodes.conf
dir /data/redis/6379/
tcp-keepalive 60
#配置密码(123456)
requirepass 123456
masterauth 123456
#内存设置单位为字节
maxmemory  6291456000

touch /data/redis/6380/redis.conf

vi /data/redis/6380/redis.conf

复制代码
#端口
port 6380
#非保护模式
protected-mode no
#后台运行
daemonize yes
#启用集群模式
cluster-enabled yes
#超时时间
cluster-node-timeout 5000
appendonly yes
pidfile  /var/run/redis_6380.pid
cluster-config-file nodes.conf
dir /data/redis/6380/ 
tcp-keepalive 60
#配置密码(123456)
requirepass 123456
masterauth 123456
#内存设置单位为字节
maxmemory  6291456000

(5)启动

复制代码
/usr/local/redis/bin/redis-server /data/redis/6379/redis.conf
/usr/local/redis/bin/redis-server /data/redis/6380/redis.conf
3.4 验证

(1)创建 redis 集群

复制代码
/usr/local/redis/bin/redis-cli  --cluster create  \
IP:6379  IP:6380  IP:6379  \
IP:6380  IP:6379  IP:6380  \
--cluster-replicas 1 -a 123456

注:其中IP为三台机器的IP,检查集群配置并输入****yes

(2)检测 redis 集群

复制代码
/usr/local/redis/bin/redis-cli --cluster check {任意一台机器IP}:6379 -a 123456
/usr/local/redis/bin/redis-cli --cluster check {任意一台机器IP}:6380 -a 123456

以下状态说明集群正常

相关推荐
轻松Ai享生活1 小时前
5 节课深入学习Linux Cgroups
linux
christine-rr2 小时前
linux常用命令(4)——压缩命令
linux·服务器·redis
三坛海会大神5552 小时前
LVS与Keepalived详解(二)LVS负载均衡实现实操
linux·负载均衡·lvs
東雪蓮☆2 小时前
深入理解 LVS-DR 模式与 Keepalived 高可用集群
linux·运维·服务器·lvs
qq_264220892 小时前
LVS负载均衡群集和LVS+Keepalived群集
运维·负载均衡·lvs
乌萨奇也要立志学C++3 小时前
【Linux】进程概念(二):进程查看与 fork 初探
linux·运维·服务器
雨落Liy3 小时前
Nginx 从入门到进阶:反向代理、负载均衡与高性能实战指南
运维·nginx·负载均衡
Yyyy4823 小时前
Nginx负载均衡集群实验步骤
运维·nginx·负载均衡
凯子坚持 c3 小时前
精通 Redis list:使用 redis-plus-plus 的现代 C++ 实践深度解析
c++·redis·list
weixin_456904273 小时前
跨域(CORS)和缓存中间件(Redis)深度解析
redis·缓存·中间件