首页 > 其他分享 >高可用Kubernetes集群实战(三)

高可用Kubernetes集群实战(三)

时间:2023-09-30 10:02:24浏览次数:43  
标签:实战 log Kubernetes keepalived server nginx 集群 k8sm1 root

安装nginx
安装依赖
[root@k8sm1 ~]# yum install -y  epel-release
安装nginx keepalived
[root@k8sm1 ~]# yum install -y nginx  keepalived nginx-mod-stream
配置nginx
[root@k8sm1 ~]# cat /etc/nginx/nginx.conf
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

stream {

    log_format  main  '$remote_addr $upstream_addr - [$time_local] $status $upstream_bytes_sent';

    access_log  /var/log/nginx/k8s-access.log  main;

    upstream k8s-apiserver {
            server 192.168.1.180:6443 weight=5 max_fails=3 fail_timeout=30s;  
            server 192.168.1.181:6443 weight=5 max_fails=3 fail_timeout=30s;
            server 192.168.1.182:6443 weight=5 max_fails=3 fail_timeout=30s;  

    }

    server {
       listen 16443; # 由于nginx与master节点复用,这个监听端口不能是6443,否则会冲突
       proxy_pass k8s-apiserver;
    }
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80;
#        listen       [::]:80;
        server_name  _;
#        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
#       include /etc/nginx/default.d/*.conf;

#        error_page 404 /404.html;
        location / {

        }
        
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
配置keepalived
[root@k8sm1 keepalived]# cat keepalived.conf 
! Configuration File for keepalived

global_defs {
   notification_email {
     [email protected]
     [email protected]
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id NGINX_MASTER
}

vrrp_script check_nginx {
  script "/etc/keepalived/check_nginx.sh"
  
}
vrrp_instance VI_1 {
    state MASTER
    interface ens192
    virtual_router_id 51
    priority 100
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.1.188/24
    }
}
配置nginx 进程检测脚本
[root@k8sm1 keepalived]# cat check_nginx.sh 
#!/bin/bash
counter=$(ps -ef |grep nginx | grep sbin | egrep -cv "grep|$$" )
if [ $counter -eq 0 ]; then
    service nginx start
    sleep 2
    counter=$(ps -ef |grep nginx | grep sbin | egrep -cv "grep|$$" )
    if [ $counter -eq 0 ]; then
        service  keepalived stop
    fi
fi
配置nginx 检测脚本权限
[root@k8sm1 keepalived]# chmod +x check_nginx.sh
启动高可用
重载配置
[root@k8sm1 keepalived]# systemctl daemon-reload
启动nginx 并配置开机自启
[root@k8sm1 keepalived]# systemctl enable nginx --now
启动keepalived并配置开机自启
[root@k8sm1 keepalived]# systemctl enable keepalived --now


标签:实战,log,Kubernetes,keepalived,server,nginx,集群,k8sm1,root
From: https://blog.51cto.com/u_11726705/7654900

相关文章

  • Kubernetes 无法join:[ERROR CRI]: container runtime is not running:
    Kubernetes初始化成功,然后将node加入,结果报错:[root@k8s-node1~]#kubeadmjoin10.10.10.185:6443--token84pas2.ifxb6o8g7h2abg28--discovery-token-ca-cert-hashsha256:f85f0c324e0b951238617f9037832b63e4c4a6c7679aaa53c711a829fc9374e6[preflight]Runningpre-flight......
  • 大模型强化学习——PPO项目实战
    【PPO算法介绍】PPO(Proximal Policy Optimization)是一种强化学习算法,它的目标是找到一个策略,使得根据这个策略采取行动可以获得最大的累积奖励。PPO的主要思想是在更新策略时,尽量让新策略不要偏离旧策略太远。这是通过在目标函数中添加一个额外的项来实现的,这个额外的项会惩罚......
  • Redis主从及哨兵及集群相关介绍
    主从模式为了避免单点故障和读写不分离,Redis提供了复制(replication)功能,master数据库中的数据更新后,会自动将更新的数据同步到其他slave数据库上。优点:主从结构具有读写分离,提高效率、数据备份,提供多个副本等优点。不足:大的不足就是主从模式不具备自动容错和恢复功能,主......
  • lesson6课堂练习与讲解 (布局实战)
     packagecom.zym.lesson6;importjava.awt.*;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;publicclassTestMixLayOut{publicstaticvoidmain(String[]args){Frameframe=newFrame("课堂练习,混合布局");......
  • hadoop HA高可用集群搭建
    首先是四项配置core-site.xml<?xmlversion="1.0"encoding="UTF-8"?><?xml-stylesheettype="text/xsl"href="configuration.xsl"?><!--LicensedundertheApacheLicense,Version2.0(the"License"......
  • 使用 Terraform 创建K8S集群
    Terraform是一个开源的基础设施即代码(InfrastructureasCode,IaC)工具,由HashiCorp公司开发和维护。它用于自动化和管理云基础设施、服务和资源的创建、配置和部署。Terraform允许开发人员和运维团队以声明性的语言描述基础设施,并使用代码的方式来管理基础设施,从而提高......
  • 02. Kubeadm部署Kubernetes集群
    目录1、前言2、Kubernetes部署方式3、kubeadmin部署3.1、关闭防火墙3.2、配置阿里云Kubernetes源3.3、安装kubeadm,kubelet,kubectl3.4、初始化master节点3.5、master节点配置kubectl命令行工具3.6、master节点下载flannel网络配置文件3.7、node1和node2节点加入Kubernetes集群3.8、......
  • 华为现网真机怎么抓包 端口镜像实战
    端口镜像-可以在不影响数据正常处理的情况下,把镜像端口的数据复制一份到观察端口-业务实时监控故障处理分析网络流量优化-汇聚点-定义:-把镜像端口【源端口】的数据复制一份到观察端口【目的端口】1.2.observe-portinterfaceg0/0/0interfacerangeg0/0/1tog0/0/2mirror......
  • Kubernetes 上的数据已跨越鸿沟:在 GKE 上运行有状态应用程序的案例
    Kubernetes是当今云原生开发的事实上的标准。长期以来,Kubernetes主要与无状态应用程序相关,例如Web和批处理应用程序。然而,与大多数事物一样,Kubernetes也在不断发展。如今,我们看到Kubernetes上有状态应用程序的数量呈指数级增长。事实上,自2019年以来,在GoogleKubernetesE......
  • Kubernetes 上的数据已跨越鸿沟:在 GKE 上运行有状态应用程序的案例
    Kubernetes是当今云原生开发的事实上的标准。长期以来,Kubernetes主要与无状态应用程序相关,例如Web和批处理应用程序。然而,与大多数事物一样,Kubernetes也在不断发展。如今,我们看到Kubernetes上有状态应用程序的数量呈指数级增长。事实上,自2019年以来,在GoogleKubernetes......