安装jdk:
[root@stu ~]# rpm -ivh jdk-7u9-linux-x64.rpm #此为安装官方的版本(c6已经使用了openjdk)报错不用关心
查看安装位置:
[root@stu ~]# rpm -ql jdk
目录:
[root@stu ~]# cd /usr/java [root@stu java]# ls default jdk1.7.0_09 latest
查看文件:
[root@stu java]# cd latest/bin [root@stu bin]# ls appletviewer idlj javac javap jconsole jinfo jsadebugd jvisualvm pack200 rmiregistry tnameserv xjc apt jar javadoc java-rmi.cgi jcontrol jmap jstack keytool policytool schemagen unpack200 ControlPanel jarsigner javafxpackager javaws jdb jps jstat native2ascii rmic serialver wsgen extcheck java javah jcmd jhat jrunscript jstatd orbd rmid servertool wsimport src.zip THIRDPARTYLICENSEREADME.txt
导出环境变量:
[root@stu ~]# vim /etc/profile.d/java.sh export JAVA_HOME=/usr/java/latest export PATH=$JAVA_HOME/bin:$PATH [root@stu ~]# . /etc/profile.d/java.sh
查看版本:
[root@stu ~]# java -version java version "1.7.0_09" Java(TM) SE Runtime Environment (build 1.7.0_09-b05) Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)
/usr/java/latest/bin/目录下的文件说明:
jar:打包工具 javac:编译工具 jmap:监控工具 javadoc:文档 jbd:调试工具 jstack、jstat:监控命令 jconsole:图形监控控制台
java监控和故障处理工具:
jps:显示指定系统内所有的hotspot虚拟机进程的列表信息 jstat,jvm statistics monitoring tool,收集并显示hotspot虚拟机各方面的运行数据 jinfo,显示正在运行的hotspot虚拟机配置信息 jmap:内存映射,生成某hotspot虚拟机的内存转储快照
可视化工具:
jconsole:java监控管理平台,这个运行下 jvisualvm:也是可视化工具
java配置参数:
--XX:+<option>:开启此参数指定的功能 --XX:-<option>:关闭功能 --XX:<option>=<value>:给option指定的选项赋值 java –XX:+ PrintFlagFinal:显示所有参数及默认值 -D<name>=<value>:设置系统属性值
安装tomcat:
[root@stu ~]# tar xf apache-tomcat-7.0.70.tar.gz -C /usr/local [root@stu ~]# cd /usr/local [root@stu local]# ln -sv apache-tomcat-7.0.70/ tomcat [root@stu tomcat]# ls bin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work
导出环境变量:
[root@stu conf]# vim /etc/profile.d/tomcat.sh export CATALINA_HOME=/usr/local/tomcat export PATH=$PATH:$CATALINA_HOME/bin [root@stu conf]# . /etc/profile.d/tomcat.sh
查看版本:
[root@stu bin]# catalina.sh version 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 Server version: Apache Tomcat/7.0.70 Server built: Jun 15 2016 16:27:45 UTC Server number: 7.0.70.0 OS Name: Linux OS Version: 2.6.32-504.el6.x86_64 Architecture: amd64 JVM Version: 1.7.0_09-b05 JVM Vendor: Oracle Corporation
启动:
[root@stu bin]# 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.
查看是否启动:
[root@stu bin]# jps 2612 Bootstrap 2630 Jps [root@stu bin]# netstat -tnlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1147/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1233/master tcp 0 0 :::22 :::* LISTEN 1147/sshd tcp 0 0 ::1:25 :::* LISTEN 1233/master tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 2612/java tcp 0 0 :::8009 :::* LISTEN 2612/java tcp 0 0 :::8080 :::* LISTEN 2612/java
添加服务脚本:
[root@stu tomcat]# vim /etc/rc.d/init.d/tomcat #!/bin/sh # Tomcat init script for Linux. # # chkconfig: 2345 96 14 # description: The Apache Tomcat servlet/JSP container. # JAVA_OPTS='-Xms64m -Xmx128m' JAVA_HOME=/usr/java/latest CATALINA_HOME=/usr/local/tomcat export JAVA_HOME CATALINA_HOME case $1 in start) exec $CATALINA_HOME/bin/catalina.sh start ;; stop) exec $CATALINA_HOME/bin/catalina.sh stop;; restart) $CATALINA_HOME/bin/catalina.sh stop sleep 2 exec $CATALINA_HOME/bin/catalina.sh start ;; *) echo "Usage: `basename $0` {start|stop|restart}" exit 1 ;; esac [root@stu tomcat]# chmod +x /etc/rc.d/init.d/tomcat [root@stu tomcat]# chkconfig --add tomcat [root@stu tomcat]# chkconfig --list tomcat tomcat 0:off1:off2:on3:on4:on5:on6:off
测试一下即可(此处省略)
虚拟主机:
先设置windows主机的hosts文件: 192.168.0.20 www.a.com 192.168.0.20 www.b.net 配置虚拟主机: [root@stu www]# cd /usr/local/tomcat/conf/ [root@stu conf]# vim server.xml <Host name="www.a.com" appBase="/www/webapps" unpackWARs="true" autoDeploy="true"> <Context path="" docBase="ROOT" reloadable="true" /> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="a.com_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host> 创建目录: [root@stu conf]# mkdir -pv /www/webapps/ROOT [root@stu conf]# cd /www/webapps/ROOT 创建测试页: [root@stu conf]# vim 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: [root@stu ROOT]# service tomcat restart
访问:
加第二个虚拟主机:
<Host name="www.a.com" appBase="/www/webapps" unpackWARs="true" autoDeploy="true"> <Context path="" docBase="ROOT" reloadable="true" /> <Context path="/test" docBase="testapp" reloadable="true" /> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="a.com_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host> [root@stu conf]# cd /www/webapps/ [root@stu webapps]# mkdir testapp [root@stu webapps]# cp ROOT/index.jsp testapp/ [root@stu webapps]# vim testapp/index.jsp <%@ page language="java" %> <%@ page import="java.util.*" %> <html> <head> <title>JSP test page.</title> </head> <body> <% out.println("Hello,tomcat!"); %> </body> </html> [root@stu webapps]# service tomcat restart
访问:
状态:
状态:
[root@stu ~]# cd /usr/local/tomcat/conf/ [root@stu conf]# vim tomcat-users.xml <role rolename="manager-gui"/> <user username="tomcat" password="tomcat" roles="tomcat,manager-gui"/> [root@stu conf]# service tomcat stop [root@stu conf]# service tomcat start
点击manager:用户名、密码都是tomcat
admin:
[root@stu conf]# vim tomcat-users.xml <role rolename="manager-gui"/> <role rolename="admin-gui"/> <user username="tomcat" password="tomcat" roles="tomcat,manager-gui,admin-gui"/> [root@stu conf]# service tomcat stop [root@stu conf]# service tomcat start
原创文章,作者:黑白子,如若转载,请注明出处:http://www.178linux.com/23487