2、tomcat应用程序部署
部署(deploy)webapp的相关操作:
deploy:将webapp的源文件放置于目标目录、配置tomcat服务器能够基于context.xml文件中定义的路径来访问此webapp;将其特有的类通过class loader装载至tomcat:
有两种方式:
自动部署:auto deploy
手动部署:
(1) 冷部署:把webapp复制到指定位置,而后才启动tomcat;
(2) 热部署:在不停止tomcat的前提下进行的部署:
部署工具:manager app、ant脚本、tcd(Tomcat Client Deployer)等;
undeploy:反部署,停止webapp,并从tomcat实例上拆除其部署文件和部署名;
stop:停止,不再向用户提供服务;
start:启动处于“停止”状态的webapp;
redeploy:重新部署;
tomcat自带的应用程序:
manager app: webapp管理工具;
host manager: VHosts管理工具;
(1)手动创建一个测试应用程序
~]# cd /usr/local/tomcat/webapps/
webapps]# ls
docs examples host-manager manager ROOT
webapps]# mkdir myapp
webapps]# cd myapp/
myapp]# mkdir class lib WEB-INF META-INF
[root@localhost myapp]# ls
class lib META-INF WEB-INF
myapp]# vim index.jsp
myapp]# cat index.jsp
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<html>
<head>
<title>JSP Test Page</title>
</head>
<body>
<% out.println("hello world");
%>
</body>
</html>

此时由于tomcat默认为热部署,所以网页已经可以正常访问
tomcat会默认把jsp网页编译成java语言
~]# cd /usr/local/tomcat/work/Catalina/localhost/myapp/org/apache/jsp/
jsp]# ls
index_jsp.class index_jsp.java
(2)tomcat自带的应用程序


提示用户在conf/tomcat-users.xml下进行配置
~]# cd /usr/local/tomcat/conf/
conf]# vim tomcat-users.xml
在<tomcat-users>下面添加
<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui"/>
重启tomcat服务
conf]# catalina.sh stop
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/latest
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
conf]# catalina.sh configtest
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/latest
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
四月 26, 2017 12:18:23 下午 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environmen
ts was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib四月 26, 2017 12:18:24 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-bio-8080"]
四月 26, 2017 12:18:24 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["ajp-bio-8009"]
四月 26, 2017 12:18:24 下午 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 1348 ms
conf]# catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/latest
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
conf]# ss -tnlp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
users:(("sshd",pid=1071,fd=3))LISTEN 0 100 127.0.0.1:25 *:*
users:(("master",pid=1429,fd=13))LISTEN 0 100 :::8009 :::*
users:(("java",pid=16600,fd=43))LISTEN 0 100 :::8080 :::*
users:(("java",pid=16600,fd=42))LISTEN 0 128 :::22 :::*
users:(("sshd",pid=1071,fd=4))LISTEN 0 100 ::1:25 :::*
users:(("master",pid=1429,fd=14))




管理页面可以对web app进行部署,开启,关闭,reload,update
(3)部署一个商城app进行测试
商城app解压
~]# unzip shopxx-a5-Beta.zip
~]# ls
all.sql apache-tomcat-7.0.55.tar.gz shopxx-a5-Beta.zip 说明.htm
anaconda-ks.cfg jdk-7u79-linux-x64.rpm shopxx-v3.0-Beta
将文件mv至部署目录
~]# cd shopxx-v3.0-Beta/shopxx-3.0Beta/
shopxx-3.0Beta]# ls
admin favicon.ico install META-INF robots.txt upload
changelog.txt index.jsp license.html resources shopxx.txt WEB-INF
hopxx-3.0Beta]# ls install/
check_encoding.jsp css index.html install_demo.jsp js
check.jsp data index.jsp install_init.jsp sample
common.jsp images install_config.jsp install.jsp setting.jsp
shopxx-3.0Beta]# cd ..
shopxx-v3.0-Beta]# ls
shopxx-3.0Beta
shopxx-v3.0-Beta]# mv shopxx-3.0Beta/ /usr/local/tomcat/webapps/shopxx
此时网站已经可以正常访问

配置后台数据库
~]# yum -y install mariadb-server
~]# systemctl start mariadb.service
~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2016,
Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> GRANT ALL ON shopxx.* to shopxx@'localhost' IDENTIFIED BY 'shopxx';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT ALL ON shopxx.* to shopxx@'127.0.0.1' IDENTIFIED BY 'shopxx';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye



安装提示删除install目录,并重启
~]# cd /usr/local/tomcat/
tomcat]# ls
bin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work
tomcat]# cd webapps/
webapps]# ls
docs examples host-manager manager myapp ROOT shopxx
webapps]# cd shopxx/
shopxx]# ls
admin changelog.txt index.html license.html product robots.txt sitemap WEB-INF
article favicon.ico install META-INF resources shopxx.txt upload
shopxx]# mv install/ install.bak
此时我的tomcat管理界面上已经有shopxx应用,进行reload操作,或者使用catalina.sh进行stop再start

此时网站部署完成
