标签:webapp str tables 修改 tput startup opp sed rzsz
1、在windows安装xshell(非必需,但是推荐)
2、在linux安装Linux与windows文件传输工具RZSZ
[root@192 ~]# yum install lrzsz
windows下下载linux的jre(http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jre-7u79-linux-x64.tar.gz?AuthParam=1494032273_7bab4bfca10697b99871cea7baab274c)
windows下下载linux的tomcat7(https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.77/bin/apache-tomcat-7.0.77.tar.gz)
# 下载完成后在linux下创建要存放压缩包的文件夹: [root@192 ~]# mkdir /usr/wangzf [root@192 ~]# mkdir /usr/wangzf/downloads [root@192 ~]# cd /usr/wangzf/downloads/ # 在windows下将jre-7u79-linux-x64.tar.gz和apache-tomcat-7.0.77.tar.gz拖动到xshell窗口,完成tar包的文件传输 [root@192 downloads]# pwd /usr/wangzf/downloads [root@192 downloads]# ll total 54756 -rw-r--r--. 1 root root 8967197 May 5 20:58 apache-tomcat-7.0.77.tar.gz -rw-r--r--. 1 root root 47098831 May 5 21:02 jre-7u79-linux-x64.tar.gz
# 解压jre-7u79-linux-x64.tar.gz到/usr/wangzf/ [root@192 downloads]# tar -xzvf jre-7u79-linux-x64.tar.gz -C /usr/wangzf/ # 解压apache-tomcat-7.0.77.tar.gz到/usr/local/tomcat [root@192 downloads]# tar -xzvf apache-tomcat-7.0.77.tar.gz -C /usr/wangzf/ # 查看解压后的两个文件夹 [root@192 downloads]# cd /usr/wangzf/ [root@192 wangzf]# ll total 12 drwxr-xr-x. 9 root root 4096 May 5 23:04 apache-tomcat-7.0.77 drwxr-xr-x. 2 root root 4096 May 5 22:47 downloads drwxr-xr-x. 6 uucp 143 4096 Apr 10 2015 jre1.7.0_79 # 重命名文件夹 [root@192 wangzf]# mv jre1.7.0_79/ jre1.7 [root@192 wangzf]# mv apache-tomcat-7.0.77/ tomcat7 [root@192 wangzf]# ll total 12 drwxr-xr-x. 2 root root 4096 May 5 22:47 downloads drwxr-xr-x. 6 uucp 143 4096 Apr 10 2015 jre1.7 drwxr-xr-x. 9 root root 4096 May 5 23:04 tomcat7 # 一般jre1.x都在java文件夹下,现在移动下 [root@192 wangzf]# mkdir /usr/wangzf/java [root@192 wangzf]# mv jre1.7/ ./java/jre1.7 [root@192 wangzf]# ll total 12 drwxr-xr-x. 2 root root 4096 May 5 22:47 downloads drwxr-xr-x. 3 root root 4096 May 5 23:13 java drwxr-xr-x. 9 root root 4096 May 5 23:04 tomcat7 [root@192 wangzf]# ll ./java/ total 4 drwxr-xr-x. 6 uucp 143 4096 Apr 10 2015 jre1.7
3.1、配置jre环境
# 将java环境配置到/etc/profile.d/java.sh [root@192 wangzf]# vi /etc/profile.d/java.sh # 将以下内容写入文件: JAVA_HOME=/usr/wangzf/java JRE_HOME=$JAVA_HOME/jre1.7 PATH=$PATH:$JRE_HOME/bin CLASSPATH=$JRE_HOME/lib/rt.jar:$JRE_HOME/lib/ext export JAVA_HOME export JRE_HOME export PATH export CLASSPATH # 使用source命令重新执行java.sh中的命令而不用注销并重新登录 [root@192 wangzf]# source /etc/profile.d/java.sh # 查看刚刚的环境变量 [root@192 wangzf]# echo $JAVA_HOME /usr/wangzf/java [root@192 wangzf]# echo $JRE_HOME /usr/wangzf/java/jre1.7 [root@192 wangzf]# echo $PATH /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/wangzf/java/jre1.7/bin [root@192 wangzf]# echo $CLASSPATH /usr/wangzf/java/jre1.7/lib/rt.jar:/usr/wangzf/java/jre1.7/lib/ext # 测试java环境 [root@192 wangzf]# java -version java version "1.7.0_79" Java(TM) SE Runtime Environment (build 1.7.0_79-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
3.2、配置tomcat环境
# 将tomcat环境配置到/etc/profile.d/tomcat.sh [root@192 ~]# vi /etc/profile.d/tomcat.sh # 在tomcat.sh中写入以下内容 CATALINA_BASE=/usr/wangzf/tomcat7 PATH=$PATH:$CATALINA_BASE/bin export CATALINA_BASE export PATH # 执行tomcat.sh脚本,使之生效 [root@192 ~]# source /etc/profile.d/tomcat.sh # 查看环境变量PATH [root@192 ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/wangzf/java/jre1.7/bin:/usr/wangzf/tomcat7/bin # 查看tomcat的版本状态 [root@192 ~]# catalina.sh version Using CATALINA_BASE: /usr/wangzf/tomcat7 Using CATALINA_HOME: /usr/wangzf/tomcat7 Using CATALINA_TMPDIR: /usr/wangzf/tomcat7/temp Using JRE_HOME: /usr/wangzf/java/jre1.7 Using CLASSPATH: /usr/wangzf/tomcat7/bin/bootstrap.jar:/usr/wangzf/tomcat7/bin/tomcat-juli.jar Server version: Apache Tomcat/7.0.77 Server built: Mar 28 2017 16:01:48 UTC Server number: 7.0.77.0 OS Name: Linux OS Version: 2.6.32-696.el6.x86_64 Architecture: amd64 JVM Version: 1.7.0_79-b15 JVM Vendor: Oracle Corporation
# 在centos中,开放iptables防火墙的端口80|8080|3306端口 [root@192 ~]# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT [root@192 ~]# /sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT [root@192 ~]# /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT [root@192 ~]# /etc/rc.d/init.d/iptables save iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ] # 查看防火墙的状态 [root@192 ~]# /etc/init.d/iptables status Table: filter Chain INPUT (policy ACCEPT) num target prot opt source destination 1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 2 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:3306 3 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 4 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 5 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 6 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 7 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 8 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT) num target prot opt source destination 1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT) num target prot opt source destination # 在linux下启动tomact [root@192 ~]# startup.sh Using CATALINA_BASE: /usr/wangzf/tomcat7 Using CATALINA_HOME: /usr/wangzf/tomcat7 Using CATALINA_TMPDIR: /usr/wangzf/tomcat7/temp Using JRE_HOME: /usr/wangzf/java/jre1.7 Using CLASSPATH: /usr/wangzf/tomcat7/bin/bootstrap.jar:/usr/wangzf/tomcat7/bin/tomcat-juli.jar Tomcat started. # 查看linux的ip(这里是192.168.22.130) [root@192 ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:45:F2:D8 inet addr:192.168.22.130 Bcast:192.168.22.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe45:f2d8/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:55440 errors:0 dropped:0 overruns:0 frame:0 TX packets:16803 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:66627061 (63.5 MiB) TX bytes:1665738 (1.5 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) # 想要在windows下访问linux的服务器项目,前提是必须能够在windows下ping虚拟机下的centos主机 C:\Users\Administrator>ping 192.168.22.130 正在 Ping 192.168.22.130 具有 32 字节的数据: 来自 192.168.22.130 的回复: 字节=32 时间<1ms TTL=64 来自 192.168.22.130 的回复: 字节=32 时间=5ms TTL=64 来自 192.168.22.130 的回复: 字节=32 时间=1ms TTL=64 来自 192.168.22.130 的回复: 字节=32 时间=1ms TTL=64 192.168.22.130 的 Ping 统计信息: 数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失), 往返行程的估计时间(以毫秒为单位): 最短 = 0ms,最长 = 5ms,平均 = 1ms C:\Users\Administrator> # 在windows下访问http://192.168.22.130:8080/,是不是看到了熟悉的tomcat,大功告成? 如果要关闭tomcat,则执行以下命令: [root@192 ~]# shutdown.sh Using CATALINA_BASE: /usr/wangzf/tomcat7 Using CATALINA_HOME: /usr/wangzf/tomcat7 Using CATALINA_TMPDIR: /usr/wangzf/tomcat7/temp Using JRE_HOME: /usr/wangzf/java/jre1.7 Using CLASSPATH: /usr/wangzf/tomcat7/bin/bootstrap.jar:/usr/wangzf/tomcat7/bin/tomcat-juli.jar
1、使用Eclipse或者MyEclipse创建一个最简单的web项目(本人这里项目名称是MyCentos)
2、在tomcat目录下找到对应的项目,打包成zip(linux没有安装jdk,只安装了jre,所以在linux下不能解压war包,这里压缩成zip),放入/usr/wangzf/Apps目录
# MyCentos.zip的目录结构 MyCentos.zip ├── MyCentos ├── index.jsp ├── META-INF │ └── MANIFEST.MF └── WEB-INF ├── classes ├── lib └── web.xml
# 创建目录/usr/wangzf/Apps用来存放发布的项目 [root@192 ~]# mkdir /usr/wangzf/Apps [root@192 ~]# cd /usr/wangzf/Apps # 将MyCentos.zip拖到xshell窗口上传到当前目录 [root@192 Apps]# rz -E rz waiting to receive. # 查看上传的文件 [root@192 Apps]# ll total 4 -rw-r--r--. 1 root root 1939 May 5 23:36 MyCentos.zip # 在linux下解压缩zip文件需要安装zip和unzip [root@192 Apps]# yum install zip [root@192 Apps]# yum install unzip # 解压MyCentos.zip下的所有文件()到当前目录 [root@192 Apps]# unzip MyCentos.zip Archive: MyCentos.zip creating: MyCentos/ creating: MyCentos/META-INF/ extracting: MyCentos/META-INF/MANIFEST.MF creating: MyCentos/WEB-INF/ creating: MyCentos/WEB-INF/classes/ inflating: MyCentos/WEB-INF/index.jsp creating: MyCentos/WEB-INF/lib/ inflating: MyCentos/WEB-INF/web.xml inflating: MyCentos/index.jsp # 备份并修改tomcat server.xml,加入Context节点,部署项目 [root@192 MyCentos]# cd /usr/wangzf/tomcat7/config/ [root@192 conf]# cp server.xml server.xml.back [root@192 conf]# vi server.xml # server.xml代码片段 ... <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Context docBase="/usr/wangzf/Apps/MyCentos" path="/MyCentosWeb" reloadable="true"/> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> ...
3、启动tomcat
[root@192 conf]# startup.sh Using CATALINA_BASE: /usr/wangzf/tomcat7 Using CATALINA_HOME: /usr/wangzf/tomcat7 Using CATALINA_TMPDIR: /usr/wangzf/tomcat7/temp Using JRE_HOME: /usr/wangzf/java/jre1.7 Using CLASSPATH: /usr/wangzf/tomcat7/bin/bootstrap.jar:/usr/wangzf/tomcat7/bin/tomcat-juli.jar Tomcat started.
4、windows客服端访问
在windows下访问“http://192.168.22.130:8080/MyCentosWeb/”,就可以看到index.jsp的内容了!
# 尚未启动java之前 [root@localhost ~]# ps -ef|grep java root 1428 1413 0 02:47 pts/0 00:00:00 grep java # 尚未启动tomcat之前 [root@localhost ~]# ps -ef|grep tomcat root 1430 1413 0 02:47 pts/0 00:00:00 grep tomcat # 启动tomcat [root@localhost ~]# startup.sh Using CATALINA_BASE: /usr/wangzf/tomcat7 Using CATALINA_HOME: /usr/wangzf/tomcat7 Using CATALINA_TMPDIR: /usr/wangzf/tomcat7/temp Using JRE_HOME: /usr/wangzf/java/jre1.7 Using CLASSPATH: /usr/wangzf/tomcat7/bin/bootstrap.jar:/usr/wangzf/tomcat7/bin/tomcat-juli.jar Tomcat started. # 启动tomcat之后 [root@localhost ~]# ps -ef|grep tomcat root 1439 1 23 02:47 pts/0 00:00:00 /usr/wangzf/java/jre1.7/bin/java -Djava.util.logging.config.file=/usr/wangzf/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.endorsed.dirs=/usr/wangzf/tomcat7/endorsed -classpath /usr/wangzf/tomcat7/bin/bootstrap.jar:/usr/wangzf/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/usr/wangzf/tomcat7 -Dcatalina.home=/usr/wangzf/tomcat7 -Djava.io.tmpdir=/usr/wangzf/tomcat7/temp org.apache.catalina.startup.Bootstrap start root 1450 1413 0 02:47 pts/0 00:00:00 grep tomcat # 启动tomcat(会启动jre)之后 [root@localhost ~]# ps -ef|grep java root 1439 1 36 02:47 pts/0 00:00:12 /usr/wangzf/java/jre1.7/bin/java -Djava.util.logging.config.file=/usr/wangzf/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.endorsed.dirs=/usr/wangzf/tomcat7/endorsed -classpath /usr/wangzf/tomcat7/bin/bootstrap.jar:/usr/wangzf/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/usr/wangzf/tomcat7 -Dcatalina.home=/usr/wangzf/tomcat7 -Djava.io.tmpdir=/usr/wangzf/tomcat7/temp org.apache.catalina.startup.Bootstrap start root 1480 1413 0 02:48 pts/0 00:00:00 grep java
标签:webapp str tables 修改 tput startup opp sed rzsz
原文地址:http://www.cnblogs.com/wrcold520/p/6816555.html