美文网首页
Redis5.0.8 副本模式安装部署手册

Redis5.0.8 副本模式安装部署手册

作者: 葬花逐流 | 来源:发表于2021-12-18 14:03 被阅读0次

Redis5.0.8 副本模式安装部署手册

1.基础环境

  • 软件版本:centos7.8 、redis5.0.8
  • 节点1 IP地址 192.168.0.1
  • 节点2 IP地址 192.168.0.2
  • 资源:需要2台虚拟机

2.Redis 副本模式离线安装

单机Redis虽然能够将数据持久化到磁盘上,重启的时候能够将数据读入内容中,但是磁盘损坏无法避免,Redis副本模式很好的解决了防止数据丢失这个问题。

1.编译源码

下载源码包 redis-5.0.8.tar.gz,解压缩并编译:

# 解压源码包
tar -xzvf redis-5.0.8.tar.gz

# 进入Redis源码文件夹
cd redis-5.0.8

# 编译(编译依赖gcc,需要事先安装,安装命令是yum install gcc-c++ -y)
make

# 测试(测试依赖tcl,需要事先安装,安装命令是yum install tcl)
make test

2.修改默认配置项

  • 主节点修改默认端口、改为后台运行、进程号文件、日志文件、数据文件
  • 从节点修改默认端口、改为后台运行、进程号文件、日志文件、数据文件、指定主节点

主节点配置内容:

#bind 127.0.0.1
port 6379
daemonize yes
logfile /opt/log/redis-5.0.8/6379.log
dbfilename dump-6379.rdb
dir /opt/data/redis-5.0.8/
protected-mode yes
requirepass beijing

从节点配置内容:

#bind 127.0.0.1
port 6379
daemonize yes
logfile /opt/log/redis-5.0.8/6379.log
dbfilename dump-6379.rdb
dir /opt/data/redis-5.0.8/
replicaof 192.168.31.128 6379
masterauth beijing
protected-mode yes
requirepass beijingslave

3.启动 Redis

3.1 添加启动 redis 的账户

#添加 nologin 用户
groupadd opr
useradd opr -M -s /sbin/nologin -g opr

#创建 redis 需要的目录
mkdir -p /opt/data/redis-5.0.8
mkdir -p /opt/log/redis-5.0.8

#将这些目录拥有者指定为 nologin 用户
chown -R opr:opr /opt/data/redis-5.0.8
chown -R opr:opr /opt/log/redis-5.0.8
chown -R opr:opr /usr/local/redis-5.0.8

将 redis 服务添加为开机自动启动服务

vi /usr/lib/systemd/system/redis-5.0.8.service

添加以下内容

[Unit]
Description=The redis service
After=syslog.target network.target remote-fs.target nss-lookup.target
After=network-online.target
Wants=network-online.target

[Service]
User=opr
Group=opr
LimitNOFILE=30050
Type=forking
ExecStart=/usr/local/redis-5.0.8/src/redis-server /usr/local/redis-5.0.8/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target
# 添加或修改配置文件后,需要重新加载
systemctl daemon-reload
#设置开机自启动,实质就是在 /etc/systemd/system/multi-user.target.wants/ 添加服务文件的链接
systemctl enable redis-5.0.8

最后不要忘记在防火墙上开放 6379/TCP 端口。

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

重启服务器

reboot

验证

在主服务上添加一个key

SET order_1 20200721001

在从服务上查看是否同步

GET order_1

到此,关于redis 副本模式如何搭建就到此总结完毕了。

相关文章

网友评论

      本文标题:Redis5.0.8 副本模式安装部署手册

      本文链接:https://www.haomeiwen.com/subject/hlrgfrtx.html