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字数 ...
随机推荐
- learning webrtc 使用node.js
第二章 有使用node.js创建静态服务器的步骤 不过不够详细 下面以Windows为例 1.到官方网站下载安装包 然后安装 2.用管理员权限启动命令行 3.命令行窗口执行npm config set ...
- layui table指定某一行样式
1.想指定layui table中某一行的样式,找了这个资源可行.转自: https://blog.csdn.net/weixin_44729896/article/details/100524824 ...
- C# WPF 漂亮的loading 效果
<UserControl x:Class="TestLoadPic.Loading" xmlns="http://schemas.microsoft.com/win ...
- Django学习之缓存
1.配置 2.应用 由于Django是动态网站,所有每次请求均会去数据进行相应的操作,当程序访问量大时,耗时必然会更加明显,最简单解决方式是使用:缓存.缓存将一个某个views的返回值保存至内存或者m ...
- Struts2测试题
今天给大家看一套我最近做的一套关于Struts2的题: 1.以下关于jQuery说法错误的选项是( D ). A.“$”为jQuery脚本库的默认全局变量名,即“$” = “jQuery” B.$.a ...
- 移动端自动化==>AppiumApi接口详解
Appium 初始化配置信息(Desired Capabilities) Desired Capabilities实际上就是一个字典,它主要用于向Appium Server提供初始化配置参数,如:想要 ...
- JavaWeb项目:Shiro实现简单的权限控制(整合SSM)
该demo整合Shiro的相关配置参考开涛的博客 数据库表格相关设计 表格设计得比较简单,导航栏直接由角色表auth_role的角色描述vRoleDesc(父结点)和角色相关权限中的权限描述(标记为 ...
- Pager
jQuery var Pager = function (ops) { this._ops = { count: ops.count || 0, selectedIndex: ops.selected ...
- JDK,JRE,JVM的区别与联系?
概念区别 JDK: Java Develpment Kit java 开发工具JRE: Java Runtime Environment java运行时环境JVM: ...
- linux修改用户最大线程数
linux下普通用户最大允许使用线程数为1024: 但是并发量大时,该1024配置项远远不够满足我们的需要,我们可以修改/etc/security/limits.d/90-nproc.conf配置设置 ...