新建用户tomcat,该用户不能登录
useradd tomcat -s '/sbin/nologin'
chown -R tomcat:tomcat /usr/local/tomcat/
chmod -R 744 /usr/local/tomcat
# 判断用户是否存在
ret=`id -u tomcat >& /dev/null`
if [ $? -ne 0 ];then
echo "not exist"
fi
将/usr/local/tomcat/bin/startup.sh、shutdown.sh更名
mv /usr/local/tomcat/bin/startup.sh /usr/local/tomcat/bin/startup_.sh
mv /usr/local/tomcat/bin/shutdown.sh /usr/local/tomcat/bin/shutdown_.sh
新建脚本startup.sh、shutdown.sh
# startup.sh
#!/bin/bash
usermod -s /bin/bash tomcat
su - tomcat -c /usr/local/tomcat_web/bin/startup_.sh
usermod -s /sbin/nologin tomcat
# shutdwon.sh
#!/bin/bash
usermod -s /bin/bash tomcat
su - tomcat -c /usr/local/tomcat_web/bin/shuwdown_.sh
usermod -s /sbin/nologin tomcat
加入开机自启
/usr/local/tomcat/bin/startup.sh >> /etc/rc.local