安装jdk,tomcat
位置:/opt/jdk1.8.0_141 /opt/tomcat
配置环境变量:
/etc/profile引用了/etc/profile.d下的文件
在/etc/profile.d下添加me.sh
内容:
export JAVA_HOME=/opt/jdk1.8.0_141
export JRE_HOME=/opt/jdk1.8.0_141/jre
export CATALINA_HOME=/opt/tomcat
export CATALINA_BASE=/opt/tomcat
export PATH=$JAVA_HOME/bin:$CATALINA_HOME/bin:$PATH
tomcat设置:
在bin下添加
setenv.sh
内容(进程ip如果不设置shutdown.sh有可能关不掉进程):
export JAVA_HOME=/opt/jdk1.8.0_141
export JRE_HOME=/opt/jdk1.8.0_141/jre
#add tomcat pid
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
#add Java opts
JAVA_OPTS="-server -XX:PermSize=256M -XX:MaxPermSize=1024m -Xms512M -Xmx1024M -XX:MaxNewSize=256m"
置入项目
位置:/opt/tomcat/webapps
设置随机启动:
在/usr/lib/systemd/system/下新建tomcat.service
##[unit]配置了服务的描述,规定了在network启动之后执行,
#export JAVA_HOME=/opt/jdk1.8.0_141 环境变量重新设置在setenv.sh中,在etc中设置的不起作用
#export JRE_HOME=/opt/jdk1.8.0_141/jre
[Unit]
Description=Tomcat
After=syslog.target network.target
##[service]配置服务的pid,服务的启动,停止,重启
## 命令用绝对路径,环境变量设置的找不到
[Service]
Type=forking
PIDFile=/opt/tomcat/tomcat.pid
ExecStart=/opt/tomcat/bin/startup.sh
#ExecReload=/opt/tomcat/bin/shutdown.sh /opt/tomcat/bin/startup.sh
#ExecStop=/opt/tomcat/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
##[install]配置了使用用户
[Install]
WantedBy=multi-user.target
命令:
systemctl enable tomcat.service
systemctl disable tomcat.service
systemctl restart tomcat.service
systemctl start tomcat.service
systemctl stop tomcat.service