一、动态站点
准备数据库
[root@node05 ~]# yum install mariadb-server -y
[root@node05 ~]# systemctl enable --now mariadb
[root@node05 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database jpress default character set utf8;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on jpress.* to jpress@localhost identified by '123456';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]>
部署 jpress
[root@node05 webapps]# ll
total 20316
drwxr-x--- 14 root root 4096 Mar 7 08:33 docs
drwxr-x--- 6 root root 83 Mar 7 08:33 examples
drwxr-x--- 5 root root 87 Mar 7 08:33 host-manager
drwxr-x--- 7 root root 102 Mar 7 16:06 jpress-web-newest
-rw-r--r-- 1 root root 20797013 Aug 9 2020 jpress-web-newest.war
drwxr-x--- 5 root root 103 Mar 7 08:33 manager
drwxr-x--- 3 root root 306 Mar 7 08:33 ROOT
上传压缩包,自动解压到当前路径!*
浏览器登录:http://192.168.5.15:8080/jpress-web-newest
单机下一步,继续
配置数据库信息
设置管理员密码
等待安装 jpress
部署完成
二、虚拟主机
修改 Tomcat 配置文件
[root@node05 ~]# cd /usr/local/tomcat/conf/
[root@node05 conf]# cp server.xml{,.bak}
[root@node05 conf]# vim server.xml
<Host name="www.a.com" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context docBase="/web/a" path="" reloadable="flase" />
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
<Host name="www.b.com" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context docBase="/web/b" path="" reloadable="flase" />
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
[root@node05 conf]# mkdir -p /web/{a,b}
[root@node05 conf]# vim /web/a/index.jsp
<html>
<head>
<title>JSP a page</title>
</head>
<body>
<% out.println("Welocome to test site,http://www.a.com");%>
</body>
</html>
[root@node05 conf]# vim /web/b/index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>JSP b page</title>
</head>
<body>
<% out.println("Welocome to test site,http://www.b.com");%>
</body>
</html>
[root@node05 conf]# systemctl restart tomcat.service
添加hosts解析
浏览器访问:http://www.a.com:8080/
浏览器访问:http://www.b.com:8080/