jfinal网站开发,昆明网站建设seo公司哪家好,网站空间在哪里买,网站seo优化要怎么做VRRP 通信原理#xff1a; VRRP就是虚拟路由冗余协议#xff0c;它的出现就是为了解决静态路由的单点故障。 VRRP是通过一种竞选的一种协议机制#xff0c;来将路由交给某台VRRP路由。 VRRP用IP多播的方式#xff08;多播地址224.0.0.18#xff09;来实现高可用的通信 VRRP就是虚拟路由冗余协议它的出现就是为了解决静态路由的单点故障。 VRRP是通过一种竞选的一种协议机制来将路由交给某台VRRP路由。 VRRP用IP多播的方式多播地址224.0.0.18来实现高可用的通信工作时主节点发包备节点接收包当备节点接收不到主节点发的数据包时候就启动接管主节点的资源备节点可以有多个通过优先级来进行竞选但一般keepalived系统运维工作时一对。 VRRP使用加密协议加密数据但keepalive官方目前还是推荐用明文的方式认证类型和密码。 Keepalived 是一个基于VRRP协议来实现的LVS服务高可用方案可以解决静态路由出现的单点故障问题。
在一个LVS服务集群中通常有主服务器MASTER和备份服务器BACKUP两种角色的服务器但是对外表现为一个虚拟IP主服务器会发送VRRP通告信息给备份服务器当备份服务器收不到VRRP消息的时候即主服务器异常的时候备份服务器就会接管虚拟IP继续提供服务从而保证了高可用性。
Keepalived体系主要模块及其作用 keepalived体系架构中主要有三个模块分别是core、check和vrrp。 ●core模块为keepalived的核心负责主进程的启动、维护及全局配置文件的加载和解析。 ●vrrp模块是来实现VRRP协议的。 ●check模块负责健康检查常见的方式有端口检查及URL检查。
以下实验使用LVS-DRkeepalived的抢占模式实现高可用负载群集
Web 服务器120.0.0.101VIP 20.0.0.10
Web 服务器220.0.0.102VIP 20.0.0.10NFS 共享存储器20.0.0.103LVSkeepalived 主负载调度器20.0.0.104VIP 20.0.0.10)LVSkeepalived 备负载调度器20.0.0.105VIP 20.0.0.10网关/路由器20.0.0.2
客户端192.168.116.50一、配置NFS共享存储
systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0yum -y install nfs-utils rpcbind
mkdir /opt/nfs/server1 /opt/nfs/server2
chmod -R 777 /opt/nfsvim /etc/exports
/opt/nfs 20.0.0.0/24(rw,sync)
/opt/nfs/server1 20.0.0.0/24(rw,sync)
/opt/nfs/server2 20.0.0.0/24(rw,sync)systemctl restart rpcbind.service
systemctl restart nfs.service检查发布的共享策略
showmount -e
在共享目录中添加web测试页面
mkdir /opt/nfs/server1 server2
echo this is web-01 /opt/nfs/server1/index.html
echo this is web-02 /opt/nfs/server2/index.html
检查一下是否写入成功
cat /opt/nfs/server1/index.htmlcat
cat /opt/nfs/server2/index.html二.配置节点web服务20.0.0.101 20.0.0.102两台的配置相同
【安装 Nginx 服务】
1、安装依赖包
yum -y install pcre-devel zlib-devel gcc gcc-c make2、创建运行用户
useradd -M -s /sbin/nologin nginx3、编译安装
cd /opt
tar zxvf nginx-1.22.0.tar.gz -C /opt/cd nginx-1.22.0/
./configure \
--prefix/usr/local/nginx \
--usernginx \
--groupnginx \
--with-http_stub_status_modulemake -j 4 make install4、优化路径
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/5、添加 Nginx 系统服务
vim /lib/systemd/system/nginx.service
[Unit]
Descriptionnginx
Afternetwork.target
[Service]
Typeforking
PIDFile/usr/local/nginx/logs/nginx.pid
ExecStart/usr/local/nginx/sbin/nginx
ExecReload/bin/kill -s HUP $MAINPID
ExecStop/bin/kill -s QUIT $MAINPID
PrivateTmptrue
[Install]
WantedBymulti-user.target[Unit]这个部分定义了服务单元的元数据。
Description: 描述该服务单元的信息描述为nginx。
After: 定义服务单元所依赖的其他单元这里表示服务需要在网络加载完成之后启动。[Service]这个部分定义了服务的运行配置。
Type: 指定服务的类型这里是forking表示服务是一个后台进程通常是fork出子进程。
PIDFile: 指定保存主进程ID的文件路径Nginx将会把主进程ID写入这个文件以便Systemd可以追踪和管理进程。
ExecStart: 指定启动服务的命令。这里是启动Nginx的命令/usr/local/nginx/sbin/nginx。
ExecReload: 指定重新加载配置的命令。当执行此命令时Systemd将发送HUP信号给主进程Nginx将重新加载配置文件。
ExecStop: 指定停止服务的命令。当执行此命令时Systemd将发送QUIT信号给主进程Nginx将优雅地停止服务。
PrivateTmp: 将此项设置为true表示为服务提供独立的临时目录。[Install]这个部分定义了服务的安装配置。
WantedBy: 指定服务所属的目标target这里是multi-user.target表示服务在多用户模式下启动。chmod 777 /lib/systemd/system/nginx.service
systemctl start nginx.service
systemctl enable nginx.service查看nginx服务是否启动netstat -antp | grep 80将网站根目录挂载到各自的共享目录
首先打开nfs服务
systemctl restart rpcbind.service
systemctl restart nfs.servicemount 20.0.0.103:/opt/nfs/server1 /usr/local/nginx/html/
mount 20.0.0.103:/opt/nfs/server2 /usr/local/nginx/html/在web01 -02上查看是否共享成功cat /usr/local/nginx/html/index.html
cat /usr/local/nginx/html/index.html设置回环网卡虚拟ipweb-01 web-02都要设置cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifcfg-lo:0vim /etc/sysconfig/network-scripts/ifcfg-lo:0
DEVICElo:0
IPADDR20.0.0.10
NETMASK255.255.255.255
ONBOOTyes~ ifup lo:0 配置回环网卡完成后
ifconfig 查看一下是否配置成功添加静态路由将数据包封锁在回环网卡中#临时配置
route add -host 20.0.0.10 dev lo:0#永久配置
vim /etc/rc.local
/sbin/route add -host 20.0.0.10 dev lo:0
chmod x /etc/rc.d/rc.local调整内核的ARP响应参数阻止更新VIP的MAC地址防止发生冲突vim /etc/sysctl.conf
#添加
net.ipv4.conf.lo.arp_ignore 1
net.ipv4.conf.lo.arp_announce 2
net.ipv4.conf.all.arp_ignore 1
net.ipv4.conf.all.arp_announce 2#加载配置文件并查看
sysctl -p三、配置主备LVSkeepalived负载调度器keepalived-01 keepalived-02关闭防火墙下载keepalived和ipvsadm并修改内核参数systemctl stop firewalld.service 。
systemctl disable firewalld.service
setenforce 0modprobe ip_vs
yum -y install ipvsadm keepalivedvim /etc/sysctl.conf
net.ipv4.ip_forward 0
net.ipv4.conf.all.send_redirects 0
net.ipv4.conf.default.send_redirects 0
net.ipv4.conf.ens33.send_redirects 0sysctl -p
修改主负载器配置文件
cd /etc/keepalived/
cp keepalived.conf keepalived.conf.bak #改配置文件前先备份
vim keepalived.confglobal_defs {notification_email {acassenfirewall.locfailoverfirewall.locsysadminfirewall.loc}notification_email_from Alexandre.Cassenfirewall.locsmtp_server 127.0.0.1smtp_connect_timeout 30router_id LVS_01#vrrp_skip_check_adv_addr#vrrp_strict#vrrp_garp_interval 0#vrrp_gna_interval 0
}vrrp_instance VI_1 {state MASTERinterface ens33virtual_router_id 51priority 100advert_int 1authentication {auth_type PASSauth_pass abc123}virtual_ipaddress {20.0.0.10}
}virtual_server 20.0.0.10 80 {delay_loop 6lb_algo rrlb_kind DRpersistence_timeout 10protocol TCPreal_server 20.0.0.101 80 {weight 1TCP_CHECK {connect_port 80connect_timeout 3nb_get_retry 3delay_before_retry 3
}
}
real_server 20.0.0.102 80 {weight 1TCP_CHECK {connect_port 80connect_timeout 3nb_get_retry 3delay_before_retry 3
}
}
}
修改备负载器配置文件与主配置一致只需修改以下部分 global_defs {notification_email {acassenfirewall.locfailoverfirewall.locsysadminfirewall.loc}notification_email_from Alexandre.Cassenfirewall.locsmtp_server 127.0.0.1smtp_connect_timeout 30router_id LVS_02#vrrp_skip_check_adv_addr#vrrp_strict#vrrp_garp_interval 0#vrrp_gna_interval 0
}vrrp_instance VI_1 {state BACKUPinterface ens33virtual_router_id 51priority 90advert_int 1authentication {auth_type PASSauth_pass abc123}virtual_ipaddress {20.0.0.10}
}virtual_server 20.0.0.10 80 {delay_loop 6lb_algo rrlb_kind DRpersistence_timeout 10protocol TCPreal_server 20.0.0.101 80 {weight 1TCP_CHECK {connect_port 80connect_timeout 3nb_get_retry 3delay_before_retry 3
}
}
real_server 20.0.0.102 80 {weight 1TCP_CHECK {connect_port 80connect_timeout 3nb_get_retry 3delay_before_retry 3
}
}
}
启动keepalived再启动ipvsadmipvsadm会自动加载keepslived中的配置systemctl restart keepalived.service
ipvsadm-save /etc/sysconfig/ipvsadm#启动ipvsadm 分别添加主备负载均衡器VIP 的分发策略
systemctl restart ipvsadm.serviceipvsadm -C ##清空规则
ipvsadm -A -t 20.0.0.10:80 -s rr
ipvsadm -a -t 20.0.0.10:80 -r 20.0.0.101:80 -g
ipvsadm -a -t 20.0.0.10:80 -r 20.0.0.102:80 -g查看主负载和副负载均衡器
ipvsadm -ln访问20.0.0.10
可以将主负载器服务停止或关机模拟宕机继续访问 20.0.0.10查看主备切换是否正常脑裂现象的解释和解决办法 1.解释 在抢占模式中MASTER需要定时发送报文通告BACKUP自己仍在运作但是当MASTER还在运作但其中的线路或交换机等出现故障导致BACKUP不能收到通告时会认为MASTER已经失效此时BACKUP抢占VIP会导致VIP同时存在这就是脑裂现象。
2.解决方法 1.主备服务器之间使用双链路通信 2. 通过脚本来实时监控主备的网络状态然后再根据脚本逻辑采取措施关掉主服务器的keepalived服务器