1. 程式人生 > >tomcat9 用非root用戶開機自啟動

tomcat9 用非root用戶開機自啟動

daemon classpath cms commons user 非root fig 修改 oca

用tomcat用戶開機啟動

創建用戶

groupadd tomcat
useradd -g tomcat   tomcat   -s /sbin/nologin
chown tomcat.tomcat -R /usr/local/tomcat/*

編譯 jsvc

cd /usr/local/tomcat/bin/
tar xf commons-daemon-native.tar.gz
cd commons-daemon-1.1.0-native-src/unix/
./configure --with-java=$JAVA_HOME
make

cp jsvc /usr/local/tomcat/bin/
cp /usr/local/tomcat/bin/daemon.sh    /etc/init.d/tomcat

修改啟動文件,內存優化

vim   /etc/init.d/tomcat
#!/bin/sh
# chkconfig: 2345 81 91   
# description: Start and Stop  tomcat

JAVA_HOME=/usr/local/jdk8.0
JAVA_BIN=/usr/local/jdk8.0/bin
CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar  
CATALINA_BASE=/usr/local/tomcat
CATALINA_HOME=/usr/local/tomcat

JAVA_OPTS="-server
-Xms1024m
-Xmx1536m
-XX:PermSize=256m
-XX:MaxPermSize=512m
-XX:+UseConcMarkSweepGC
-XX:+UseCMSCompactAtFullCollection  
-XX:CMSFullGCsBeforeCompaction=0
-XX:-PrintGC
-XX:-PrintGCDetails
-XX:-PrintGCTimeStamps  
-Xloggc:../logs/gc.log "

## -Xmx1536m     堆內存最大允許大小,一般不要大於物理內存的80%

/etc/init.d/tomcat start

chkconfig tomcat on

tomcat9 用非root用戶開機自啟動