导言:

本次实验,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. 记录java

    1.从今天起,我会将自己在java学习道路上的一些心得体会记录下来.

  2. jQ无法设置checkbox变成选中状态

    设置以后checkbox并没有变成选中状态,用chrome调试看了一下,checkbox中确实有checked属性,针对这个问题,大家可以参考下本文 代码如下: $("input" ...

  3. python3中装饰器的用法总结

    装饰器预备知识点 1 函数赋值给一个变量 函数名可以像普通变量一样赋值给另一个变量. def test(): print("i am just a test function") ...

  4. list中的所有值转换为字符串,以及list拼接成一个字符串

    import stringlis=[1,2,3,'abc']fw=open('hello.txt','w',encoding='utf-8')# print(''.join(str(lis).repl ...

  5. if语句基本结构以及基础案例演示

    1.结构 if(比较表达式1) { 语句体1; }else if(比较表达式2) { 语句体2; }else if(比较表达式3) { 语句体3; } ... else { 语句体n+1; } 2.执 ...

  6. 搭建git服务器遇到的问题

    1.错误提示: remote: error: insufficient permission for adding an object to repository database ./objects ...

  7. windows10 Bash on Ubuntu 安装pygame

    在bash命名行下执行以下三个命令1.下载pip2.apt-get install python3-setuptools3.python3 setup.py install以管理员身份运行cmd,执行 ...

  8. Pandas_key_point

    10分钟快速入门pandas: http://pandas.pydata.org/pandas-docs/stable/10min.html ----------------------------- ...

  9. c++while控制语句

    while语句结构:while(condition){ statement; } condition 表示返回值是true or false 如果返回的一直是true则statement语句则一直执行 ...

  10. oracle 数据库插入中文乱码

    一. 查询数据库编码 select userenv('language') from dual; 查询服务器编码 select * from v$nls_parameters; 推出sql查询系统编码 ...