devops 信创在数字经济时代提升企业竞争力的关键策略
729
2022-11-26
【系统部署知识汇总】第13章—— 构建高可用集群
构建Nginx⾼可⽤集群
本节内容01 ⾼可⽤介绍02keepalived安装管理03构建⾼可⽤集群04
⾼可⽤介绍 01
• 分发器宕机怎么办• 数据服务器宕机怎么办
02Keepalived
Keepalived的作⽤是检测服务器的状态,如果有1台web服务器宕机,或⼯作出现故障,Keepalived将检测到,并将有故障的服务器从系统中剔除,同时使用其他服务器代替该服务器的运作,当服务器 正常后Keepalived自动将服务器加到服务器群中,这些⼯作全部⾃动完成,不需要⼈⼯⼲涉,需要⼈⼯做的只是修复故障的服务器。
1个监控+自愈的软件
Keepalived获得
安装
#cat keepalived_install.sh#!/bin/bashpkg=keepalived-2.0.8.tar.gztar xf $pkgyum -y install kernel-develln -s /usr/src/kernels/3.10.0-862.14.4.el7.x86_64/ /usr/src/linuxcd keepalived-2.0.8/yum install openssl-* -y./configure --prefix=/usr/local/keepalivedmakemake installmkdir -pv /etc/keepalivedcp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/ln -s /usr/local/keepalived/sbin/keepalived /sbin/
03 构建⾼可⽤Nginx集群
• 实验机器: Vmware 虚拟机 2核4G• ⽹卡:桥接• 系统:centos7.5• 防⽕墙:关闭• Selinux:关闭• ⽹段:192.168.10.0/24主机名 IP ⻆⾊ 软件Master.ayitula.com 192.168.10.40 主分发器 Nginx+keepalivedBackup.ayitula.com 192.168.10.41 备分发器 Nginx+keepalivedWeb01.ayitula.com 192.168.10.42 数据服务器1 nginxWeb02.ayitula.com 192.168.10.43 数据服务器2
部署步骤
软件环境部署
1)分发器 nginx+keepalived2)数据服务器 Nginx3) 配置Nginx分发器4)配置数据服务器⻚⾯(web01 web02)5)配置keepalived.conf6)测试
配置Nginx集群
upstream web { server 192.168.10.42 max_fails=2 fail_timeout=3; server 192.168.10.43 max_fails=2 fail_timeout=3; server { listen 80; server_name localhost; location / { proxy_pass } }
配置keepalived
#cat /etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_defs {router_id NGINX_DEVEL}vrrp_script check_nginx {script "/etc/keepalived/nginx_pid.sh"interval 2fall 1}vrrp_instance nginx { state MASTER interface ens33mcast_src_ip 192.168.10.40virtual_router_id 51 priority 100advert_int 1 authentication {auth_type PASSauth_pass 1111 }track_script {check_nginx}virtual_ipaddress { 192.168.10.213/24 }}
关联脚本 nginx_pid.sh
#chmod 755 /etc/keepalived/nginx_pid.sh#cat /etc/keepalived/nginx_pid.sh#!/bin/bashnginx_kp_check () {nginxpid=`ps -C nginx --no-header |wc -l`if [ $nginxpid -eq 0 ];then /usr/local/nginx/sbin/nginx sleep 1nginxpid=`ps -C nginx --no-header |wc -l` if [ $nginxpid -eq 0 ];thensystemctl stop keepalived fifi}
启动keepalived
systemctl start keepalived
配置备份Nginx分发器
backuo.ayitula.com#cat /etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_defs {router_id NGINX_DEVEL}vrrp_script check_nginx {script "/etc/keepalived/nginx_pid.sh"interval 2fall 1}vrrp_instance nginx { state BACKUP interface ens33mcast_src_ip 192.168.10.41virtual_router_id 51 priority 90advert_int 1 authentication {auth_type PASSauth_pass 1111 }track_script {check_nginx}virtual_ipaddress { 192.168.10.213/24 }}
04 测试⾼可⽤
模拟故障数据服务器宕机测试分发器宕机测试
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~