赞
踩
目录
两台tomcat 和 一台nginx
设定Nginx主机:ip :192.168.159.68
[root@zwb_nginx nginx-1.15.9]# hostname
zwb_nginx
设定tomcat1主机: ip:192.168.159.10
[root@zwb_tomcat1 opt]# hostname
zwb_tomcat1
设定tomcat2主机:ip:192.168.159.110
[root@zwb_tomcat2 opt]# hostname
zwb_tomcat2
- systemctl stop firewalld.service
- systemctl disable firewalld.service
- setenforce 0
-
- hostnamectl set-hostname zwb_nginx
yum install -y pcre-devel zlib-devel openssl-devel gcc gcc-c++ make
- [root@zwb_nginx nginx-1.15.9]# useradd -M -s /sbin/nologin nginx
- [root@zwb_nginx nginx-1.15.9]# tail -2 /etc/passwd
- roott:x:1000:1000:root:/home/roott:/bin/bash
- nginx:x:1001:1001::/home/nginx:/sbin/nologin
- [root@zwb_nginx nginx-1.15.9]# cd /opt/
- [root@zwb_nginx opt]# tar zxvf nginx-1.15.9.tar.gz #解压
-
- [root@zwb_nginx nginx]# cd /opt/nginx-1.15.9/ #进行安装配置,相当于windows里的安装软件自
- #定义
- ./configure \
- --prefix=/usr/local/nginx \
- --user=nginx \
- --group=nginx \
- --with-file-aio \
- --with-http_stub_status_module \
- --with-http_gzip_static_module \
- --with-http_flv_module \
- --with-http_ssl_module
-
-
- [root@zwb_nginx nginx-1.15.9]# make && make install ##编译安装
-
[root@zwb_nginx nginx-1.15.9]#ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
- [root@zwb_nginx nginx-1.15.9]# vim /lib/systemd/system/nginx.service
-
- [Unit]
- Description=nginx
- After=network.target
- [Service]
- Type=forking
- PIDFile =/usr/local/nginx/logs/nginx.pid
- ExecStart=/usr/local/nginx/sbin/nginx
- ExecReload=/bin/kill -s HUP $MAINPID
- ExecStop=/bin/kill -s QUIT $MAINPID
- PrivateTmp=true
- [Install]
- WantedBy=multi-user.target
- chmod 754 /lib/systemd/system/nginx.service
- systemctl start nginx.service
- systemctl enable nginx.service
- systemctl stop firewalld.service
- systemctl disable firewalld.service
- setenforce 0
-
- hostnamectl set-hostname zwb_tomcat1
- [root@zwb_tomcat1 opt]# vim /etc/profile.d/java.sh
-
-
- export JAVA_HOME=/usr/java/jdk1.8.0_201-amd64
- export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
- export PATH=$JAVA_HOME/bin:$PATH
-
-
- [root@zwb_tomcat1 opt]# source /etc/profile.d/java.sh
- [root@zwb_tomcat1 opt]# java -version
- java version "1.8.0_201"
- Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
- Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
(Tomcat不需要安装,只需要把解压的目录放到指定位置)
- [root@zwb_tomcat1 ~]#cd /opt
- [root@zwb_tomcat1 opt]# tar zxvf apache-tomcat-9.0.16.tar.gz
- [root@zwb_tomcat1 opt]# mv apache-tomcat-9.0.16 /usr/local/tomcat
-
-
- #优化管理
- [root@zwb_tomcat1 opt]# ln -s /usr/local/tomcat/bin/startup.sh /usr/local/bin/
- [root@zwb_tomcat1 opt]# ln -s /usr/local/tomcat/bin/shutdown.sh /usr/local/bin/
-
- [root@zwb_tomcat1 opt]# startup.sh
- [root@zwb_tomcat1 ~]# mkdir /usr/local/tomcat/webapps/test
- [root@zwb_tomcat1 webapps]# ls
- docs examples host-manager manager ROOT test
动态页面设置
- [root@zwb_tomcat1 webapps]# vim /usr/local/tomcat/webapps/test/index.jsp
-
- <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
- <html>
- <head>
- <title>JSP test1 page</title>
- </head>
- <body>
- <% out.println("动态页面 1,http://www.test1.com");%>
- </body>
- </html>
添加虚拟主机
动态页面设置
- [root@zwb_tomcat2 opt]# hostname
- zwb_tomcat2
- [root@zwb_tomcat2 opt]# mkdir /usr/local/tomcat/webapps/test
- [root@zwb_tomcat2 opt]# vim /usr/local/tomcat/webapps/test/index.jsp
-
- vim /usr/local/tomcat/webapps/test/index.jsp #动态页面的配置
- <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
- <html>
- <head>
- <title>JSP test2 page</title>
- </head>
- <body>
- <% out.println("动态页面 2,http://www.test2.com");%>
- </body>
- </html>
添加主机
- [root@zwb_nginx nginx-1.15.9]# echo '<html><body><h1>this is static</h1></body></html>' > /usr/local/nginx/html/index.html
-
-
- [root@zwb_nginx html]# ls
- 50x.html index.html
- [root@zwb_nginx html]# mkdir img ##创建img目录
- [root@zwb_nginx html]# ls
- 50x.html img index.html
- [root@zwb_nginx html]# cd img/
- [root@zwb_nginx img]# rz -E ##上传照片
- rz waiting to receive.
- [root@zwb_nginx img]# ls
- jz.jpg
- [root@zwb_nginx img]# vim /usr/local/nginx/conf/nginx.conf
- ..............................
- #keepalive_timeout 0;
- keepalive_timeout 65;
-
- #gzip on;
-
- upstream tomcat { ### 增加,此信息增加在http模块下
- server 192.168.159.10:8080 weight=1;
- server 192.168.159.110:8080 weight=1;
- }
-
-
- server {
- listen 80;
- server_name location;
-
- location ~ .*\.jsp$ { ###增加,此信息增加在server模块下
- proxy_pass http://tomcat;
- proxy_set_header HOST $host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- }
-
-
- #charset koi8-r;
-
- ..............................
验证:
访问静态页面
访问动态
刷新
通过不断刷新会发现,会发现他会在tomcat1和tomcat2服务器之间不停跳转
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。