#!/bin/bash
mkdir /usr/java
jdk_package=`ls |grep 'jdk'`
jdk_url='/usr/java'
echo -e "\e[32;1m----------------$jdk_package install---------------------\e[0m"
echo -e "\e[32;1m---Check whether the system has installed jdk------------\e[0m"
echo "$(rpm -qa |grep jdk)"
chmod +x $jdk_package
./$jdk_package
#jdk配置环境变量
#export JAVA_HOME=/usr/java/$jdk_package
#export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
#export PATH=$PATH:$JAVA_HOME/bin
jdk_dic=`ls /usr/java |grep 'jdk'`
sed -i '$a export JAVA_HOME='"$jdk_url"'/'"$jdk_dic" /etc/profile
sed -i '$a export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib' /etc/profile
sed -i '$a export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOME/bin' /etc/profile
source /etc/profile
# ln -s -f /usr/java/$jdk_dic/jre/bin/java
# ln -s -f /usr/java/$jdk_dic/bin/javac
java -version
echo -e "\e[32;1m------------------JDK Install Done---------------------\e[0m"
#tomcat部署
echo -e "\e[32;1m------------------Tomcat deploy------------------------\e[0m"
tar -zxvf ./apache-tomcat-6.0.44.tar.gz -C /usr/local
echo -e '
#!/bin/bash
#tomcat:start/stop/restat tomcat
#chkconfig:2345 80 20
# description: Tomcat is a Java Servlet Container
# match these values to your environment
tomcat=`ls /usr/local |grep 'tomcat'`
tomcat_url='/usr/local'
jdk=`ls /usr/java | grep 'jdk'`
jdk_url='/usr/java'
JAVA_HOME="$jdk_url/$jdk"
export CATALINA_HOME=$tomcat_url/$tomcat
case $1 in
start)
sh $CATALINA_HOME/bin/startup.sh
;;
stop)
sh $CATALINA_HOME/bin/shutdown.sh
;;
restart)
sh $CATALINA_HOME/bin/shutdown.sh
sh $CATALINA_HOME/bin/startup.sh
;;
esac
exit $RETVAL
' > /etc/init.d/tomcat
echo -e "\e[32;1m--------------tomcat add service---------------------\e[0m"
chmod +x /etc/init.d/tomcat
chkconfig --add tomcat
#source /etc/init.d/tomcat
chkconfig --list | grep tomcat
chkconfig tomcat on
#tomcat 版本隐藏
echo -e "\e[32;1m--------------tomcat alter version-------------------\e[0m"
tomcat=`ls /usr/local |grep 'tomcat'`
unzip /usr/local/$tomcat/lib/catalina.jar -d /usr/local/$tomcat/lib
sed -ri '/^server\.info=Apache/s#(Tomcat).+#\1#' /usr/local/$tomcat/lib/org/apache/catalina/util/ServerInfo.properties
sed -ri '/^server\.number=/s#(=).+#\10.0.0.0#' /usr/local/$tomcat/lib/org/apache/catalina/util/ServerInfo.properties
jar uvf /url/local/$tomcat/lib/catalina.jar /usr/local/$tomcat/lib/org/apache/catalina/util/ServerInfo.properties
service tomcat restart
#日志处理
echo -e "\e[32;1m---------------log process---------------------------\e[0m"
echo -e '
#!/bin/bash
d=`data -d'1 day gao' +%y-%m-%d`
days=30
tomcat=`ls /usr/local | grep 'tomcat'`
log_dest="/usr/local/$tomcat/logs"
cd $log_dest
cp catalina.out catalina.${d}.out
echo "" > catalina.out
tar -zcvf qzkj_$d.tar.gz *.$d.* --remove-files
find $log_dest -type f -name ".*.tar.gz" -mtime +$days -exec rm -rf {} \;
' > /usr/local/$tomcat/bin/catalina_out.sh
chmod +x /usr/local/$tomcat/bin/catalina_out.sh
#定时器 每天0点10分执行catalina_out.sh
echo '10 0 * * * /usr/local/'$tomcat'/catalina_out.sh' >> /var/spool/cron/catalina_out
crontab -l
#tomcat参数调整
echo -e "\e[32;1m---------------catalina.sh revise--------------------\e[0m"
tomcat_url=`find / -name catalina.sh`
limits_url=`find / -name limits.conf`
mem=`free -m | awk 'NR==2{print $2}'`
tomcat_mem=`echo "$mem * 0.6" | bc`
MEM_SIZE=${tomcat_mem%.*}
sed -i "/^cygwin=false/i JAVA_HOME='$jdk_url/$jdk_dic'" $tomcat_url
sed -i "/^cygwin=false/i JAVA_OPTS='-Xms"$MEM_SIZE"m -Xmx"$MEM_SIZE"m -XX:MaxPermSize="$MEM_SIZE"m -XX:PermSize="$MEM_SIZE"M -Djava.library.path=/usr/local/$tomcat/webapps/ROOT'" $tomcat_url
[ -n "$(grep 'soft' $limits_url)" ] && echo 'already added' || sed -i '$a\soft nofile 65536\' $limits_url
[ -n "$(grep 'hard' $limits_url)" ] && echo 'already added' || sed -i '$a\hard nofile 65536\' $limits_url
echo -e "\e[32;1m-----------------server.xml revise--------------------\e[0m"
#[ -n "$(grep '<Connector port="8080"' /usr/local/$tomcat/conf/server.xml)" ] && sed -ri '/\<Connector port=.*\"/s/8080/80/' /usr/local/$tomcat/conf/server.xml || echo 'It has been modified'
[ -n "$(grep 'compressableMimeType' /usr/local/$tomcat/conf/server.xml)" ] && echo 'It has been modified' || sed -i '/\<Connector port="8080"/a\\t\tcompressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"' /usr/local/$tomcat/conf/server.xml
[ -n "$(grep 'noCompressionUserAgents' /usr/local/$tomcat/conf/server.xml)" ] && echo 'It has been modified' || sed -i '/\<Connector port="8080"/a\\t\tnoCompressionUserAgents="gozilla,traviata"' /usr/local/$tomcat/conf/server.xml
[ -n "$(grep 'compression' /usr/local/$tomcat/conf/server.xml)" ] && echo 'It has been modified' || sed -i '/\<Connector port="8080"/a\\t\tcompression\="on"' /usr/local/$tomcat/conf/server.xml
[ -n "$(grep 'emptySessionPath' /usr/local/$tomcat/conf/server.xml)" ] && echo 'It has been modified' || sed -i '/\<Connector port="8080"/a\\t\temptySessionPath="true"' /usr/local/$tomcat/conf/server.xml
[ -n "$(grep 'compressionMinSize' /usr/local/$tomcat/conf/server.xml)" ] && echo 'It has been modified' || sed -i '/\<Connector port="8080"/a\\t\tcompressionMinSize="50"' /usr/local/$tomcat/conf/server.xml
[ -n "$(grep 'maxThreads' /usr/local/$tomcat/conf/server.xml)" ] && echo 'It has been modified' || sed -i '/\<Connector port="8080"/a\\t\tmaxThreads="2000"' /usr/local/$tomcat/conf/server.xml
jdk+tomcat安装
最新推荐文章于 2024-05-06 21:56:52 发布