Tomcat服务器搭建实验
1.实现LNT同主机实现
1、安装并启动tomcat 1)OpenJDK的安装 yum install java-1.8.0-openjdk-devel.x86_64 确定JDK是否安装可以使用如下命令 java -version ##可以看到版本,说明安装成功 2)tomcat安装 yum install tomcat tomcat-admin-webapps tomcat-docs-webapp tomcat-webapps service tomcat start ss -ntl 监听的端口有三个:8080为http协议的接口,8009为ajp协议的接口,8005为管理接口 2、安装nginx并配置 vim /etc/nginx/nginx.conf 在server段增加如下内容 root /usr/local/tomcat/webapps/ROOT; ##表示访问静态文件就访问nginx的这个目录,此目录是tomcat默认根目录。 index index.jsp; location ~* \.(jsp|do)$ { ##访问的是jsp或者do结尾的动态文件就调度到后端主机tomcat proxy_pass :8080; } nginx -t service nginx restart ##这里直接访问80端口就可以了看到tomcat默认主页面了 2.实现LAT同主机(静态网页)
1、安装并启动tomcat 1)OpenJDK的安装 yum install java-1.8.0-openjdk-devel.x86_64 确定JDK是否安装可以使用如下命令 java -version ##可以看到版本,说明安装成功 2)tomcat安装 yum install tomcat tomcat-admin-webapps tomcat-docs-webapp tomcat-webapps service tomcat start ss -ntl 监听的端口有三个:8080为http协议的接口,8009为ajp协议的接口,8005为管理接口 2、安装httpd服务并确保有ajp_module和http_module httpd -M |grep "proxy" ##查看模块是否已经加载,如果没有加载,要在配置文件中加载这些模块 proxy_module (shared) proxy_ajp_module (shared) ##表示反向代理时后端服务器是aip协议 proxy_balancer_module (shared) proxy_connect_module (shared) proxy_express_module (shared) proxy_fcgi_module (shared) proxy_fdpass_module (shared) proxy_ftp_module (shared) proxy_http_module (shared) ##表示反向代理时后端主机时http协议 proxy_scgi_module (shared) proxy_wstunnel_module (shared) 3、与后端tomcat使用http协议连接时配置 vim /etc/httpd/conf.d/tomcat.conf <virtualhost *:80> documentroot "/usr/share/tomcat/webapps/ROOT" <directory "usr/local/tomcat/webapps/ROOT"> require all granted </directory> proxyrequests off ##关闭正向代理,不加可以 proxyvia on proxypreservehost on proxypass "/" "http://127.0.0.1:8080/" proxypassreverse "/" "http://127.0.0.1:8080/" </virtualhost> httpd -t systemctl start httpd 测试:http://172.18.21.107/ 4、与后tomcat连接时使用的ajp协议时的配置 vim /etc/httpd/conf.d/tomcat.conf <virtualhost *:80> documentroot "/usr/local/tomcat/webapps/ROOT" <directory "usr/local/tomcat/webapps/ROOT"> require all granted </directory> proxyrequests off proxyvia on proxypreservehost on proxypass "/" "ajp://127.0.0.1:8009/" proxypassreverse "/" "ajp://127.0.0.1:8009/" </virtualhost> httpd -t systemctl reload httpd 5、测试 http://172.18.21.107/ 3.实现lnmt的zrlog博客搭建环境:
A主机:tomcat,nginx,ip地址为192.168.213.251
B主机:数据库,ip地址为192.168.213.253