CentOS7 增加tomcat 啟動(dòng)、停止(使用systemctl進(jìn)行配置)
發(fā)布時(shí)間:2015-11-02 16:22:29 作者:佚名
我要評(píng)論

這篇文章主要介紹了CentOS7 增加tomcat 啟動(dòng)、停止(使用systemctl進(jìn)行配置),需要的朋友可以參考下
1,centos7 使用 systemctl 替換了 service命令
參考:redhat文檔:
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
查看全部服務(wù)命令:
systemctl list-unit-files --type service
查看服務(wù)
systemctl status name.service
啟動(dòng)服務(wù)
systemctl start name.service
停止服務(wù)
systemctl stop name.service
重啟服務(wù)
systemctl restart name.service增加開(kāi)機(jī)啟動(dòng)
systemctl enable name.service
刪除開(kāi)機(jī)啟動(dòng)
systemctl disable name.service
其中.service 可以省略。
2,tomcat增加啟動(dòng)參數(shù)
tomcat 需要增加一個(gè)pid文件
在tomca/bin 目錄下面,增加 setenv.sh 配置,catalina.sh啟動(dòng)的時(shí)候會(huì)調(diào)用,同時(shí)配置java內(nèi)存參數(shù)。
#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.service
在/usr/lib/systemd/system目錄下增加tomcat.service,目錄必須是絕對(duì)目錄。
[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]配置了服務(wù)的描述,規(guī)定了在network啟動(dòng)之后執(zhí)行。[service]配置服務(wù)的pid,服務(wù)的啟動(dòng),停止,重啟。[install]配置了使用用戶。
4,使用tomcat.service
配置開(kāi)機(jī)啟動(dòng)
systemctl enable tomcat
啟動(dòng)tomcat
systemctl start tomcat
停止tomcat
systemctl stop tomcat
重啟tomcat
systemctl restart tomcat
因?yàn)榕渲胮id,在啟動(dòng)的時(shí)候會(huì)再tomcat根目錄生成tomcat.pid文件,停止之后刪除。
同時(shí)tomcat在啟動(dòng)時(shí)候,執(zhí)行start不會(huì)啟動(dòng)兩個(gè)tomcat,保證始終只有一個(gè)tomcat服務(wù)在運(yùn)行。
多個(gè)tomcat可以配置在多個(gè)目錄下,互不影響。
參考:redhat文檔:
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
查看全部服務(wù)命令:
systemctl list-unit-files --type service
查看服務(wù)
systemctl status name.service
啟動(dòng)服務(wù)
systemctl start name.service
停止服務(wù)
systemctl stop name.service
重啟服務(wù)
systemctl restart name.service增加開(kāi)機(jī)啟動(dòng)
systemctl enable name.service
刪除開(kāi)機(jī)啟動(dòng)
systemctl disable name.service
其中.service 可以省略。
2,tomcat增加啟動(dòng)參數(shù)
tomcat 需要增加一個(gè)pid文件
在tomca/bin 目錄下面,增加 setenv.sh 配置,catalina.sh啟動(dòng)的時(shí)候會(huì)調(diào)用,同時(shí)配置java內(nèi)存參數(shù)。
復(fù)制代碼
代碼如下:#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.service
在/usr/lib/systemd/system目錄下增加tomcat.service,目錄必須是絕對(duì)目錄。
復(fù)制代碼
代碼如下:[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]配置了服務(wù)的描述,規(guī)定了在network啟動(dòng)之后執(zhí)行。[service]配置服務(wù)的pid,服務(wù)的啟動(dòng),停止,重啟。[install]配置了使用用戶。
4,使用tomcat.service
配置開(kāi)機(jī)啟動(dòng)
systemctl enable tomcat
啟動(dòng)tomcat
systemctl start tomcat
停止tomcat
systemctl stop tomcat
重啟tomcat
systemctl restart tomcat
因?yàn)榕渲胮id,在啟動(dòng)的時(shí)候會(huì)再tomcat根目錄生成tomcat.pid文件,停止之后刪除。
同時(shí)tomcat在啟動(dòng)時(shí)候,執(zhí)行start不會(huì)啟動(dòng)兩個(gè)tomcat,保證始終只有一個(gè)tomcat服務(wù)在運(yùn)行。
多個(gè)tomcat可以配置在多個(gè)目錄下,互不影響。
相關(guān)文章
Win10出現(xiàn)"Shell Infrastructure Host已停止工作"怎么辦?
有用戶在使用win10時(shí)就遇上了“Shell Infrastructure Host已停止工作”的提示,這是怎么回事?怎么解決呢?下面就看看解決Win10提示“Shell Infrastructure Host已停止工作2016-02-14Win8什么時(shí)候停止服務(wù)?Win8.1系統(tǒng)停止服務(wù)時(shí)間介紹
微軟繼停止winXP系統(tǒng)安全服務(wù)后,近日,又有媒體報(bào)道微軟將停止win8/win8.1系統(tǒng)安全補(bǔ)丁更新,那么,Win8停止服務(wù)時(shí)間是什么時(shí)候?對(duì)此,本文小編就為大家進(jìn)行解答2016-01-12微軟下周(1月12日)將停止支持Win8 請(qǐng)速升級(jí)Win8.1或Win10
微軟宣布1月12日將停止支持IE8、IE9和IE10這三款瀏覽器。微軟也會(huì)在當(dāng)天給這三款瀏覽器放出KB3123303補(bǔ)丁,安裝后用戶會(huì)看到升級(jí)瀏覽器的提醒。這個(gè)補(bǔ)丁將會(huì)給運(yùn)行Windows72016-01-10Win7系統(tǒng)彈出Adobe Flash Player已停止工作窗口的解決方法
最近有用戶反映win7在瀏覽關(guān)于Falsh內(nèi)容的網(wǎng)頁(yè)時(shí),經(jīng)常會(huì)彈出Adobe Flash Player已停止工作的提示框,或顯示“插件 Adobe Flash 已崩潰”,這是怎么回事呢?這種情況怎么辦2016-01-07Win8.1系統(tǒng)提示“公用外殼DLL已停止工作”的解決方法
最近有網(wǎng)友反映Win8.1系統(tǒng)測(cè)試游戲手柄的時(shí)候,突然出現(xiàn)提示公用外殼DLL已停止工作,這是什么情況呢?這種情況怎么辦呢?本文將提供Win8.1系統(tǒng)提示“公用外殼DLL已停止工作2015-12-31Win7/Win8.1設(shè)備即將停止銷售 2016年10月31日起實(shí)施
每個(gè)系統(tǒng)都有維護(hù)期,winxp已經(jīng)停止維護(hù)了,現(xiàn)在win7/8設(shè)備也即將停止銷售,最近微軟公布了最新的OEM系統(tǒng)生命周期,預(yù)裝win7的電腦于2014年10月31日停止銷售。另外,預(yù)裝Wi2015-11-03win8.1系統(tǒng)出現(xiàn)GWXUX.exe停止工作的解決辦法
win901電腦最近總是提示GWXUX.exe停止工作,雖然并不影響工作,但是總提示也覺(jué)得麻煩,于是找了一下原因,后來(lái)的事是因?yàn)槲④浉略斐傻?,下面分享解決辦法,需要的朋友可2015-10-27win8.1安裝CAD2006無(wú)法激活提示停止工作怎么辦?
win8.1安裝CAD2006無(wú)法激活提示停止工作怎么辦?win8系統(tǒng)安裝cad2006沒(méi)有問(wèn)題,但是沒(méi)辦法激活,總是出現(xiàn)停滯工作,每次進(jìn)入激活界面時(shí)出現(xiàn)、Auto Cad application停止工作2015-10-19windows主進(jìn)程rundll32已停止工作的四種解決方法介紹
windows主進(jìn)程rundll32已停止工作怎么辦?這個(gè)問(wèn)題貌似很難啊,而且我電腦是經(jīng)常出現(xiàn),看來(lái)得解決了。 下面小編就為大家介紹四種解決方法,有需要的朋友可以參考一下哦2015-10-12WinXp系統(tǒng)死機(jī)/停止響應(yīng)怎么辦?xp系統(tǒng)死機(jī)時(shí)自動(dòng)重啟的方法
WinXp系統(tǒng)死機(jī)、停止響應(yīng)怎么辦?本文將提供讓xp系統(tǒng)死機(jī)時(shí)自動(dòng)重啟的方法供大家了解,希望對(duì)大家有所幫助2015-10-12