Keepalived+Nginx+tomcat实现主备+负载
部署系统:
Red Hat Enterprise Linux Server release 7.0
软件版本:apache-tomcat-7.0.92.tar.gz
keepalived-2.0.11.tar.gz
nginx-1.15.7.tar.gz (openssl-1.1.1.tar.gz pcre-8.40.tar.gz zlib-1.2.11.tar.gz )
架构图
vip:192.168.56.80-----> A:192.168.56.129 nginx(8001) tomcat (8080)
B:192.168.56.130 nginx(8001) tomcat (8080)
开始部署
1、准备两台虚拟机,网络我选择的是nat,如下图. 这种网络有点麻烦后面需要做一下映射。

在vmware 编辑下虚拟网络编辑器,选择NAT设置




这样通过本机IP访问这此端口了.
服务器上网络准备如下:
[root@mrice_02 sbin]# cat /etc/sysconfig/network-scripts/ifcfg-eno16777736
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
NAME=eno16777736
ONBOOT=yes
IPADDR0=192.168.56.130
PREFIX0=32
GATEWAY0=192.168.56.2
HWADDR=00:0c:29:b9:46:b5
PEERDNS=yes
2、服务器准备完毕后,开始安装软件.
tomcat 不用说了,解压后,编写一个默认页面.


nginx 安装 请参考https://www.cnblogs.com/mrice/p/9882781.html
nginx.conf 配置文件如下 ,nginx配置可简单也可复杂,可根据生产中进行配置.
#user nobody;
worker_processes ; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections ;
} http {
include mime.types;
default_type application/octet-stream; #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 logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout ;
keepalive_timeout ; #gzip on; upstream mrice{
server 192.168.56.129: weight=;
server 192.168.56.130: weight=;
} server {
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
} location /mrice {
proxy_pass http://mrice/;
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen ;
# listen somename:;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }
验证负载是否正常


keepalived 安装
本次使用的是源码安装
tar -xzvf keepalived-2.0.11.tar.gz
cd keepalived-2.0.11
./configure --prefix=/usr/local/keepalived 安装目录根据需要修改
make && make install
cp keepalived-2.0.11/keepalived/etc/init.d/keepalived /etc/init.d/
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp keepalived-2.0.11/keepalived/etc/sysconfig/keepalived
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
配置keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
mrice_02@mrice.com
}
notification_email_from mrice@mrice.com
smtp_server 192.168.56.8
smtp_connect_timeout
router_id mrice_backup
}
vrrp_script chk_http_port {
script "/opt/nginx/check_nginx.sh"
interval
weight
}
vrrp_instance VI_1 {
state BACKUP
interface eno16777736
virtual_router_id
priority
advert_int
authentication {
auth_type PASS
auth_pass
}
virtual_ipaddress {
192.168.56.80
}
}
其中配置文件中/opt/nginx/check_nginx.sh检查nginx进程
#!/bin/bash
A=`ps -C nginx --no-header |wc -l`
if [ $A -eq ];then
/usr/nginx/sbin/nginx #重启nginx
if [ `ps -C nginx --no-header |wc -l` -eq ];then #nginx重启失败
exit
else
exit
fi
else
exit
fi
通过VIP访问是否正常。

可查看VIP地址在哪台服务器上
[root@mrice_02 sbin]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:b9:46:b5 brd ff:ff:ff:ff:ff:ff
inet 192.168.56.130/32 brd 192.168.56.130 scope global eno16777736
valid_lft forever preferred_lft forever
inet 192.168.56.80/32 scope global eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:feb9:46b5/64 scope link
valid_lft forever preferred_lft forever
截止目前主备+负载配置完成,过程很简单,很多细节需要动手操作才会发现.
Keepalived+Nginx+tomcat实现主备+负载的更多相关文章
- 搭建 Keepalived + Nginx + Tomcat 的高可用负载均衡架构
1 概述 初期的互联网企业由于业务量较小,所以一般单机部署,实现单点访问即可满足业务的需求,这也是最简单的部署方式,但是随着业务的不断扩大,系统的访问量逐渐的上升,单机部署的模式已无法承载现有的业务量 ...
- Keepalived + Nginx + Tomcat 的高可用负载均衡架构搭建
Keepalived + Nginx + Tomcat 的高可用负载均衡架构搭建 Nginx 是一个高性能的 HTTP反向代理服务器 Keepalived 是一个基于VRRP协议来实现的LVS服务高可 ...
- 搭建Keepalived + Nginx + Tomcat的高可用负载均衡架构
1 概述 初期的互联网企业由于业务量较小,所以一般单机部署,实现单点访问即可满足业务的需求,这也是最简单的部署方式,但是随着业务的不断扩大,系统的访问量逐渐的上升,单机部署的模式已无法承载现有的业务量 ...
- Keepalived+Nginx+Tomcat配置高可用负载均衡系统示例
前言 此示例为keepalived+nginx+tomcat的基础配置示例,某些特定配置此例中不会出现,在示例中会用到三个虚拟机:两个纯命令行用于模拟服务端配置,一个带桌面环境的用于模拟客户端访问,这 ...
- [转]搭建Keepalived+Nginx+Tomcat高可用负载均衡架构
[原文]https://www.toutiao.com/i6591714650205716996/ 一.概述 初期的互联网企业由于业务量较小,所以一般单机部署,实现单点访问即可满足业务的需求,这也是最 ...
- Keepalived + Nginx + Tomcat 高可用负载均衡架构
环境: 1.centos7.3 2.虚拟ip:192.168.217.200 3.192.168.217.11.192.168.217.12上分别部署Nginx Keepalived Tomcat并进 ...
- Ubuntu下配置 keepalived+nginx+tomcat 负载均衡
本文力图阐述在 Ubuntu Server 环境下使用 Keepalived + Nginx + Tomcat 搭建高可用负载均衡环境的操作步骤和简约配置,这里不涉及性能调优.先说一下他们各自扮演的角 ...
- keepalived+nginx+tomcat+redis实现负载均衡和session共享(原创)
keepalived+nginx+tomcat+redis实现负载均衡和session共享 直接上链接,码了一天,就不再重写了,希望能帮到大家,有问题欢迎留言交流.
- Keepalived+Nginx+Tomcat 实现高可用Web集群
https://www.jianshu.com/p/bc34f9101c5e Keepalived+Nginx+Tomcat 实现高可用Web集群 0.3912018.01.08 20:28:59字数 ...
随机推荐
- Linux下GCC去除调试信息
如果不去除调试信息,直白点说基本上是把代码公开了,不要带-g参数,还有就是需要带 -O2 -fvisibility=hidden -s 生成程序后可以用命令strip进一步去除不需要的符号 strip ...
- day65—angularJS的学习笔记1
转行学开发,代码100天—2018-05-20 AngularJS的引用示例: <!DOCTYPE html> <html> <head> <title> ...
- 阶段3 1.Mybatis_01.Mybatis课程介绍及环境搭建_04.mybatis概述
- vue路由高级用法
五.路由设置高级用法alias 别名 {path:'/list',component:MyList,alias:'/lists'}redirect 重定向 {path:'/productList',r ...
- Django 优秀资源大全
版权: https://github.com/haiiiiiyun/awesome-django-cn 转自:https://www.jianshu.com/p/38c4dd6d8e28 Awesom ...
- 应用安全 - CMS - PHPCMS漏洞汇总
CVE-2011-0644 Date: 2011.1 类型: /flash_upload.php SQL注入 影响版本:phpCMS 2008 V2 PHPCMS PHPCMS通杀XSS 在我要报错功 ...
- Xpath素材
from lxml import etree text = """ <div> <ul> <li class="item-0&qu ...
- Canvas入门03-绘制弧线和圆
绘制弧线的API: context.arc(centerx:number, centery: number, radius: number, startAngle: number, endAngle: ...
- (4.31)sql server中的xml数据操作
关键词:xml数据转为行列方式显示 常规案例: declare @data xml declare @h int set @data=' <bookstore> <row> & ...
- JGit、SvnKit - 版本提交日志(1)提取
1.相关开源jar包 1>使用JGIT访问git项目 2>使用SVNkit访问svn Git官方JGit使用教程指导 2.Git历史提交日志导出到文件 在项目根目录执行如下命令,将日志 ...