shell

tomcat脚本

admin · 7月14日 · 2020年

install脚本

#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
i=1
while [ $i == 1 ];do
{
echo "建议tomcat的用户名:tomcat"
read -p "请输入tomcat的用户名:" tomcat_user
echo "建议tomcat的用户密码:tomcat"
read -p "请输入tomcat的用户密码:" tomcat_passwd
echo "建议tomcat的安装路径:/usr/local/tomcat"
read -p "请输入tomcat的安装路径:" tomcat_path
echo "建议tomcat的安装路径:/usr/local/jdk"
read -p "请输入jdk的安装路径:" jdk_path
echo "请确认安装信息是否正确:"
cat <<EOF
**********************************************************
    tomcat的用户名: $tomcat_user
    tomcat的用户密码: $tomcat_passwd
    tomcat的安装路径: $tomcat_path
    jdk的安装路径: $jdk_path
**********************************************************
EOF

read -p '请确认路径是否正确yes/no:'    make_sure
if [ "$make_sure" == "yes" ];then

useradd $tomcat_user
echo "$tomcat_passwd" | passwd --stdin $tomcat_user

mkdir -p $tomcat_path
wget -O $tomcat_path/tomcat.tar.gz https://luckinserver.cn:90/linux组件/tomcat/apache-tomcat-8.5.57.tar.gz
sleep 1
mkdir -p $jdk_path
tar -xzvf $tomcat_path/tomcat.tar.gz -C $tomcat_path --strip-components 1
sleep 1
wget -O $jdk_path/jdk.tar.gz https://luckinserver.cn:90/linux组件/jdk/jdk-8u251-linux-x64.tar.gz
sleep 1
tar -xzvf $jdk_path/jdk.tar.gz -C $jdk_path --strip-components 1
sleep 1

tom_path=`echo "$tomcat_path" | awk -F "/" '{print "/"$2}'`

cat >> /etc/profile <<EOF
export JAVA_HOME=$jdk_path
export PATH=\$JAVA_HOME/bin:\$PATH
export CLASSPATH=\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar

export TOMCAT_HOME=$tomcat_path
export CATALINA_BASE=$tomcat_path
export PATH=\$TOMCAT_HOME/bin:\$PATH
EOF

sed -i "1a export JAVA_HOME=$jdk_path" $tomcat_path/bin/setclasspath.sh

cat > /usr/lib/systemd/system/tomcat.service <<EOF
[Unit]
Description=Tomcat
After=syslog.target network.target

[Service]
Type=forking
PIDFile=$tomcat_path/tomcat.pid
ExecStart=$tomcat_path/bin/startup.sh
ExecReload=/bin/kill -s HUP \$MAINPID
ExecStop=/bin/kill -s QUIT \$MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF

echo "CATALINA_PID="\$CATALINA_BASE/tomcat.pid"" > $tomcat_path/bin/setenv.sh
chmod a+x $tomcat_path/bin/setenv.sh
chown -R $tomcat_user:$tomcat_user $tomcat_path
chown -R $tomcat_user:$tomcat_user $jdk_path
source /etc/profile
systemctl daemon-reload
i=0
else
i=1
fi
}
cat <<EOF
*******************************************
*                                         *
*                安装完成                  *
*                                         *
*             by liu peng fei             *
*                                         *
*******************************************
EOF
rm -f $0
done