导言:

本次实验,tomcat就直接使用录原生的主页,只是简单修改主页识别主机,nginx也是直接在欢迎页上面修改的,直接实现负载均衡。

主机1:192.168.100.156 nginx+tomcat

主机2:192.168.100.157 tomcat

安装启动tomcat

主机1

下载安装包

#打开下载目录
cd /home/download #下载tar包
wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.5.24/bin/apache-tomcat-8.5.24.tar.gz
Tomcat7官网下载地址:https://tomcat.apache.org/download-70.cgi
Tomcat8官网下载地址:https://tomcat.apache.org/download-80.cgi

配置目录

# 创建tomcat目录
sudo mkdir /usr/tomcat #解压到指定目录
sudo tar -zvxf apache-tomcat-8.5..tar.gz -C /usr/tomcat #改名目录名为tomcat8
mv /usr/tomcat/apache-tomcat-8.5. /usr/tomcat/tomcat8

修改默认主页

在<head>与<body>之间插入一行

<h1>this is 156</h1>  
vim /usr/tomcat/tomcat8/webapps/ROOT/index.jsp

%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title><%=request.getServletContext().getServerInfo() %></title>
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
<link href="tomcat.css" rel="stylesheet" type="text/css" />
</head>
<h1>this is </h1> <body>

启动tomcat

#启动
cd /usr/tomcat/tomcat8/bin && sh startup.sh

访问测试(测试环境注意关闭防火墙)

192.168.100.156:8080

主机2配置与主机一样

配置nginx

配置nginx的yum源

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

安装nginx

yum install nginx -y

启动

systemctl start nginx

配置负载均衡

 vim /etc/nginx/conf.d/default.conf

 配置好的文件如下 即增加了5-8行内容,21行内容

 upstream tomcat {
server 192.168.100.156:;
server 192.168.100.157:;
} server {
listen ;
server_name localhost; #charset koi8-r;
#access_log /var/log/nginx/host.access.log main; location / {
root /usr/share/nginx/html;
index index.html index.htm;
proxy_pass http://tomcat;
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root /usr/share/nginx/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;
#}
}

重启nginx

systemctl restart nginx

浏览器输入192.168.100.156查看效果

刷新一次为156,再刷新一次157

百度脑图:

nginx+tomcat负载均衡实验的更多相关文章

  1. nginx+tomcat负载均衡

    最近练习nginx+tomcat负载均衡.根据一些资料整理了大体思路,最终实现了1个nginx+2个tomcat负载均衡. 安装JDK 1>进入安装目录,给所有用户添加可执行的权限 #chmod ...

  2. linux+nginx+tomcat负载均衡,实现session同步

    linux+nginx+tomcat负载均衡,实现session同步 花了一个上午的时间研究nginx+tomcat的负载均衡测试,集群环境搭建比较顺利,但是session同步的问题折腾了几个小时才搞 ...

  3. Nginx + Tomcat 负载均衡配置详解

    Nginx常用操作指南一.Nginx 与 Tomcat 安装.配置及优化1. 检查和安装依赖项 yum -y install gcc pcre pcre-devel zlib zlib-devel o ...

  4. Nginx+Tomcat负载均衡、动静分离群集

    Nginx+Tomcat负载均衡.动静分离群集 目录 Nginx+Tomcat负载均衡.动静分离群集 一.Tomcat 1. Tomcat简介 2. Tomcat重要目录 二.Nginx负载均衡原理 ...

  5. Linux下Nginx+Tomcat负载均衡和动静分离配置要点

    本文使用的Linux发行版:CentOS6.7 下载地址:https://wiki.centos.org/Download 一.安装Nginx 下载源:wget http://nginx.org/pa ...

  6. Nginx+tomcat负载均衡时静态页面报404

    百度到的问题解决BLOG http://os.51cto.com/art/201204/326843.htm nginx+2台tomcat负载均衡,应用程序已部署,单独访问tomcat时,可以访问到所 ...

  7. nginx+tomcat负载均衡策略

    測试环境均为本地,測试软件为: nginx-1.6.0,apache-tomcat-7.0.42-1.apache-tomcat-7.0.42-2.apache-tomcat-7.0.42-3 利用n ...

  8. nginx+tomcat负载均衡和session复制

    本文介绍下传统的tomcat负载均衡和session复制. session复制是基于JVM内存的,当然在当今的互联网大数据时代,有更好的替代方案,如将session数据保存在Redis中. 1.安装n ...

  9. Nginx+tomcat负载均衡配置

    Nginx+tomcat是目前主流的java web架构,如何让nginx+tomcat同时工作呢,也可以说如何使用nginx来反向代理tomcat后端均衡呢?直接安装配置如下: 1.JAVA JDK ...

随机推荐

  1. python学习笔记:try与except处理异常语句

    写代码的时候会遇到各种各样的异常,那么代码就不会继续往下走了.比如说10除以0是错误的,因为除数不能为零学会捕捉异常,在异常出现的时候我们要做什么操作. 本文中只做简单使用的讲解,详细使用方法可以参考 ...

  2. 后台获取html控件的值

    string name = Request.Form["Name1"].ToString(); “xxx” 里的是name值 Request["xx"]取到相同 ...

  3. Java并发AtomicReferenceArray类

    java.util.concurrent.atomic.AtomicReferenceArray类提供了可以原子读取和写入的底层引用数组的操作,并且还包含高级原子操作. AtomicReference ...

  4. javaScript Queue

    function Queue() { var items = []; this.enqueue = function(element) { items.push(element) } this.deq ...

  5. fiddler 解决不能抓https包的问题

    新解决方案 重置Fiddler,具体步骤: Tools > Fiddler Options > HTTPS > “Certificates generated by MakeCert ...

  6. if语句的嵌套使用之获取三个数据的最大值

    获取三个数据的最大值: class Hello2 { public static void main(String[] args) { int a = 10; int b = 20; int c = ...

  7. C语言深度剖析自测题8解析

    #include <stdio.h> int  main(void) {    int  a[5] = {1, 2, 3, 4, 5}; int* ptr1 = (int*)(&a ...

  8. Python之复数、分数、大型数组数学运算(complex、cmath、numpy、fractions)

    一.复数的数学运算 复数可以用使用函数 complex(real, imag) 或者是带有后缀j的浮点数来指定 a=complex(2,4) print(a) # (2+4j) b=2-5j # 获取 ...

  9. 【学习总结】Python-3-风格各异的数值类型实例

    菜鸟教程-Python3-基本数据类型 可能是考点的各种形态的数值类型 int型:正数负数,八进制0开头,十六进制0x开头 float型:小数点的前后都可以没有数字,自动补全 complex型:虚部的 ...

  10. Linux将动态IP改为静态IP

    1.编辑 ifcfg-eth0 文件,vim 最小化安装时没有被安装,需要自行安装不描述. 2.修改如下内容 BOOTPROTO="static" #dhcp改为static ON ...