centos中安裝tomcat7,並實現web程式的熱部署
阿新 • • 發佈:2019-02-19
- 安裝前先檢查jdk是否安裝,如果沒有安裝,則先安裝jdk
[root@tomcat home]# java -version
java version "1.6.0_33"
OpenJDK Runtime Environment (IcedTea6 1.13.5) (rhel-1.13.5.1.el6_6-x86_64)
OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)
- 從官網中下載tar.gz,並解壓到/usr/local/tomcat
[root@tomcat home]# wget http://mirrors.cnnic.cn/apache/tomcat/tomcat-7/v7.0.65/bin/apache-tomcat-7.0.65.tar.gz
[root@tomcat home]# tar -zxvf apache-tomcat-7.0.65.tar.gz
[root@tomcat home]# mv apache-tomcat-7.0.65 /usr/local/tomcat
[root@tomcat home]# cd /usr/local/tomcat
- 修改tomcat的配置檔案,增加host,實現web檔案的熱部署。
[root@tomcat tomcat]# vim conf/server.xml
<Host name="192.168.0.222" appBase="/data/tomcat/webapps_xxx"
unpackWARs="true" autoDeploy="true">
</Host>
- 新建webapps_xxx的目錄,用於存放maven編譯的war包
[root@tomcat tomcat]# mkdir -p /data/tomcat/webapps_xxx
- 開放防火牆監聽埠8080
[root@tomcat tomcat]/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
[root@tomcat tomcat]/etc/rc.d/init.d/iptables save
[root@tomcat tomcat]/etc/init.d/iptables restart
啟動tomcat
[root@tomcat tomcat]# ./bin/startup.sh
檢視啟動日誌
[root@tomcat tomcat]# tail -f logs/catalina.out
- 用maven打包一個xxx.war專案,然後放在/home目錄下,複製到/data/tomcat/webapps_xxx下並重命名為ROOT.war
[root@tomcat tomcat]# mv xxx.war webapps_xxx/ROOT.war
如果此時在檢視tomcat日誌,則可以看到剛部署的xxx.war已經自動開始部署,無需重啟tomcat
- 關於tomcat的一些技巧及基本配置
1、配置tomcat開機啟動
在etc/rc.local中新增,tomcatstart.sh是新建的tomcat啟動檔案
[root@tomcat tomcat]# vim /etc/rc.local
在末尾增加:/usr/local/bin/tomcatstart.sh
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
/usr/local/bin/tomcatstart.sh
在/usr/local/bin中新建一個tomcatstart.sh檔案
[root@tomcat tomcat]# vim /usr/local/bin/tomcatstart.sh
內容如下:
#!/bin/bash
export TOMCAT_HOME='/usr/local/tomcat'
$TOMCAT_HOME/bin/startup.sh
修改執行許可權
[root@tomcat tomcat] cd /usr/local/bin
[root@tomcat bin] chmod 775 tomcatstart.sh
至此開機啟動已完成
2、在centos中增加快捷訪問路徑
[root@tomcat tomcat] vim ~/.bashrc
匯入export data=’/data/luqiao/tomcat’
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
export tomcat='/usr/local/tomcat'
[root@tomcat tomcat] source ~/.bashrc
驗證快捷路徑是否生效:
[root@tomcat tomcat] cd /home
[root@tomcat tomcat] cd $tomcat
[root@tomcat tomcat] pwd
/usr/local/tomcat
此時則證明成功新增快捷路徑