首页 > 系统相关 >Nginx和tomcat实现负载均衡

Nginx和tomcat实现负载均衡

时间:2023-02-07 16:32:02浏览次数:48  
标签:负载 tomcat 配置 Nginx IP地址 服务器 客户端

拓扑图:

Nginx和tomcat实现负载均衡_服务器

推荐步骤:

  • Nginx服务器开启路由功能,客户端和tomcat服务器配置IP地址设置正确
  • 安装tomcat服务器配置网站
  • 安装Nginx代理和负载均衡功能配置DNS服务器域名解析,客户端使用www.nlb.com负载均衡访问网站


实验步骤:

一、Nginx服务器开启路由功能,客户端和tomcat服务器配置IP地址设置正确

1、配置Nginx服务IP地址和路由转发功能

(1)Nginx服务器生成网卡配置文件

Nginx和tomcat实现负载均衡_服务器_02

(2)配置内网网卡IP地址

Nginx和tomcat实现负载均衡_Nginx_03

Nginx和tomcat实现负载均衡_服务器_04

(3)配置外网网卡IP地址

vim ifcfg-ens33

Nginx和tomcat实现负载均衡_Nginx_05

(4)重新启动服务查看IP地址

Nginx和tomcat实现负载均衡_Nginx_06

(5)配置路由转发功能开启路由功能

Nginx和tomcat实现负载均衡_Nginx_07

Nginx和tomcat实现负载均衡_服务器_08

Nginx和tomcat实现负载均衡_Nginx_09

2、第一台tomcat服务器配置IP地址

(1)第一台tomcat服务器配置IP地址

Nginx和tomcat实现负载均衡_Nginx_10

Nginx和tomcat实现负载均衡_服务器_11

(2)重新启动网卡服务查看配置的网关

Nginx和tomcat实现负载均衡_服务器_12

3、第二台tomcat服务器配置IP地址

(3)第二台tomcat服务器配置IP地址

vim /etc/sysconfig/network-scripts/ifcfg-ens32

Nginx和tomcat实现负载均衡_服务器_13

(4)重新启动网卡服务查看配置的网关

Nginx和tomcat实现负载均衡_服务器_14

4、客户端配置IP地址和DNS

(1)客户端配置IP地址和DNS

Nginx和tomcat实现负载均衡_Nginx_15

(2)查看配置的IP地址

Nginx和tomcat实现负载均衡_服务器_16

二、安装tomcat服务器配置网站

1、安装第一台tomcat服务器

(1)切换到程序光盘

Nginx和tomcat实现负载均衡_服务器_17

(3)挂载程序光盘到/mnt

Nginx和tomcat实现负载均衡_Nginx_18

(4)解压tomcat移动tomcat安装位置

tar zxvf /mnt/apache-tomcat-7.0.54.tar.gz -C /usr/src/
mv /usr/src/apache-tomcat-7.0.54/ /usr/local/tomcat/

2、配置第一台服务器

(1)创建网站服务器根目录设置网站主页

Nginx和tomcat实现负载均衡_Nginx_19

(2)修改tomcat主配置文件加载网站根目录

vim /usr/local/tomcat/conf/server.xml

124<Host name="localhost"  appBase="webapps"

125unpackWARs="true" autoDeploy="true">

126 <Context docBase="/www/" path="" reloadable="fales">     </Context>

(3)启动tomcat服务查看服务运行状态

Nginx和tomcat实现负载均衡_服务器_20

3、安装第二台tomcat服务器

(1)切换到程序光盘

Nginx和tomcat实现负载均衡_Nginx_21

(2)挂载程序光盘到/mnt

Nginx和tomcat实现负载均衡_服务器_22

(3)解压tomcat移动tomcat安装位置

Nginx和tomcat实现负载均衡_Nginx_23

Nginx和tomcat实现负载均衡_服务器_24

4、配置第二台服务器

(1)创建网站服务器根目录设置网站主页

Nginx和tomcat实现负载均衡_服务器_25

(2)修改tomcat主配置文件加载网站根目录

Nginx和tomcat实现负载均衡_Nginx_26

124       <Host name="localhost"  appBase="webapps"

125             unpackWARs="true" autoDeploy="true">

126        <Context docBase="/www/" path="" reloadable="fales">     </Context>

(3)启动tomcat服务查看服务运行状态

Nginx和tomcat实现负载均衡_Nginx_27

三、安装Nginx代理和负载均衡功能配置DNS服务器域名解析,客户端使用www.nlb.com负载均衡访问网站

1、安装Nginx反向代理依赖软件和DNS服务

(1)切换到系统光盘

Nginx和tomcat实现负载均衡_服务器_28

(3)挂载系统盘到/mnt目录

Nginx和tomcat实现负载均衡_服务器_29

(4)删除系统自带yum源配置本地yum源

Nginx和tomcat实现负载均衡_服务器_30

(5)安装依赖程序

yum -y install pcre-devel zlib-devel openssl-devel bind bind-chroot bind-utils

(6)创建管理Ngxinx服务用户

Nginx和tomcat实现负载均衡_Nginx_31

2、配置Nginx代理服务器

(1)切换到系统光盘、

Nginx和tomcat实现负载均衡_服务器_32

(2)挂载系统光盘到/mnt目录

Nginx和tomcat实现负载均衡_Nginx_33

(3)配置Nginx

Nginx和tomcat实现负载均衡_服务器_34

Nginx和tomcat实现负载均衡_服务器_35

(4)编译安装Nginx

Nginx和tomcat实现负载均衡_Nginx_36

(5)优化Nginx服务命令

Nginx和tomcat实现负载均衡_服务器_37

3、修改Nginx主配置配置支持负载均衡群集

(1)修改Nginx主配置文件

Nginx和tomcat实现负载均衡_服务器_38

Nginx和tomcat实现负载均衡_服务器_39

(2)检查Nginx主配置文件是否错误

Nginx和tomcat实现负载均衡_Nginx_40

(3)启动服务查看端口

Nginx和tomcat实现负载均衡_Nginx_41

4、配置DNS服务器

(1)修改DNS服务器主配置文件检查是否错误

vim /etc/named.conf

Nginx和tomcat实现负载均衡_Nginx_42

Nginx和tomcat实现负载均衡_服务器_43

(2)配置DNS服务于数据库文件

vim /var/named/nlb.com.zone

Nginx和tomcat实现负载均衡_Nginx_44

Nginx和tomcat实现负载均衡_Nginx_45

(3)启动服务设置开机自动启动

Nginx和tomcat实现负载均衡_服务器_46

(4)查看服务运行状态

Nginx和tomcat实现负载均衡_Nginx_47

5、客户端验证

(1)客户端第一次访问网站服务器

Nginx和tomcat实现负载均衡_Nginx_48

(2)客户端第二次访问网站服务器

Nginx和tomcat实现负载均衡_Nginx_49

标签:负载,tomcat,配置,Nginx,IP地址,服务器,客户端
From: https://blog.51cto.com/u_15830844/6041356

相关文章

  • centos7+nginx+uwsgi+python3.7.4+django部署实践
    yuminstallpython3yuminstallpython3-develyum-yinstallgccgcc-c++pip3installuwsgipython3​​manage.py​​runserver10.5.1.65:82uwsgi--iniuwsgi.i......
  • CentOS 7 yum 安装 Nginx
    添加CentOS7Nginxyum资源库,打开终端,使用以下命令:sudorpm-Uvhhttp://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm......
  • nginx [error] invalid PID number in varrunnginx.pid
    执行nginx-t是正常的。当执行nginx-sreload出现以下问题因为之前的nginx执行重启的时候出现问题了,执行以下命令即可:nginx-c/etc/nginx/nginx.confnginx-s......
  • nginx 报错 upstream timed out (110: Connection timed out)
    upstreamtimedout(110:Connectiontimedout)whilereadingresponseheaderfromupstream, 在http下面加:  proxy_http_version1.1;  proxy_set_he......
  • nginx通过参数代理到其他站点
    http{includemime.types;default_typeapplication/octet-stream;resolver8.8.8.8;##Nginx0.6.18以后的版本中启用了一个resolver指令,在使用变量来构造某个server......
  • 【漏洞复现】Tomcat弱口令+后台getshell
    Tomcat7+WeakPassword&&BackendGetshellVulnerability1.弱口令vulhub部署好靶机环境以后;在登录窗口随机输入账号密码,如admin:123456;打开burp抓包,发现数据包中包......
  • Pulsar负载均衡原理及优化
    前言前段时间我们在升级Pulsar版本的时候发现升级后最后一个节点始终没有流量。虽然对业务使用没有任何影响,但负载不均会导致资源的浪费。和同事沟通后得知之前的......
  • Nginx前端部署配置
    Nginx部署(针对vue项目)运行打包命令生成dist文件:npmrundev打开nginx.conf文件,配置对应的信息#nginx.conflocation/{rootC:\Users\Desktop\project\dist......
  • Eclipse关联tomcat
    Eclipse关联tomcat一,添加TomcatWindows-->Preferences-->Server-->RuntimeEnviroment添加一个tomcat,这里选择tomcat8.0Nextbrowse选择tomcat8.0所......
  • nginx访问日志和错误日志分割
    #!/bin/sh#Program:#Autocutnginxlogscript.#nginx日志路径LOGS_PATH=/home/wwwlogsTODAY=$(date-d'today'+%Y-%m-%d)#移动日志并改名mv${LOGS_PA......