搭建双master-k8s集群-第一步,搭建keepalived高可用和nginx转发配置

5 篇文章 0 订阅
4 篇文章 0 订阅

搭建双master-k8s集群-第一步,搭建keepalived高可用和nginx转发配置

1、准备2台lvs的虚拟机,并配置好IP地址

lvs01 192.168.136.11
lvs02 192.168.136.12
VIP 192.168.136.10

2、2台机器均安装keepalived并进行配置

1、keepalived在线安装

yum -y install keepalived

2、lvs01的keepalived.conf配置

vim /etc/keepalived/keepalived.conf
global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
   vrrp_skip_check_adv_addr
#   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_script chk_nginx {
    script "/etc/keepalived/nginx_check.sh"
    interval 2
    weight -5
    fall 3
    rise 2
}


vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.136.10
    }

track_script {
       chk_nginx
    }
}

注意:MASTER节点,priority 为100,权限数值尽量填高一点

3、lvs02的keepalived.conf配置

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
   vrrp_skip_check_adv_addr
#   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_script chk_nginx {
    script "/etc/keepalived/nginx_check.sh"
    interval 2
    weight -5
    fall 3
    rise 2
}


vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.136.10
    }

track_script {
       chk_nginx
    }
}

注意:BACKUP节点,priority 为50,权限数值尽量低一点

3、编辑nginx_check.sh脚本,2台机器均需要

vim /etc/keepalived/nginx_check.sh

#/bin/bash
A=`ps -C nginx  --no-header |wc -l`
if [ $A -eq 0 ];then
    systemctl restart docker
    sleep 2
    if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
        killall keepalived
    fi
fi

4、docker下部署nginx服务

1、拉取nginx-stream的镜像

docker pull tekn0ir/nginx-stream

2、开启nginx-stream服务

docker run -d \
       -p 80:80 \
       -p 6443:6443 \
       -v /opt/nginx/http.conf.d:/opt/nginx/http.conf.d \
       -v /opt/nginx/stream.conf.d:/opt/nginx/stream.conf.d \
       --restart=always \
       --name nginx \
       tekn0ir/nginx-stream

3、编辑master.conf的配置文件

vim /opt/nginx/stream.conf.d/master.conf

upstream master {
    server 192.168.136.15:6443;
    server 192.168.136.16:6443;
}

server {
    listen 6443;
    proxy_pass master;
}

注:这里填的IP地址为master01和master02的地址

5、开启nginx和keepalived服务,并查看虚拟IP是否正常

##开启keepalived服务
systemctl start keepalived
systemctl enable  keepalived

查看nginx服务是否正常,docker ps -a
在这里插入图片描述
查看VIP

在这里插入图片描述

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值