目录
4、修改slave节点Redis配置文件(slave1和slave2配置相同)
一、Redis主从复制的搭建
1、环境准备
master节点:192.168.127.130
slave1节点:192.168.127.140
slave2节点:192.168.127.188
2、所有安装redis
一键部署redis脚本
#!/bin/bash
#关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
#安装环境
yum -y install gcc gcc-c++ make
#解压
cd /opt
tar -zxvf redis-5.0.7.tar.gz
#编译
cd /opt/redis-5.0.7/
make
make PREFIX=/usr/local/redis install
#安装redis服务
cd /opt/redis-5.0.7/utils
yum -y install expect
/usr/bin/expect <<EOF
spawn ./install_server.sh
expect "instance" {send "\r"}
expect "config" {send "\r"}
expect "log" {send "\r"}
expect "this" {send "\r"}
expect "path" {send "/usr/local/redis/bin/redis-server\r"}
expect "abort" {send "\r"}
expect eof
EOF
#创建软链接,方便启动
ln -s /usr/local/redis/bin/* /usr/local/bin
#修改配置文件
ip=`ifconfig ens33 |awk '/netmask/{print $2}'`
sed -i "s/bind 127.0.0.1/bind 127.0.0.1 $ip/" /etc/redis/6379.conf
#启动redis
/etc/init.d/redis_6379 restart
#查看是否开启
netstat -natp |grep redis
if [ $? -eq 0 ];then
echo "redis 已安装完成并启动"
else
echo "redis 未启动,请检查"
fi
3、修改Master节点
vim /etc/redis/6379.conf
bind 0.0.0.0 #70行,修改bind 项,0.0.0.0监听所有网段
daemonize yes #137行,开启守护进程
logfile /var/log/redis_6379.log #172行,指定日志文件目录
dir /var/lib/redis/6379 #264行,指定工作目录
appendonly yes #700行,开启AOF持久化功能
/etc/init.d/redis_6379 restart
4、修改slave节点Redis配置文件(slave1和slave2配置相同)
vim /etc/redis/6379.conf #配置文件位置
70 bind 0.0.0.0 #修改监听地址
137 daemonize yes #开启守护进程
172 logfile /var/log/redis_6379.log #指定日志文件目录
264 dir /var/lib/redis/6379 #指定工作目录
288 replicaof 192.168.127.130 6379 #添加主服务器地址 及端口
700 appendonly yes #开启AOF持久化功能
#保存,并启动服务
/etc/init.d/redis_6379 restart
#重启slave1节点和slave2节点redis服务