出了很多问题,终于搞定了
java web 框架 其中主要语言是java
jsp语句所实现需要的解析,靠apache何nginx不够,它需要专有的解析工具tomcat
对tomcat的使用和安装,解析jsp
nginx负载均衡
nginx服务器给2台tomcat服务器做代理,自我理解(nginx服务器轮流访问不同的tomcat服务器),如果一台服务器挂了,那么nginx服务器还会自动访问另一台服务器。
下载安装tomcat
下载网址: apache-tomcat
安装
下载包拖进虚拟机
[root@a ~]# cd Desktop/
[root@a Desktop]# tar -xf apache-tomcat-7.0.109.tar.gz
[root@a Desktop]# mv apache-tomcat-7.0.109 /usr/local/tomcat7
启动,关闭
[root@a Desktop]# cd /usr/local/tomcat7/
[root@a tomcat7]# cd bin/
[root@a bin]# ./startup.sh //开启
[root@a bin]#shutdown.sh //关闭
没太大关系
只是检查以下有没有java软件,没有的话自己再下一下
root@a bin]# java -version //查看java的版本
[root@a bin]# which java //查看java的位置
验证
[root@a bin]# [root@a bin]# ss -antpl |grep 8080 //查看是否开启服务
ifconfig //查看ip
firefox //打开浏览器
172.16.1.254:8080
tomcat目录介绍
cd /usr/local/tomcat7/
bin //存放启动或关闭tomcat的脚本
conf //存放tomcat全局配置文件
lib //皴法tomcat需要的库文件
logs //存放日志文件
webapps //主页存放目录
cd /usr/local/tomcat7/webapps/ROOT/ //默认主页存放目录
work //jsp编译后产生的class文件
新建一个jsp写的页面
[root@a bin]# cd /usr/local/tomcat7/webapps/ROOT/
[root@a webapps]# mv ROOT/ ROOTBAK //把原来的页面保留
[root@a webapps]# mkdir ROOT
[root@a webapps]# cd ROOT
[root@a ROOT]# vim index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>JSP TEST1 page</title>
</head>
<body>
<% out.println("Welcom to TEST1 web,http://www.test1.com");%>
</body>
</html>
nginx负载均衡实验
需要用到的虚拟机有一台充当nginx服务器,两台充当tomcat服务器
Nginx+Tomcat 负载均衡集群
配置两台tomcat服务器
tomcat服务器按照上述的方法配即可
但是需要更改一下ip地址
vim /etc/sysconfig/network-scripts/ifcfg-ens33 //更改ip地址
ifdown ens33
ifup es33
nginx安装
下载好nginx包,拖进虚拟机
[root@a ~]# cd Desktop/
[root@a Desktop]# tar -xf nginx-1.6.3.tar.gz
[root@a Desktop]# cd nginx-1.6.3/
[root@a nginx-1.6.3]# ./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
命令的解释
user,goup //指定用户和组
with-file-aio //启用文件修改
with-http_stub_status_module //启用状态统计
with-http_gzip_static_module //启用gzip静态压缩
with-http_flv_moudle //启用flv模块
with-http_ssl_moudle //启用SSL模块
出错了,按它的提示安
[root@a Desktop]# yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
-------
[root@a nginx-1.6.3]# ./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
又出错了,那继续按它的提示安!
我不知道光盘是哪个,所以下rpm包,下载的rpm包的网址.
[root@a ~]# cd Desktop/
[root@a Desktop]# cd za/
[root@a za]# rpm -ivh keyutils-libs-devel-1.5.8-3.el7.x86_64.rpm
[root@a za]# rpm -ivh libcom_err-devel-1.42.9-19.el7.x86_64.rpm
[root@a za]# rpm -ivh libsepol-devel-2.5-10.el7.x86_64.rpm
[root@a za]# rpm -ivh libselinux-devel-2.5-15.el7.x86_64.rpm
[root@a za]# rpm -ivh libverto-devel-0.2.5-4.el7.x86_64.rpm
[root@a za]# rpm -ivh krb5-devel-1.15.1-50.el7.x86_64.rpm
[root@a za]# rpm -ivh openssl-devel-1.0.2k-19.el7.x86_64.rpm
---------
[root@a nginx-1.6.3]# ./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@a nginx-1.6.3]# make && make install
然后在建立一个系统用户
[root@a ~]# useradd -M -s /sbin/nologin nginx
[root@a ~]# /usr/local/nginx/sbin/nginx
[root@a ~]# netstat -antp | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 14480/nginx: master
[root@a ~]# cd /usr/local/nginx/sbin/
[root@a sbin]# ./nginx -s stop
[root@a sbin]# ./nginx
然后试着查看一下nginx是否可以启动
可以
但是之后按照
upstream tomcat_server{
server 172.16.1.10:8080 weight=1;
server 172.16.1.20:8080 weight=1;
}
proxy_pass http://tomcat_server;
最后发现网页直接报错了
然后发现又是防火墙的问题!!!!
systemctl stop firewalld.service 把tomcat服务器的防火墙给关了
但是
还是访问不了jsp页面
其他人的方法.
添加
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
在这个位置
然后重启nginx功能
终于成功了!!!!!!!!