Nginx+Tomcat实现负载均衡

如图所示:
在这里插入图片描述
一.搭建DNS服务器
www.benet.com 为192.168.200.10
二.配置Tomcat和Tomcat。(centos7以上版本无需配置)
1.配置JDK
[root@tomcat01 ~]# mv /usr/src/jdk1.7.0_65/ /usr/local/java
[root@tomcat01 ~]# vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/local/java
export PATH= P A T H : PATH: PATH:JAVA_HOME/bin
[root@tomcat01 ~]# source /etc/profile.d/java.sh .
2.安装Tomcat。
[root@tomcat01 ~]# mv /usr/src/apache-tomcat-7.0.54/ /usr/local/tomcat
3.配置Tomcat发布项目。 (在tomcat02上也需要配置)
1)创建项目根目录。
[root@tomcat01 ~]# mkdir -vp /var/www
2)设置第一台Tomcat网站主页。
[root@tomcat01 ~]# vim /var/www/index.jsp

<%@ page langerage="java" import="java.util.*" pagEncoding="utf-8"%>
				<html>
				        <head>
				                <title>test01</title>
				                                        </head>
				        <body>
				                <% out.println ("www.benet.com!!!");%>
				                                        </body>
				</html>

3)配置Tomcat主配置文件发布web服务器
[root@tomcat01 ~]# vim /usr/local/tomcat/conf/server.xml

	124       <Host name="localhost"  appBase="webapps"
	125             unpackWARs="true" autoDeploy="true">
	126         <context docBase="/var/www" path="" reloadable="fales">
	127         </context>

4)启动服务。
[root@tomcat01 ~]# /usr/local/tomcat/bin/startup.sh
[root@tomcat01 ~]# /usr/local/tomcat/bin/shutdown.sh
三.安装配置Nginx。
1.安装nginx依赖包。
[root@nginx ~]# yum -y install pcre-devel zlib-devel openssl-devel
openssl-devel:用于加密
2.创建管理账户和组。
[root@nginx ~]# groupadd nginx
[root@nginx ~]# useradd -M -s /sbin/nologin -g nginx nginx
3.配置nginx。
[root@nginx nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-file-aio --with-http_gzip_static_module --with-http_flv_module --with-http_ssl_module
在这里插入图片描述
[root@nginx nginx-1.6.0]# make && make install
4)优化命令。
[root@nginx /]# ln -s /usr/local/nginx/sbin/* /usr/sbin/
5)编辑主配置文件。
[root@nginx /]# vim /usr/local/nginx/conf/nginx.conf
http:
upstream tomcat_server {
server 192.168.200.20:80 weight=1;
server 192.168.200.30:80 weight=1;
}
user nginx;
虚拟主机:
server {
listen www.benet.com:80;
server_name www.benet.com;
charset utf-8;
location / {
root html;
index index.html index.htm;
proxy_pass http://tomcat_server;
}
三,验证
在这里插入图片描述用F5刷新验证是否负载均衡:
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

H . C . Y

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值