手动部署LNMT(Nginx+Tomcat) 并实现Nginx反向代理Tomcat-wx5c0fb8e22254f的博客

Windows Windows 2个月前 (08-15) 14次浏览 已收录 0个评论 扫描二维码

手动部署LNMT(Nginx+Tomcat) 并实现Nginx反向代理Tomcat-wx5c0fb8e22254f的博客准备环境:三台主机:一台nginx:172.18.9.200、两台Tomcat:172.18.9.201;172.18.9.202.一、安装Nginx、Tomcat:[root@200 ~]#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo #更新镜像[root@200 ~]#yum -y install epel-release[root@200 ~]#yum install nginx[root@201/202 src]#lltotal 172028-rw-r–r– 1 root root 176154027 Nov 20 03:06 jdk-8u191-linux-x64.rpm[root@201/202 src]#yum -y install jdk-8u191-linux-x64.rpm [root@201/02 src]#yum install -y tomcat.noarch tomcat-admin-webapps.noarch tomcat-docs-webapp.noarch tomcat-webapps.noarch tomcat-javadoc.noarch二、配置Nginx:[root@200 ~]#vim /etc/nginx/conf.d/tomcat.confserver {listen 80;server_name http://www.ready.com;location / {proxy_pass http://172.18.9.201:8080;}}三、查看Tomcat的默认配置:[root@201 /etc/tomcat]#lsCatalina catalina.properties context.xml logging.properties tomcat.conf web.xmlcatalina.policy conf.d log4j.properties server.xml tomcat-users.xml四、使用Tomcat默认配置测试Nginx+Tomcat是否连通:手动部署LNMT(Nginx+Tomcat) 并实现Nginx反向代理Tomcat-wx5c0fb8e22254f的博客启动Nginx、Tomcat:[root@200 ~]#systemctl start nginx[root@201 tomcat]#systemctl start tomcat五、访问www.ready.com:手动部署LNMT(Nginx+Tomcat) 并实现Nginx反向代理Tomcat-wx5c0fb8e22254f的博客六、在Tomcat上部署测试应用:1、以WAR包为例,创建一个动态网页:a、创建项目目录:[root@201 tomcat]#mkdir -pv /var/lib/tomcat/webapps/test/{WEB-INF,META-INF,classes,lib}mkdir: created directory ‘/var/lib/tomcat/webapps/test’mkdir: created directory ‘/var/lib/tomcat/webapps/test/WEB-INF’mkdir: created directory ‘/var/lib/tomcat/webapps/test/META-INF’mkdir: created directory ‘/var/lib/tomcat/webapps/test/classes’mkdir: created directory ‘/var/lib/tomcat/webapps/test/lib’b、创建主页文件index.jsp(功能为查询session状态):[root@201 tomcat]#vim /var/lib/tomcat/webapps/test/index.jsp<%@ page language=”java” %><html><head><title>TomcatA</title></head><body><h1><font color=”red”>Tomcat.ready.com</font></h1><table align=”centre” border=”1″><tr><td>Session ID</td><% session.setAttribute(“ready.com”,”ready.com”); %><td><%= session.getId() %></td></tr><tr><td>Created on</td><td><%= session.getCreationTime() %></td></tr></table></body></html>c、访问http://www.ready.com/test/index.jsp手动部署LNMT(Nginx+Tomcat) 并实现Nginx反向代理Tomcat-wx5c0fb8e22254f的博客七、Nginx做反向代理负载均衡后端Tomcat:1、在主机3上安装Tomcat,并修改index.jsp文件:[root@202 src]#mkdir -pv /var/lib/tomcat/webapps/test/{WEB-INF,META-INF,classes,lib}mkdir: created directory ‘/var/lib/tomcat/webapps/test’mkdir: created directory ‘/var/lib/tomcat/webapps/test/WEB-INF’mkdir: created directory ‘/var/lib/tomcat/webapps/test/META-INF’mkdir: created directory ‘/var/lib/tomcat/webapps/test/classes’mkdir: created directory ‘/var/lib/tomcat/webapps/test/lib’[root@202 src]#vim /var/lib/tomcat/webapps/test/index.jsp<%@ page language=”java” %><html><head><title>TomcatA</title></head><body><h1><font color=”green”>Jerrymouse.ready.com</font></h1> #修改标题颜色和内容<table align=”centre” border=”1″><tr><td>Session ID</td><% session.setAttribute(“ready.com”,”ready.com”); %><td><%= session.getId() %></td></tr><tr><td>Created on</td><td><%= session.getCreationTime() %></td></tr></table></body></html>2、在172.18.9.200上配置Nginx,在默认配置中的http模块中插入upstream:[root@200 ~]#vim /etc/nginx/nginx.confupstream tcsv {server 172.18.9.201:8080;server 172.18.9.202:8080;}[root@200 ~]#vim /etc/nginx/conf.d/tomcat.confserver {listen 80;server_name http://www.ready.com;location / {proxy_pass http://tcsv;}}3、重启Nginx和Tomcat,再次访问www.ready.com:[root@200 ~]#systemctl restart nginx[root@201/202 tomcat]#systemctl restart tomcat手动部署LNMT(Nginx+Tomcat) 并实现Nginx反向代理Tomcat-wx5c0fb8e22254f的博客本实验结束!

喜欢 (0)
[]
分享 (0)
关于作者:
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址