keepalived + nginx(负载均衡反向代理HTTP,https) + tomcat(HTTP,https)

基本架构:

                      nginx(192.168.116.198)

client        --->keepalived(116.200)      ------> tomcat (192.168.116.101,192.168.116.100)      

                      nginx(192.168.116.199)

keepalived的配置文件/etc/keepalived/keepalived.conf:

global_defs {
notification_email {
root@node2
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id nginx2
}

vrrp_script chk_nginx {
script "/server/scripts/chk_nginx.sh"
interval 2
fall 2
rise 1
}

vrrp_instance VI_1 {

track_script {
chk_nginx
}
state BACKUP
interface eth0
virtual_router_id 61
priority 90
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.116.200
}
}

###########################

#!/bin/bash
#check service of nginx is ok
/usr/bin/netstat -anlp |grep -w '0.0.0.0:9443' >/dev/null 2>&1

##################################################

前端nginx配置文件:

/etc/nginx/nginx.conf

worker_processes 3;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream shoudian_http{
ip_hash;
server 192.168.116.100:9000;
# server 192.168.116.101:9000;
}
upstream shoudianhttps {
server 192.168.116.100:9443 weight=10;
# server 192.168.116.101:9443 weight=10;
}
server {
listen 9000;
server_name shoudian_http;
location / {
proxy_pass http://shoudian_http;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
server {
listen 9443;
server_name localhost;

ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
ssl_session_timeout 5m;
location / {
proxy_pass https://shoudianhttps;
}
access_log /etc/nginx/logs/access.log;
error_log /etc/nginx/logs/error.log;
}

}

#后端tomcat的访问方式

curl https://192.168.116.100:9443/

curl http://192.168.116.100:9000/

posted @   littlevigra  阅读(335)  评论(1编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
点击右上角即可分享
微信分享提示