Tomcat是一個web-server,相似nginx,apache的http
Nginx,http只能處理html等靜態文件
網頁分爲靜態和動態網頁
Php承受併發能力1000,nginx承受能力10萬
Nginx和http配合php就可以處理動態的網頁(.php)
Tomcat也能夠處理靜態的html文件
Tomcat配合jdk就可以處理動態的網頁.php結尾
1.1.1安裝JDK java==虛擬機
tar xf jdk-8u60-linux-x64.tar.gz -C /application/php
ln -s /application/jdk1.8.0_60 /application/jdkhtml
sed -i.ori '$a export JAVA_HOME=/application/jdk\nexport PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH\nexport CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar' /etc/profilejava
source /etc/profile
安裝tomcatmysql
tar xf apache-tomcat-8.0.27.tar.gz -C /application/linux
ln -s /application/apache-tomcat-8.0.27 /application/tomcatnginx
echo 'export TOMCAT_HOME=/application/tomcat'>>/etc/profileweb
source /etc/profilesql
chown -R root.root /application/jdk/ /application/tomcat/
/application/tomcat/bin/version.sh apache
Tomcat目錄結構
.
├── bin #啓動文件目錄
├── conf #配置文件目錄 server.xml(主配置文件)
├── lib #
├── LICENSE
├── logs #日誌
├── NOTICE
├── RELEASE-NOTES
├── RUNNING.txt
├── temp #臨時目錄
├── webapps #站點存放目錄
└── work#tomcat編譯文件存放目錄vim
利用瀏覽器訪問:http://10.0.0.200:8080/
Tomcat日誌
catalina.2018-03-01.log #catalina.2018-03-01.log 天天的日誌文件切割
catalina.out #實時記錄tomcat的運行信息,文件會愈來愈大,定時清空
#每一個站點的訪問日誌
host-manager.2018-03-01.log
localhost.2018-03-01.log
localhost_access_log.2018-03-01.txt
manager.2018-03-01.log
1.[root@tomcat tomcat]# cd webapps/
2.[root@tomcat webapps]# ll
3.total 20
4.drwxr-xr-x 14 root root 4096 Oct 5 12:09 docs #→tomcat幫助文檔
5.drwxr-xr-x 6 root root 4096 Oct 5 12:09 examples #→web應用實例
6.drwxr-xr-x 5 root root 4096 Oct 5 12:09 host-manager #→管理
7.drwxr-xr-x 5 root root 4096 Oct 5 12:09 manager #→管理
8.drwxr-xr-x 3 root root 4096 Oct 5 12:09 ROOT #→默認網站根目錄
1.3搭建jpress--java版本的wordpress
1.mysql安裝:yum install mariadb-server
啓動:systemctl start mariadb.service
2.mysq命令行操做:create database jpress DEFAULT CHARACTER SET utf8;
grant all on jpress.* to jpress@'localhost' identified by '123456';
2.部署站點代碼
上傳jpress-web-newest.war到/application/tomcat/webapps目錄會自動解壓
mv jpress-web-newest jpress
利用瀏覽器訪問10.0.0.200/jpress4重啓
/application/tomcat/bin/shutdown.sh
/application/tomcat/bin/startup.sh
5.後臺登錄vim /application/tomcat/conf/server.xml 語法:註釋以<!--開頭,以-->結尾
<Server port="8005" shutdown="SHUTDOWN">指定關閉tomcat的端口號及暗號
<Connector port="8080" protocol="HTTP/1.1" 指定監聽tomcat的web站點監聽端口
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />專門和apache通信的端口
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
1.5
1.6自定義網站目錄
默認:webapps下的ROOT1.將meminfo.jsp放在ROOT目錄
sed -i.ori '125a <Context path="" docBase="/application/tomcat/webapps/memtest" debug="0" reloadable="false" crossContext="true"/>' /application/tomcat/conf/server.xml
重啓: /application/tomcat/bin/shutdown.sh
/application/tomcat/bin/startup.sh
也能夠不使用一下:
sed -i.ori2 '126a <Context path="43class" docBase="/application/tomcat/webapps/memtest" debug="0" reloadable="false" crossContext="true"/>' /application/tomcat/conf/server.xml
訪問:http://10.0.0.200:8080/43class/meminfo.jsp
1.7Tomcat多實例
cd /server/tools/
tar xf apache-tomcat-8.0.27.tar.gz
cp -a apache-tomcat-8.0.27 tomcat_1
cp -a apache-tomcat-8.0.27 tomcat_2 多實例
sed -i 's#8005#8011#;s#8080#8081#' tomcat_1/conf/server.xml
sed -i 's#8005#8012#;s#8080#8082#' tomcat_2/conf/server.xml 配置過程
tar zcf tomcat_mtui.tar.gz ./tomcat_1/ tomcat_2/#將已經配置實例打包
mv tomcat_1/ tomcat_2/ /application/
/application/tomcat_1/bin/startup.sh
/application/tomcat_2/bin/startup.sh
netstat -lntup|grep java1.8Tomcat反向代理
安裝peplyum源yum -y install epel-release
安裝nginx:yum -y install nginx
Vim /eyc/nginx/nginx.conf配置文件
利用瀏覽器訪問10.0.0.200
1.9Tomcat遠程監控D:\監控tomcat\bin
雙擊1.10Zabbix監控
安裝zabbix-java-gateway
利用m01安裝rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm
yum -y install zabbix-java-qateway
1.12 瀏覽器輸入:主機ip-配置-主機-建立主機
1.13Tomcat優化
1.13.1安全優化
Telnet、nc管理端口保護(8005)
Ajp鏈接端口保護8009
禁用管理端
降權啓動:下降權限啓動tomcat1.13.2性能優化
vim /application/tomcat_1/bin/catalina.sh +97
JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1024m -Xmx1024m -XX:NewSize=512m -XX:MaxNewSize=512m -XX:PermSize=512m -XX:MaxPermSize=512m"