tomcat
#: 安装jdk [root@localhost ~]# yum install jdk-8u211-linux-x64.rpm -y #:导入环境变量 [root@localhost java]# vim /etc/profile.d/jdk.sh export JAVA_HOME=/usr/java/default export PATH=$JAVA_HOME/bin:$PATH [root@localhost java]# . /etc/profile.d/jdk.sh [root@localhost java]# . /etc/profile.d/jdk.sh #: 安装tomcat [root@localhost ~]# tar xf apache-tomcat-8.5.42.tar.gz -C /usr/local/ [root@localhost ~]# cd /usr/local/ [root@localhost local]# ln -sv apache-tomcat-8.5.42/ tomcat #:创建Java用户 [root@localhost tomcat]# useradd -r java #: 修改属主属组 [root@localhost tomcat]# chown -R java.java ./* #: 启动服务 [root@localhost tomcat]# su - java -c "/usr/local/tomcat/bin/catalina.sh start"
#: 修改默认页 [root@localhost tomcat]# vim /usr/local/tomcat/conf/web.xml <welcome-file-list> <welcome-file>index.jsp</welcome-file> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> </welcome-file-list> #:在ROOT目录下添加一个test.jsp,然后访问 [root@localhost ROOT]# vim test.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>jsp例子</title> </head> <body> 后面的内容是服务器端动态生成字符串,最后拼接在一起 <% out.println("hello jsp"); %> %</body> %</html> % #:然后通过网页访问,访问后在此目录下会有转换后的文件 [root@localhost tomcat]# cd work/Catalina/localhost/ROOT/org/apache/jsp/ [root@localhost jsp]# ll total 68 -rw-r----- 1 java java 18182 Jun 5 04:31 index_jsp.class -rw-r----- 1 java java 30078 Jun 5 04:31 index_jsp.java -rw-r----- 1 java java 5644 Sep 2 10:16 test_jsp.class -rw-r----- 1 java java 5004 Sep 2 10:16 test_jsp.java #:部署一个应用,跟ROOT目录同级 [root@localhost webapps]# mkdir myapp/{WEB-INF,class,lib} -pv [root@localhost webapps]# cp ROOT/test.jsp myapp/index.jsp #:在此访问 http://192.168.5.101:8080/myapp/ #: 修改管理接口的SHUTDOWN命令 [root@localhost tomcat]# vim conf/server.xml <Server port="8005" shutdown="slkfjlsjflksjdglksvv">
#:用户认证 [root@localhost tomcat]# vim conf/tomcat-users.xml <role rolename="manager-gui"/> <user username="tomcat" password="maxuebin" roles="manager-gui"/> [root@localhost tomcat]# vim webapps/manager/META-INF/context.xml allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.168.*" /> [root@localhost tomcat]# su - tomcat -c "bin/startup.sh"
#:虚拟机配置 尝试再配置一个虚拟主机,并将myapp部署到/data/webapps目录下 [root@localhost ~]# mkdir /data/webapps -pv [root@localhost ~]# cp /usr/local/tomcat/webapps/myapp/index.jsp /data/webapps/ROOT/ [root@localhost ~]# vim /usr/local/tomcat/conf/server.xml <Host name="www.magedu.net" appBase="/data/webapps/"> </Host> #:在物理机hosts解析,访问测试
http://www.magedu.net:8080
#:contex配置
[root@localhost conf]# vim server.xml
<Context path="/test" docBase="/data/test" reloadable="" /> #:reloadable,true表示如果WEB-INF/classes或META-INF/lib目录下.class文件有改动,就会将WEB应用重新加载。 生成环境中,会使用false来禁用。
[root@localhost webapps]# mv ROOT/index.jsp test/
[root@localhost webapps]# ln -sv test/ tests #:注意:这里特别使用了软链接,原因就是以后版本升级,需要将软链接指向myappv2,重启Tomcat。如果新版上 线后,出现问题,重新修改软链接到上一个版本的目录,并重启,就可以实现回滚
#:访问测试
http://www.magedu.net:8080/tests/
#: tomcat和nginx结合 [root@localhost webapps]# vim /etc/nginx/nginx.conf location / { proxy_pass http://127.0.0.1:8080; } #:实现动静分离 [root@localhost webapps]# vim /etc/nginx/nginx.conf location / { root /data/webapps/ROOT; index index.html; } location ~* \.jsp { proxy_pass http://127.0.0.1:8080; } [root@localhost ROOT]# cd /data/webapps/ROOT/ [root@localhost ROOT]# vim index.html this is html [root@localhost ROOT]# cp ../test/index.jsp ./ #:分别测试
#:host-manager配置 [root@localhost tomcat]# vim conf/tomcat-users.xml <role rolename="admin-gui"/> <user username="tom" password="centos" roles="admin-gui"/> [root@localhost tomcat]# su - tomcat -c "/usr/local/tomcat/bin/shutdown.sh" [root@localhost tomcat]# su - tomcat -c "/usr/local/tomcat/bin/startup.sh"
# httpd和tomcat结合 [root@localhost ~]# httpd -M |grep proxy # 注释中心主机 [root@localhost conf.d]# vim /etc/httpd/conf/httpd.conf #DocumentRoot "/var/www/html" #:创建虚拟主机 [root@localhost conf.d]# vim virthost.conf <VirtualHost *:80> ServerName node1.magedu.com ProxyRequests Off ProxyVia On ProxyPreserveHost On ProxyPass / http://127.0.0.1:8080/ ProxyPassReverse / http://127.0.0.1:8080/ </VirtualHost> ProxyRequests:Off关闭正向代理。 ProxyPass:反向代理指令 ProxyPassReverse:保留代理的response头不重写(个别除外) ProxyPreserveHost:On开启。让代理保留原请求的Host首部 #:测试 #:proxy_ajp_module模块代理配置 [root@localhost conf.d]# vim virthost.conf <VirtualHost *:80> ServerName node1.magedu.com ProxyRequests Off ProxyVia On ProxyPreserveHost On ProxyPass / ajp://127.0.0.1:8009/ </VirtualHost>