首页 > 代码库 > 应用容器_Tomcat-基础入门.0001.Tomcat规范化安装部署?
应用容器_Tomcat-基础入门.0001.Tomcat规范化安装部署?
简单介绍:
说明: Tomcat是Apache软件基金会项目中的一个核心项目,它具有处理HTML页面的功能(性能不如Nginx/Apache),而且是Servlet和JSP容器(在标准的MVC架构中,Servlet作为Controller控制层接受用户请求并转发给相应的Action处理,JSP作为View主要用来产生动态页面),独立的Servlet容器是Tomcat的默认模式
版本选择:
Tomcat | apache-tomcat-7.0.72.tar | http://tomcat.apache.org/download-70.cgi |
JRE | jre-7u80-linux-x64.tar.gz | http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html |
说明: Tomcat以Java编写,安装对应的完整的Java运行环境(JRE, Java Runtime Envirment),个人经验以版本选择以上个稳定版为主,个人选择7.0.x版
快速安装:
通用安装:
略
绿色安装:
# 安装JRE
mkdir -p /xm-workspace/xm-webs/xmcloud/jre/ tar -zxvf jre-7u80-linux-x64.tar.gz -C /xm-workspace/xm-webs/xmcloud/jre/ cd /xm-workspace/xm-webs/xmcloud/jre/ mv jre1.7.0_80/* ./ && rm -rf rm -rf jre1.7.0_80
# 安装Tomcat
groupadd tomcat useradd -M -s /bin/bash -g tomcat tomcat usermod -L tomcat mkdir -p /xm-workspace/xm-webs/xmcloud/tomcat8081 tar -zxvf apache-tomcat-7.0.72.tar.gz -C /xm-workspace/xm-webs/xmcloud/tomcat8081/ chown tomcat.tomcat /xm-workspace/xm-webs/xmcloud/tomcat8081 cd /xm-workspace/xm-webs/xmcloud/tomcat8081/ mv apache-tomcat-7.0.72/* ./ && rm -rf apache-tomcat-7.0.72 chown -R tomcat ./*
# 设置环境变量(头部添加环境变量即可)
vim /xm-workspace/xm-webs/xmcloud/tomcat8081/bin/catalina.sh
PORT=8081 HOME=`pwd|sed "s/\/tomcat${PORT}.*//g"` export JRE_HOME="${HOME}/jre" export JAVA_OPTS="-server -Xms1024m -Xmx1024m -Xmn384m -XX:PermSize=64m -XX:MaxPermSize=128m -XX:+UseParallelOldGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -Xloggc:${HOME}/tomcat${PORT}/logs/gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${HOME}/tomcat${PORT}/heapdump.bin"
说明: -server表示启用jdk的server版,-Xms1024m表示java虚拟机初始化时最小内存,-Xmx1024m表示java虚拟机可使用的最大内存,-XX:PermSize=64m -XX:MaxPermSize=128m主要是为了防止堆栈永久区溢出设置,所以可以保持默认或是任意合理值即可,-XX:+UseParallelOldGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -Xloggc:${HOME}/tomcat${PORT}/logs/gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${HOME}/tomcat${PORT}/heapdump.bin主要是添加内存溢出导致Tomcat宕掉后日志记录分析使用,生产环境推荐加上.
目录结构:
[root@xm-server-50024 xm-webs]# tree -L 3
. └── xmcloud ├── jre │ ├── bin │ ├── COPYRIGHT │ ├── lib │ ├── LICENSE │ ├── man │ ├── plugin │ ├── README │ ├── release │ ├── THIRDPARTYLICENSEREADME-JAVAFX.txt │ ├── THIRDPARTYLICENSEREADME.txt │ └── Welcome.html └── tomcat8081 ├── bin ├── conf ├── lib ├── LICENSE ├── logs ├── NOTICE ├── RELEASE-NOTES ├── restart_service.sh ├── RUNNING.txt ├── start_service.sh ├── stop_service.sh ├── temp ├── webapps └── work
说明: 为了更好配合SaltStack实现自动化配置管理,纵然是单实例也可使用此结构,每个实例的配置以及启动/关闭/重启等控制脚本独立存在方便后期扩展和管理
快速启动:
/xm-workspace/xm-webs/xmcloud/tomcat8081/start_service.sh
#!/usr/bin/env bash # -*- coding: utf-8 -*- # # # Authors: limanman # 51CTOBG: http://xmdevops.blog.51cto.com/ # Purpose: # # prog_name=`pwd` prog_path=`pwd` runningas="tomcat" prog_ppid=`ps -ef | grep ${prog_name}| grep -v grep | tr -s " "|cut -d" " -f2` if [[ "${prog_ppid}" != "" ]];then echo -e "Host: $(hostname) Pid: ${prog_ppid} Prog: ${prog_path} Status: start" else wlansip=`grep -oP ‘(?<=Wan_IP: )[0-9.]+‘ /etc/motd` redisip=`grep -oP ‘(?<=DataIP: )[0-9.]+‘ /etc/motd` ipareas=`grep -oP ‘(?<=IPArea: )[a-zA-Z:]+‘ /etc/motd` su ${runningas} -c "bin/startup.sh" &>/dev/null prog_ppid=`ps -ef | grep ${prog_name}| grep -v grep | tr -s " "|cut -d" " -f2` fi
/xm-workspace/xm-webs/xmcloud/tomcat8081/stop_service.sh
#!/usr/bin/env bash # -*- coding: utf-8 -*- # # # Authors: limanman # 51CTOBG: http://xmdevops.blog.51cto.com/ # Purpose: # # prog_name=`pwd` prog_path=`pwd` runningas="tomcat" prog_ppid=`ps -ef | grep ${prog_name}| grep -v grep | tr -s " "|cut -d" " -f2` [ "X${prog_ppid}" != "X" ] && kill -9 ${prog_ppid} &>/dev/null echo -e "Host: $(hostname) Pid: ${prog_ppid:-"None"} Prog: ${prog_path} Status: stop"
/xm-workspace/xm-webs/xmcloud/tomcat8081/restart_service.sh
#!/usr/bin/env bash # -*- coding: utf-8 -*- # # # Authors: limanman # 51CTOBG: http://xmdevops.blog.51cto.com/ # Purpose: # # source stop_service.sh sleep 1 source start_service.sh source start_service.sh
本文出自 “ζ自动化运维开发之路ζ” 博客,请务必保留此出处http://xmdevops.blog.51cto.com/11144840/1859533
应用容器_Tomcat-基础入门.0001.Tomcat规范化安装部署?