1. 程式人生 > >CentOS6u9 tomcat 目錄拆分和多例項以及普通使用者啟動等等多個實驗

CentOS6u9 tomcat 目錄拆分和多例項以及普通使用者啟動等等多個實驗

實驗環境搭建:

1° 參照《CentOS6實驗機模板搭建部署》克隆一臺實驗機並進行部署:

hostname tomcat
echo "$(grep -E '127|::1' /etc/hosts)">/etc/hosts
echo "$(ifconfig eth0|grep inet|awk -F'[ :]' '{print $13}') $(hostname)">>/etc/hosts
sed -i "s/^HOSTNAME.*$/HOSTNAME=$(hostname)/g" /etc/sysconfig/network
ping -c 3 $(hostname)

2° 解壓安裝jdk和tomcat

mkdir -pv /usr/local/java
cd /usr/local/java
tar -xf /tmp/jdk-8u172-linux-x64.tar.gz
chown root: -R .
cat >>/etc/profile<<EOF
export JAVA_HOME=/usr/local/java/jdk1.8.0_172
export CLASSPATH=\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib
export PATH=\$JAVA_HOME/bin:\$JAVA_HOME/jre/bin:\$PATH
EOF
source /etc/profile

mkdir -pv /usr/local/tomcat
cd /usr/local/tomcat
tar -xf /tmp/apache-tomcat-8.0.51.tar.gz
chown root: -R .

tomcat7或tomcat8啟動緩慢解決:

報錯日誌:
26-Sep-2018 09:51:22.273 WARNING [localhost-startStop-1] 
org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom 
Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [79,675] milliseconds.

tomcat7或tomcat8啟動緩慢的原因,問題產生的原因不在過多解釋,解決辦法其中之一如下:
JAVA_OPTS=${JAVA_OPTS}" -Djava.security.egd=file:/dev/./urandom"

目錄拆分實驗:

# tomcat例項執行時有三個和目錄相關的引數:CATALINA_HOME和CATALINA_BASE以及CATALINA_TMPDIR

# 環境變數CATALINA_HOME指向tomcat的安裝目錄
# 所謂安裝目錄即是tomcat的bin目錄和lib目錄的所在位置
# 也就是說如果要升級tomcat版本,只需要替換這倆目錄即可,同時需要替換conf目錄下的對應檔案

# 環境變數CATALINA_BASE指向tomcat的工作目錄
# 所謂工作目錄即是除bin目錄和lib目錄之外的其他目錄
# 如conf、webapps、logs、work目錄

# 環境變數CATALINA_TMPDIR指向tomcat的工作臨時目錄
# 所謂的工作臨時目錄是指例項執行時候的相對臨時目錄

mkdir -pv /web/tomcat1
cd /web/tomcat1
mkdir -pv {conf,webapps/ROOT,logs,temp,work}
echo 'tomcat1'>webapps/ROOT/index.html
cp -av /usr/local/tomcat/apache-tomcat-8.0.51/conf/*  conf/

export CATALINA_HOME=/usr/local/tomcat/apache-tomcat-8.0.51
export CATALINA_BASE=/web/tomcat1
export CATALINA_TMPDIR=${CATALINA_BASE}/temp
JAVA_OPTS=${JAVA_OPTS}" -Djava.security.egd=file:/dev/./urandom"
${CATALINA_HOME}/bin/shutdown.sh
${CATALINA_HOME}/bin/startup.sh
tailf ${CATALINA_BASE}/logs/catalina.out

多例項啟動實驗:

# tomcat配置多例項啟動時需要需要每個例項都有各自的CATALINA_BASE
# 例項的執行需要獨佔四個系統埠,不可重複
# shutdown埠,預設8005
# http服務埠,預設8080
# https服務埠,預設8443,預設https配置是註釋掉的
# AJP聯結器埠,預設8009

mkdir -pv /web/tomcat2
cd /web/tomcat2
mkdir -pv {conf,webapps/ROOT,logs,temp,work}
echo 'tomcat2'>webapps/ROOT/index.html
cp -av /usr/local/tomcat/apache-tomcat-8.0.51/conf/*  conf/
sed -i 's/8005/8006/g' conf/server.xml
sed -i 's/8080/8081/g' conf/server.xml
sed -i 's/8443/8444/g' conf/server.xml
sed -i 's/8009/8010/g' conf/server.xml

export CATALINA_HOME=/usr/local/tomcat/apache-tomcat-8.0.51
export CATALINA_BASE=/web/tomcat2
export CATALINA_TMPDIR=${CATALINA_BASE}/temp
JAVA_OPTS=${JAVA_OPTS}" -Djava.security.egd=file:/dev/./urandom"
${CATALINA_HOME}/bin/shutdown.sh
${CATALINA_HOME}/bin/startup.sh
tailf ${CATALINA_BASE}/logs/catalina.out

普通使用者啟動實驗:

# 普通使用者啟動tomcat,需要有讀取和執行java環境、CATALINA_HOME目錄的許可權
# 具有能夠讀寫CATALINA_BASE目錄的許可權

useradd tomcat
mkdir -pv /web/tomcat3
cd /web/tomcat3
mkdir -pv {conf,webapps/ROOT,logs,temp,work}
echo 'tomcat3'>webapps/ROOT/index.html
cp -av /usr/local/tomcat/apache-tomcat-8.0.51/conf/*  conf/
sed -i 's/8005/8007/g' conf/server.xml
sed -i 's/8080/8082/g' conf/server.xml
sed -i 's/8443/8445/g' conf/server.xml
sed -i 's/8009/8011/g' conf/server.xml
chown -R tomcat: /web/tomcat3

su - tomcat
export CATALINA_HOME=/usr/local/tomcat/apache-tomcat-8.0.51
export CATALINA_BASE=/web/tomcat3
export CATALINA_TMPDIR=${CATALINA_BASE}/temp
JAVA_OPTS=${JAVA_OPTS}" -Djava.security.egd=file:/dev/./urandom"
${CATALINA_HOME}/bin/shutdown.sh
${CATALINA_HOME}/bin/startup.sh
tailf ${CATALINA_BASE}/logs/catalina.out

[TOC]