1、基于nfs实现openstack云盘容量的扩容(留坑,待完成)
2、安装配置tomcat,实现对java代码访问
2.1 环境准备
Ubuntu 18.04 :192.168.7.18
2.2 安装默认JDK
<root@ubuntu181 ~>#apt-get install default-jdk
<root@ubuntu181 ~>#java -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu118.04.1)
OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu118.04.1, mixed mode, sharing)
2.3 安装tomcat
<root@ubuntu181 src>#cd /usr/local/src
<root@ubuntu181 src>#tar xvf apache-tomcat-8.5.57.tar.gz
创建软连接
<root@ubuntu181 src>#ln -sv apache-tomcat-8.5.57 tomcat
'tomcat' -> 'apache-tomcat-8.5.57'
修改权限
<root@ubuntu181 tomcat>#groupadd -r tomcat && useradd -g tomcat -r tomcat
<root@ubuntu181 tomcat>#chown -Rv tomcat.tomcat /usr/local/src/apache-tomcat-8.5.57 #对软连接修改无效
启动
<root@ubuntu181 tomcat>#su - tomcat -c '/usr/local/src/tomcat/bin/startup.sh'
访问 192.168.7.18:8080
2.4 主页实验
2.4.1 添加html文件
<root@ubuntu181 WEB-INF>#echo 88888 > /usr/local/src/tomcat/webapps/ROOT/index.html
访问 192.168.7.18:8080
2.4.2 修改主页配置
<root@ubuntu181 WEB-INF>#vim /usr/local/src/tomcat/webapps/ROOT/WEB-INF/web.xml
<description>
Welcome to Tomcat
</description>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
访问 192.168.7.18:8080
2.5 部署(deploy)实验
2.5.1 创建相关目录
<root@ubuntu181 myapp>#mkdir projects/myapp/{WEB-INF,classes,lib} -pv
mkdir: created directory 'projects'
mkdir: created directory 'projects/myapp'
mkdir: created directory 'projects/myapp/WEB-INF'
mkdir: created directory 'projects/myapp/classes'
mkdir: created directory 'projects/myapp/lib'
2.5.2 创建index.jsp文件
<root@ubuntu181 myapp>#cat index.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>
myapp/test.jsp 后面的内容是服务器端动态生成字符串,最后拼接在一起
<%
out.println("hello jsp");
%>
</body>
</html>
拷贝至webapps目录下
<root@ubuntu181 projects>#cp -r myapp/ /usr/local/src/tomcat/webapps/ # 自动部署
2.5.3 访问:http://192.168.7.18:8080/myapp/index.jsp
2.6 用户认证
2.6.1 修改/usr/local/src/tomcat/conf/tomcat-users.xml配置文件
<root@ubuntu181 conf>#vim tomcat-users.xml
-->
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<user username="magedu" password="magedu" roles="manager-gui,admin-gui"/>
</tomcat-users>
2.6.2 修改/usr/local/src/tomcat/webapps/manager/META-INF/context.xml配置文件
<root@ubuntu181 META-INF>#vim context.xml
<Context antiResourceLocking="false" privileged="true" >
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.*" />
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
2.6.3 修改/usr/local/src/tomcat/webapps/host-manager/META-INF/context.xml配置文件
<root@ubuntu181 META-INF>#vim context.xml
<Context antiResourceLocking="false" privileged="true" >
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.*" />
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
2.6.4 访问测试
启动前查看配置
<root@ubuntu181 bin>#./catalina.sh configtest
重启tomcat
<root@ubuntu181 bin>#sh shutdown.sh
Using CATALINA_BASE: /usr/local/src/tomcat
Using CATALINA_HOME: /usr/local/src/tomcat
Using CATALINA_TMPDIR: /usr/local/src/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/src/tomcat/bin/bootstrap.jar:/usr/local/src/tomcat/bin/tomcat-juli.jar
NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
<root@ubuntu181 bin>#sh startup.sh
Using CATALINA_BASE: /usr/local/src/tomcat
Using CATALINA_HOME: /usr/local/src/tomcat
Using CATALINA_TMPDIR: /usr/local/src/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/src/tomcat/bin/bootstrap.jar:/usr/local/src/tomcat/bin/tomcat-juli.jarTomcat started.
2.7 虚拟主机配置实验
2.7.1 创建相关目录文件
<root@ubuntu181 META-INF>#mkdir /data/webapps -pv
mkdir: created directory '/data'
mkdir: created directory '/data/webapps'
cd /usr/local/src/tomcat/webapps
<root@ubuntu181 webapps>#cp -r /usr/local/src/tomcat/webapps/myapp/ /data/webapps/ROOT
<root@ubuntu181 ROOT>#cat index.jsp
node1/test.jsp 后面的内容是服务器端动态生成字符串,最后拼接在一起
2.7.2 修改/usr/local/src/tomcat/conf/server.xml配置文件
<root@ubuntu181 META-INF>#vim context.xml
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
autoDeploy="false" />
</Engine>
</Service>
</Server>
2.7.3 访问测试
<root@ubuntu181 bin>#cd /usr/local/src/tomcat/bin
<root@ubuntu181 bin>#sh shutdown.sh
<root@ubuntu181 bin>#sh startup.sh
修改C:\Windows\System32\drivers\hosts文件
2.8 Context配置
2.8.1 创建相关目录文件
<root@ubuntu181 data>#cp -r /usr/local/src/tomcat/webapps/myapp/ /data/myappv1
<root@ubuntu181 myappv1>#vim index.jsp
myappv1/test.jsp 后面的内容是服务器端动态生成字符串,最后拼接在一起
<root@ubuntu181 myappv1>#ln -sv /data/myappv1/ /data/test
'/data/test' -> '/data/myappv1/'
2.6.2 修改/usr/local/src/tomcat/conf/server.xml配置文件
<root@ubuntu181 META-INF>#vim context.xml
<Host name="node1.magedu.com" appBase="/data/webapps" unpackWARs="true" autoDeploy="true" >
<Context path="/test" docBase="/data/test" reloadable="false" />
</Host>
访问 http://node1.magedu.com:8080/test/