CentOS7 增長tomcat 啓動,中止,使用systemctl進行配置

1,centos7 使用 systemctl 替換了 service命令html

參考:redhat文檔:java

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Services.html#sect-Managing_Services_with_systemd-Services-List
centos

查看所有服務命令:
systemctl list-unit-files --type service
查看服務
systemctl status name.service
啓動服務
systemctl start name.service
中止服務
systemctl stop name.service
重啓服務
systemctl restart name.service增長開機啓動
systemctl enable name.service
刪除開機啓動
systemctl disable name.service
其中.service 能夠省略。tomcat

2,tomcat增長啓動參數ide

tomcat 須要增長一個pid文件ui

在tomca/bin 目錄下面,增長 setenv.sh 配置,catalina.sh啓動的時候會調用,同時配置java內存參數。centos7

#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"


3,增長tomcat.servicerest

在/usr/lib/systemd/system目錄下增長tomcat.service,目錄必須是絕對目錄。code

[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
 
[Service]
Type=forking
PIDFile=/data/tomcat/tomcat.pid
ExecStart=/data/tomcat/bin/startup.sh 
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target


[unit]配置了服務的描述,規定了在network啓動以後執行。[service]配置服務的pid,服務的啓動,中止,重啓。[install]配置了使用用戶。server

4,使用tomcat.service

配置開機啓動 

systemctl enable tomcat

啓動tomcat
systemctl start tomcat
中止tomcat
systemctl stop tomcat
重啓tomcat
systemctl restart tomcat

由於配置pid,在啓動的時候會再tomcat根目錄生成tomcat.pid文件,中止以後刪除。

同時tomcat在啓動時候,執行start不會啓動兩個tomcat,保證始終只有一個tomcat服務在運行。

多個tomcat能夠配置在多個目錄下,互不影響。

相關文章
相關標籤/搜索