栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

搭建Nginx+tomcat的实现集群

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

搭建Nginx+tomcat的实现集群

集群的简介:

集群(cluster)技术是一种较新的技术,通过集群技术,可以在付出较低成本的情况下获得在性能、可靠性、高可用、灵活性方面的相对较高的收益,其任务调度则是集群系统中的核心技术。

如果一个事情是由多个人去完成,则有着和集群类似的地方。大家共同承担着压力,如果有的人临时请假,其他的可以分担他的任务,事情不会因此耽搁。并且当他忙完自己的事情依然会分给他新的任务,不会因此断了节奏。而集群就是在模拟的做这样的事情,事实上大部分的公司也都是用集群在向用户提供服务。无论是apache还是nginx。我们总不希望自己在浏览网页的时候突然not found吧。那么你需要了解集群。这种调度方法和思想对于我们做任何事情都是非常有益的。


Linux集群安装tomcat+nginx实现负载均衡

jdk安装:linux安装jdk_bakelFF的博客-CSDN博客

tomcat服务器安装:centos7安装Tomcat完整步骤_bakelFF的博客-CSDN博客

nginx安装:centos7下nginx的安装_bakelFF的博客-CSDN博客

首先在linux里面最少需要两个tomcat才能实现集群,所以我们在实现集群时还得在复制tomcat,两个tomcat的名称和端口不能一样

linux上安装配置多个tomcat:linux上安装配置多个tomcat_bakelFF的博客-CSDN博客


搭建nginx+tomcat实现集群

1.在每个tomcat的webapps中创建test1文件夹

 mkdir test1

创建index.html文件

启动每个tomcat并测试


启动:/apache-tomcat-3/bin/startup.sh(根据自己实即的路径)

测试:192.168.67.13:8081/test1/index.html


2.配置nginx.conf文件(nginx/conf/nginx.conf)
upstream clustertomcat{
                server 192.168.67.13:8081 weight=5;

                server 192.168.67.13:8082 weight=1;

                server 192.168.67.13:8083 weight=1;

        }

server {
        listen       80;       

        server_name  localhost;

       

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
        root html;

        index index.html index.htm;

            proxy_pass httP://clustertomcat;

        }

}

注意:(配置所放的位置)

修改完后要重新加载nginx./nginx -s reload

测试:http://192.168.67.13/test1/index.html


3.在linux服务下解决session共享的方式加入如ip_hash,这样不同IP主机就访问同一个tomcat,

       upstream clustertomcat{
                server 192.168.67.13:8081 weight=5;

                server 192.168.67.13:8082 weight=1;

                server 192.168.67.13:8083 weight=1;

       ip_hash;

        }

server {
        listen       80;       

        server_name  localhost;

       

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
        root html;

        index index.html index.htm;

            proxy_pass httP://clustertomcat;

        }

}


4.nginx搭建图片服务器

在 /usr/local/创建文件夹images,放入图片
upstream clustertomcat{
                server 192.168.67.13:8081 weight=5;

                server 192.168.67.13:8082 weight=1;

                server 192.168.67.13:8083 weight=1;

                ip_hash;

        }

server {
        listen       80;

        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location /images {
                root /usr/local/;

        }

        location / {
        root html;

        index index.html index.htm;

            proxy_pass httP://clustertomcat;

        }

测试:http://192.168.67.13/images/003.jpg

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/583753.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号