生产环境一键部署Tomcat8.5+JDK1.8脚本

1.解压脚本
2.执行install.sh
3.启动服务
4.测试访问tomcat
5.防火墙放开此服务的程序端

脚本:
#!/usr/bin/env sh
# -*- coding:UTF-8 -*-
# auther: Formal environment

curr_dir=`dirname $0`
. ./config

init()
{
	yum clean all
	yum makecache
	yum install screen wget curl vim gcc cpp automake -y
}

Install_JDK()
{
	cd $source
	yum localinstall $JDK.rpm -y
	cd $curr_dir
}

Install_JRE()
{
	cd $source
	yum localinstall $JRE.rpm -y
	cd $curr_dir
}

Install_tomcat80()
{
	cd $source
	cp -rf $tomcat80.tar.gz /tmp
	cd /tmp
	tar zxf $tomcat80.tar.gz
	cd $tomcat80
	mkdir -p $tomcat
	cp -rf * $tomcat/
	cd ..
	rm -rf $tomcat80
	cd $curr_dir
}

Install_tomcat85()
{
        cd $source
        cp -rf $tomcat85.tar.gz /tmp
        cd /tmp
        tar zxf $tomcat85.tar.gz
        cd $tomcat85
	mkdir -p $tomcat
        cp -rf * $tomcat/
        cd ..
        rm -rf $tomcat85
        cd $curr_dir
}

Edit_utf()
{
	cd $tomcat/bin
	sed -i 's/JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS"/JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS -Dfile.encoding=UTF-8"/' catalina.sh
	cd ../conf
	sed -i 's/redirectPort="8443" \/>/redirectPort="8443" URIEncoding="UTF-8" \/>/' server.xml
	cd $curr_dir	
}

Tomcat_run()
{
	cd $tomcat/bin
	tar zxf commons-daemon-native.tar.gz
	cd commons-daemon-1.0.15-native-src/unix
	./configure --with-java=$JAVA_HOME
	make
	mv jsvc ../..
	useradd tomcat --no-create-home --shell /usr/bin/nologin
	echo 'JAVA_HOME='$JAVA_HOME >> /etc/profile
	ln -s $tomcat/bin/daemon.sh /etc/init.d/tomcat
	chown -R tomcat.tomcat $tomcat
	cd $curr_dir
}

Tomcat_clean()
{
	cd $tomcat/webapps
	rm -rf *
}

clear
echo '**********************************************************'
echo '**********************************************************'
echo '*              Tomcat JAVA 一键安装程序                  *'
echo '*  本脚本旨在简化tomcat和jdk等的安装,包含jdk1.8和jre1.8 *'
echo '*的安装及初步优化,使用时请小心,部分命令存在删除和修改文*'
echo '*件操作,请在使用前一定记得备份现有文件及配置,并且确认以*'
echo '*ROOT用户运行本脚本。                                    *'
echo '*                                         ------by anyran*'
echo '**********************************************************'
echo '**********************************************************'
# Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: 请使用ROOT用户运行本脚本!"
    exit 1
fi

echo 
echo '1.JDK 1.8'
echo '2.JRE 1.8'
echo '输入其他将不安装JAVA'
read -p '请选择安装JDK还是JRE1.8版本(安装JRE将无法设置tomcat非root运行):' JAVA_SE

echo 
echo '1.Tomcat 8.0'
echo '2.Tomcat 8.5'
echo '输入其他将不安装Tomcat'
read -p '请选择安装Tomcat版本:' Tomcat_SE

echo 
echo '1.设置Tomcat以非root权限运行(将新建tomcat账号并设置systemd服务)'
echo '输入其他将不进行设置'
read -p '请选择Toncat运行方式:' ROOT_SE

echo 
echo '是否清理tomcat默认的webapps文件夹'
read -p '请选择是否清理(Y/y):' CLEAN_SE

read -p '按任意键开始安装或设置,或者此时按Ctrl+C退出'

# init
case "$JAVA_SE" in
1)
Install_JDK
;;
2)
Install_JRE
;;
*)
exit 1
esac

case "$Tomcat_SE" in
1)
Install_tomcat80
Edit_utf
;;
2)
Install_tomcat85
Edit_utf
;;
*)
exit 1
esac

case "$ROOT_SE" in
1)
Tomcat_run
;;
*)
exit 1
esac

case "$CLEAN_SE" in
[yY])
Tomcat_clean
;;
*)
exit 1
esac

echo '脚本执行完毕'
exit 1

压缩包:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200717172817356.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNjA5NTI5,size_16,color_FFFFFF,t_70)![在这里插入图片描述](https://img-blog.csdnimg.cn/20200717172825685.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNjA5NTI5,size_16,color_FFFFFF,t_70)

你可能感兴趣的:(Tomcat)