第十三周-day58-Tomcat与阿里云
准备一台阿里云实例
Tomcat 阿里云
云服务器
架构
知识点 概念
ECS 快照 镜像
EIP
RDS
NAS
OSS
DNS和CDN
ESS(弹性伸缩)
yum install -y tree vim wget bash-completion bash-completion-extras lrzsz net-tools sysstat iotop iftop htop unzip nc nmap telnet bc psmisc httpd-tools bind-utils
#准备jdk环境
[root@web01 tools]# tar xf jdk-8u60-linux-x64.tar.gz
[root@web01 tools]# mkdir -p /application/
[root@web01 tools]# mv jdk
jdk1.8.0_60/ jdk-8u60-linux-x64.tar.gz
[root@web01 tools]# mv jdk1.8.0_60/ /application/jdk-1.8.0
[root@web01 tools]# ln -s /application/jdk-1.8.0 /application/jdk
[root@web01 tools]# ll /application/
total 0
lrwxrwxrwx 1 root root 22 Mar 26 16:56 jdk -> /application/jdk-1.8.0
drwxr-xr-x 8 10 143 255 Aug 5 2015 jdk-1.8.0
配置JDK环境变量
[root@web01 tools]# cat >>/etc/profile<<'EOF'
export JAVA_HOME=/application/jdk
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
EOF
[root@web01 tools]# . /etc/profile
[root@web01 tools]# java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
[root@web01 tools]#
#部署Tomcat
[root@web01 tools]# tar xf apache-tomcat-8.0.27.tar.gz
[root@web01 tools]# ll
total 185912
drwxr-xr-x 9 root root 160 Mar 26 17:07 apache-tomcat-8.0.27
-rw-r--r-- 1 root root 9128610 Oct 5 2015 apache-tomcat-8.0.27.tar.gz
-rw-r--r-- 1 root root 181238643 Oct 5 2015 jdk-8u60-linux-x64.tar.gz
-rw-r--r-- 1 root root 332 Mar 26 16:59 profile.txt
[root@web01 tools]# mv apache-tomcat-8.0.27 /application/tomcat-8.0.27
[root@web01 tools]# ln -s /application/tomcat-8.0.27 /application/tomcat
[root@web01 tools]# echo 'export TOMCAT_HOME=/application/tomcat' >>/etc/profile
[root@web01 tools]# . /etc/profile
#检测 tomcat jdk环境变量是否ok
[root@web01 tools]# /application/tomcat/bin/version.sh
Using CATALINA_BASE: /application/tomcat
Using CATALINA_HOME: /application/tomcat
Using CATALINA_TMPDIR: /application/tomcat/temp
Using JRE_HOME: /application/jdk
Using CLASSPATH: /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar
Server version: Apache Tomcat/8.0.27
Server built: Sep 28 2015 08:17:25 UTC
Server number: 8.0.27.0
OS Name: Linux
OS Version: 3.10.0-862.el7.x86_64
Architecture: amd64
JVM Version: 1.8.0_60-b27
JVM Vendor: Oracle Corporation
#启动 tomcat
[root@web01 bin]# /app/tomcat/bin/startup.sh
Using CATALINA_BASE: /application/tomcat
Using CATALINA_HOME: /application/tomcat
Using CATALINA_TMPDIR: /application/tomcat/temp
Using JRE_HOME: /application/jdk
Using CLASSPATH: /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar
Tomcat started.
#检查进程
[root@lcx-01 app]# ss -lntup|grep java
[root@web01 bin]# ps -ef |grep java
root 21656 1 10 17:17 pts/0 00:00:06 /application/jdk/bin/java -Djava.util.logging.config.file=/application/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/application/tomcat/endorsed -classpath /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/application/tomcat -Dcatalina.home=/application/tomcat -Djava.io.tmpdir=/application/tomcat/temp org.apache.catalina.startup.Bootstrap start
[root@lcx-01 app]# ll /app/tomcat/
total 112
drwxr-xr-x 2 root root 4096 Jul 5 09:46 bin
drwxr-xr-x 3 root root 4096 Jul 5 10:11 conf
drwxr-xr-x 2 root root 4096 Jul 5 09:46 lib
-rw-r--r-- 1 root root 57011 Sep 28 2015 LICENSE
drwxr-xr-x 2 root root 4096 Jul 5 10:11 logs
-rw-r--r-- 1 root root 1444 Sep 28 2015 NOTICE
-rw-r--r-- 1 root root 6741 Sep 28 2015 RELEASE-NOTES
-rw-r--r-- 1 root root 16204 Sep 28 2015 RUNNING.txt
drwxr-xr-x 2 root root 4096 Jul 5 09:46 temp
drwxr-xr-x 7 root root 4096 Sep 28 2015 webapps
drwxr-xr-x 3 root root 4096 Jul 5 10:11 work
[root@lcx-01 app]# ls -l /app/tomcat/bin/{startup,shutdown,catalina,version}.sh
-rwxr-xr-x 1 root root 21389 Sep 28 2015 /app/tomcat/bin/catalina.sh #核心
-rwxr-xr-x 1 root root 1902 Sep 28 2015 /app/tomcat/bin/shutdown.sh #检查端口和进程是否没,关闭
-rwxr-xr-x 1 root root 1904 Sep 28 2015 /app/tomcat/bin/startup.sh #启动
-rwxr-xr-x 1 root root 1908 Sep 28 2015 /app/tomcat/bin/version.sh
[root@lcx-01 tomcat]# ll conf/
total 216
drwxr-xr-x 3 root root 4096 Jul 5 10:11 Catalina
-rw------- 1 root root 12374 Sep 28 2015 catalina.policy
-rw------- 1 root root 7106 Sep 28 2015 catalina.properties
-rw------- 1 root root 1577 Sep 28 2015 context.xml
-rw------- 1 root root 3387 Sep 28 2015 logging.properties
-rw------- 1 root root 6458 Sep 28 2015 server.xml
-rw------- 1 root root 1744 Sep 28 2015 tomcat-users.xml
-rw------- 1 root root 1846 Sep 28 2015 tomcat-users.xsd
-rw------- 1 root root 167302 Sep 28 2015 web.xml
properties 属性
[root@lcx-01 tomcat]# ll logs/
total 144
-rw-r--r-- 1 root root 65763 Jul 5 10:26 catalina.2019-07-05.log
-rw-r--r-- 1 root root 65811 Jul 5 10:26 catalina.out #核心日志
-rw-r--r-- 1 root root 0 Jul 5 10:11 host-manager.2019-07-05.log
-rw-r--r-- 1 root root 2504 Jul 5 10:26 localhost.2019-07-05.log
-rw-r--r-- 1 root root 2478 Jul 5 10:32 localhost_access_log.2019-07-05.txt
-rw-r--r-- 1 root root 0 Jul 5 10:11 manager.2019-07-05.log
nginx html 站点目录
[root@lcx-01 tomcat]# vim /server/scripts/01.py
# -*- encoding: utf-8 -*-
print('厉害了 老铁')
print('双击666')
[root@lcx-01 tomcat]# python /server/scripts/01.py
厉害了 老铁
双击666
[root@lcx-01 tomcat]# cat conf/tomcat-users.xml
#账号密码
[root@lcx-01 tomcat]# ll conf/server.xml
-rw------- 1 root root 6458 Jul 5 10:58 conf/server.xml
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000" #超市时间(ms)
redirectPort="8443" /> #https时候
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
Tomcat | Nginx |
---|---|
Host name=“localhost” | server_name |
appBase=“webapps” | root |
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<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@lcx-01 tomcat]# yum install -y mariadb-server
[root@lcx-01 tomcat]#
[root@lcx-01 tomcat]# systemctl restart mariadb.service
[root@lcx-01 tomcat]# systemctl enable mariadb.service
[root@lcx-01 tomcat]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-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)]>
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)]> grant all on jpress.* to jpress@'172.17.%.%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> drop user ''@'lcx-01'; #删除空表
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> drop user ''@'localhost'; #删除空表
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all on jpress.* to root@'oldboy' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> select user,host from mysql.user; #查看表
+-----------+-------------+
| user | host |
+-----------+-------------+
| root | 127.0.0.1 |
| jpress | 172.17.%.% |
| root | ::1 |
| root | lcx-01 |
| jpress | localhost |
| root | localhost |
| root | oldboy |
+-----------+-------------+
8 rows in set (0.00 sec)
MariaDB [(none)]> flush privileges; #刷新
Query OK, 0 rows affected (0.00 sec)
[root@lcx-01 tomcat]# mysql -ujpress -p -e 'select user();'
Enter password:
+------------------+
| user() |
+------------------+
| jpress@localhost |
+------------------+
[root@lcx-01 tomcat]# su - oldboy -c whoami
oldboy
[root@lcx-01 tomcat大礼包]# mv jpress-web-newest.war /app/tomcat/webapps/jpress.war
[root@lcx-01 tomcat大礼包]# cd /app/tomcat/webapps/
[root@lcx-01 tomcat大礼包]# ll
total 20336
drwxr-xr-x 14 root root 4096 Jul 5 09:46 docs
drwxr-xr-x 6 root root 4096 Jul 5 09:46 examples
drwxr-xr-x 5 root root 4096 Jul 5 09:46 host-manager
drwxr-xr-x 7 root root 4096 Jul 5 12:40 ipress
-rw-r--r-- 1 root root 20797013 Mar 3 2017 ipress.war
drwxr-xr-x 5 root root 4096 Jul 5 09:46 manager
drwxr-xr-x 3 root root 4096 Jul 5 09:46 ROOT
http://www.linuxcx.cn:8080/ipress/install
#重启Tomcat
[root@lcx-01 tomcat]# pkill java
[root@lcx-01 tomcat]# ps -ef|grep java
[root@lcx-01 tomcat]#
[root@lcx-01 tomcat]# /app/tomcat/bin/startup.sh
Using CATALINA_BASE: /app/tomcat
Using CATALINA_HOME: /app/tomcat
Using CATALINA_TMPDIR: /app/tomcat/temp
Using JRE_HOME: /app/jdk
Using CLASSPATH: /app/tomcat/bin/bootstrap.jar:/app/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@lcx-01 tomcat]# ps -ef|grep java
root 5065 1 99 13:14 pts/4 00:00:02 /app/jdk/bin/java -Djava.util.logging.config.file=/app/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/app/tomcat/endorsed -classpath /app/tomcat/bin/bootstrap.jar:/app/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/app/tomcat -Dcatalina.home=/app/tomcat -Djava.io.tmpdir=/app/tomcat/temp org.apache.catalina.startup.Bootstrap start
root 5082 2377 0 13:14 pts/4 00:00:00 grep --color=auto java
[root@lcx-01 tomcat]#
点击链接查看图片:
http://www.linuxcx.cn:8080/jpress/c/该吃午饭拉
图片的存放路径
#查看图片路径
[root@lcx-01 tomcat]# ll webapps/jpress
total 24
drwxr-xr-x 3 root root 4096 Jul 5 13:17 attachment
drwxr-xr-x 3 root root 4096 Jul 5 12:56 META-INF
-rw-r--r-- 1 root root 96 Jul 27 2016 robots.txt
drwxr-xr-x 11 root root 4096 Jul 5 12:56 static
drwxr-xr-x 4 root root 4096 Jul 5 12:56 templates
drwxr-xr-x 6 root root 4096 Jul 5 12:56 WEB-INF
[root@lcx-01 tomcat]# ll webapps/jpress/attachment/20190705/
total 68
-rw-r--r-- 1 root root 22329 Jul 5 13:17 c41dda8267174a0a81de850224eaac3b_780x240.jpg
-rw-r--r-- 1 root root 42347 Jul 5 13:17 c41dda8267174a0a81de850224eaac3b.jpg