centos一键自动安装tomcat7

post by rocdk890 / 2018-8-20 17:01 Monday linux技术
此次脚本在上一个版本的基础上,增加了根据系统版本添加相应的自启动脚本,centos6和centos7都可以使用.

cat /root/soft_shell/auto_install_tomcat7.sh  
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin:~/bin
export PATH

# Check the network status
NET_NUM=`ping -c 4 www.baidu.com |awk '/packet loss/{print $6}' |sed -e 's/%//'`
if [ -z "$NET_NUM" ] || [ $NET_NUM -ne 0 ];then
        echo "Please check your internet"
        exit 1
fi

if [ -s server-jre-7u51-linux-x64.tar.gz ];then
	echo -e "\033[40;31m jdk [found]\033[40;37m"
else
	wget http://download.slogra.com/java/server-jre-7u51-linux-x64.tar.gz
fi

if [ -e /usr/java ];then
	echo "delete old exist jdk ..."
	sleep 2
	rm -rf /usr/java
	echo "install new jdk ..."
	mkdir /usr/java
	sleep 2
	tar zxf server-jre* -C /usr/java
else
	mkdir /usr/java
	tar zxf server-jre* -C /usr/java
fi

if [ -e /etc/init.d/tomcat ];then
  echo "delete old exist startup script ..."
  rm -f /etc/init.d/tomcat
else
  echo "No old startup scripts exist for this system ..."
fi

if [ -e /usr/lib/systemd/system/tomcat.service ];then
  echo "delete old startup script ..."
  rm -f /usr/lib/systemd/system/tomcat.service
else
  echo "no found startup script ..."
fi   

JDKPATH=`ls /usr/java`
echo ${JDKPATH}

echo " ">>/etc/profile
echo "# JDK ENV">>/etc/profile
echo "JAVA_HOME=/usr/java/${JDKPATH}">>/etc/profile
echo 'PATH=$JAVA_HOME/bin:$PATH'>>/etc/profile
echo 'CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar'>>/etc/profile
echo 'export JAVA_HOME'>>/etc/profile
echo 'export PATH'>>/etc/profile
echo 'export CLASSPATH'>>/etc/profile

if [ -s apache-tomcat-7.0.90.tar.gz ];then
	echo -e "\033[40;31mapache-tomcat-7.0.90.tar.gz [found]\033[40;37m"
else
	wget http://mirrors.shu.edu.cn/apache/tomcat/tomcat-7/v7.0.90/bin/apache-tomcat-7.0.90.tar.gz
fi

if [ -e /usr/local/apache-tomcat* ];then
	echo "delete old exist tomcat ..."
	sleep 2
	rm -rf /usr/local/apache-tomcat*
	echo "install new tomcat ..."
	sleep 2
	tar zxvf apache-tomcat* -C /usr/local
else
	tar zxvf apache-tomcat* -C /usr/local
fi

cd /usr/local/apache-tomcat*
TOMCATPATH=`pwd`
echo ${TOMCATPATH}

echo " ">>/etc/profile
echo "# TOMCAT ENV">>/etc/profile
echo "TOMCAT_HOME=${TOMCATPATH}">>/etc/profile
echo 'PATH=$TOMCAT_HOME/bin:$PATH'>>/etc/profile

ln -s ${TOMCATPATH} /usr/local/tomcat

cat >/usr/local/tomcat/bin/setenv.sh <<EOF
#add tomcat ptah
export CATALINA_HOME=/usr/local/tomcat
export CATALINA_BASE=/usr/local/tomcat
#add tomcat pid
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
#add Java_home
JAVA_HOME=/usr/java/jdk1.7.0_51
#add Java opts
JAVA_OPTS="-server -Djava.awt.headless=true -Dfile.encoding=UTF-8 -XX:PermSize=256M -XX:MaxPermSize=1024m -Xms512M -Xmx1024M -XX:MaxNewSize=256m"
EOF

chmod +x /usr/local/tomcat/bin/setenv.sh

if [ "$(awk '{if ( $4 >= 7.0 ) print "CentOS 7.x"}' /etc/redhat-release 2>/dev/null)" != "CentOS 7.x" ];then
wget http://download.slogra.com/tomcat/tomcat_for_centos6.sh -O /etc/init.d/tomcat

chmod +x /etc/init.d/tomcat
chkconfig tomcat on
service tomcat start

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

	[Service]
	Type=forking
	ExecStart=/usr/local/tomcat/bin/startup.sh
	ExecReload=
	ExecStop=/usr/local/tomcat/bin/shutdown.sh
	PrivateTmp=true

	[Install]
	WantedBy=multi-user.target
EOF

systemctl enable tomcat
systemctl start tomcat

fi

source /etc/profile
夜空- 本站版权
1、本站所有主题由该文章作者发表,该文章作者与夜空享有文章相关版权
2、其他单位或个人使用、转载或引用本文时必须同时征得该文章作者和夜空的同意
3、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
4、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
5、原文链接:blog.slogra.com/post-732.html

标签: centos 安装 tomcat install 一键 自动

评论: