最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Windows如何設(shè)置定時(shí)重啟Tomcat

 更新時(shí)間:2024年01月02日 15:16:06   作者:謝小濤  
本文主要介紹了Windows如何設(shè)置定時(shí)重啟Tomcat,可以使用Windows系統(tǒng)的計(jì)劃任務(wù)程序,在這里設(shè)置定時(shí)執(zhí)行的.bat批處理文件,具有一定的參考價(jià)值,感興趣的可以了解一下

項(xiàng)目場(chǎng)景:

系統(tǒng):Windows 7

Tomcat:apache-tomcat-8.0.5

JDK:1.8

問題描述

最近項(xiàng)目的Tomcat隔一段時(shí)間就假死,最后想到的解決方式就是:每天凌晨1點(diǎn)重啟tomact。

解決方案:

使用Windows系統(tǒng)的計(jì)劃任務(wù)程序,可以在這里設(shè)置定時(shí)執(zhí)行的.bat批處理文件(將你要定時(shí)執(zhí)行的cmd命令放在這里),這樣就可以實(shí)現(xiàn)讓電腦在某個(gè)時(shí)刻做你想讓它干的事。

實(shí)現(xiàn)步驟:

一、創(chuàng)建tomcat重啟的腳本

        創(chuàng)建txt文件restart.txt,編輯內(nèi)容,把下面的內(nèi)容復(fù)制進(jìn)去,然后把綴改為.bat,最后文件名為:restart.bat  

echo 正在關(guān)閉Tomcat服務(wù),請(qǐng)稍等......

@echo off
rem Licensed to the Apache Software Foundation (ASF) under one or more
rem contributor license agreements.  See the NOTICE file distributed with
rem this work for additional information regarding copyright ownership.
rem The ASF licenses this file to You under the Apache License, Version 2.0
rem (the "License"); you may not use this file except in compliance with
rem the License.  You may obtain a copy of the License at
rem
rem     http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.

rem ---------------------------------------------------------------------------
rem Stop script for the CATALINA Server
rem ---------------------------------------------------------------------------

setlocal

rem Guess CATALINA_HOME if not defined
set "CURRENT_DIR=%cd%"
if not "%CATALINA_HOME%" == "" goto gotHome
set "CATALINA_HOME=%CURRENT_DIR%"
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
cd ..
set "CATALINA_HOME=%cd%"
cd "%CURRENT_DIR%"
:gotHome
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
echo The CATALINA_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
:okHome

set "EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat"

rem Check that target executable exists
if exist "%EXECUTABLE%" goto okExec
echo Cannot find "%EXECUTABLE%"
echo This file is needed to run this program
goto end
:okExec

rem Get remaining unshifted command line arguments and save them in the
set CMD_LINE_ARGS=
:setArgs
if ""%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto setArgs
:doneSetArgs

call "%EXECUTABLE%" stop %CMD_LINE_ARGS%

:end


echo 關(guān)閉Tomcat服務(wù)完成

ping 127.0.0.1 -n 20
echo ******************************************

echo 正在啟動(dòng)Tomcat服務(wù),請(qǐng)稍等......

@echo off
rem Licensed to the Apache Software Foundation (ASF) under one or more
rem contributor license agreements.  See the NOTICE file distributed with
rem this work for additional information regarding copyright ownership.
rem The ASF licenses this file to You under the Apache License, Version 2.0
rem (the "License"); you may not use this file except in compliance with
rem the License.  You may obtain a copy of the License at
rem
rem     http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.

rem ---------------------------------------------------------------------------
rem Start script for the CATALINA Server
rem ---------------------------------------------------------------------------

setlocal

rem Guess CATALINA_HOME if not defined
set "CURRENT_DIR=%cd%"
if not "%CATALINA_HOME%" == "" goto gotHome
set "CATALINA_HOME=%CURRENT_DIR%"
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
cd ..
set "CATALINA_HOME=%cd%"
cd "%CURRENT_DIR%"
:gotHome
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
echo The CATALINA_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
:okHome

set "EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat"

rem Check that target executable exists
if exist "%EXECUTABLE%" goto okExec
echo Cannot find "%EXECUTABLE%"
echo This file is needed to run this program
goto end
:okExec

rem Get remaining unshifted command line arguments and save them in the
set CMD_LINE_ARGS=
:setArgs
if ""%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto setArgs
:doneSetArgs

call "%EXECUTABLE%" start %CMD_LINE_ARGS%

:end


echo 啟動(dòng)Tomcat服務(wù)完成

把restart.bat 文件復(fù)制到apache-tomcat-8.0.50\bin目錄下 ,然后可以直接雙擊運(yùn)行,啟動(dòng)會(huì)報(bào)個(gè)錯(cuò),是因?yàn)閠omcat沒啟動(dòng),是正常的。

 二、創(chuàng)建任務(wù)計(jì)劃程序

1、開始菜單搜索“任務(wù)計(jì)劃程序”

或者到控制面板里面找到“計(jì)劃任務(wù)”

2、彈出任務(wù)計(jì)劃程序界面,在右側(cè)點(diǎn)擊創(chuàng)建任務(wù)

3、輸入 名稱和描述

4、點(diǎn)擊觸發(fā)器選項(xiàng)卡,點(diǎn)擊左下角新建,彈出新建操作,新建一個(gè)觸發(fā)器,每天凌晨一點(diǎn)觸發(fā)

5、點(diǎn)擊操作選項(xiàng)卡,點(diǎn)擊左下角新建,彈出新建操作,點(diǎn)擊瀏覽。選擇要執(zhí)行的腳本restart.bat ,點(diǎn)擊打開確定。

附加: 

這里說(shuō)下nginx配置集群和tomcat實(shí)現(xiàn)session共享

首先要啟動(dòng)兩個(gè)tomcat,然后端口不一樣,比如8889和8899

1、nginx.conf關(guān)鍵配置

upstream serverlist {
   #最少連接數(shù),根據(jù)連接數(shù)多少自動(dòng)選擇后端服務(wù)器,連接數(shù)相等時(shí)根據(jù)權(quán)重選擇
   least_conn;
   #每個(gè)請(qǐng)求按訪問ip的hash結(jié)果分配,這樣每個(gè)訪客固定訪問一個(gè)后端服務(wù)器,可以解決session的問題
   #ip_hash; 
   #若120秒內(nèi)出現(xiàn)2次錯(cuò)誤,則下個(gè)120秒內(nèi)不再訪問此服務(wù)器,weight權(quán)重越大,請(qǐng)求機(jī)會(huì)越多
   server 127.0.0.1:8889 max_fails=2 fail_timeout=120s weight=1;#主服務(wù)
   server 127.0.0.1:8899 max_fails=2 fail_timeout=120s weight=1 backup;#備用tomcat服務(wù),主服務(wù)掛了會(huì)調(diào)用備用服務(wù)
}

2、tomcat實(shí)現(xiàn)session共享 

server.xml在Engine標(biāo)簽內(nèi)加上配置

<Engine name="Catalina" defaultHost="localhost">
    <!-- tomcat集群session共享 -->
    <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
</Engine>

修改web項(xiàng)目,工程WEB-INF下的web.xml,添加如下一句配置 

<distributable />

到此這篇關(guān)于Windows如何設(shè)置定時(shí)重啟Tomcat 的文章就介紹到這了,更多相關(guān)Tomcat定時(shí)重啟內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家! 

相關(guān)文章

最新評(píng)論

同德县| 本溪| 武冈市| 章丘市| 安阳市| 丹江口市| 台州市| 武功县| 宜阳县| 铁岭县| 白河县| 揭东县| 永年县| 灵川县| 海阳市| 自治县| 乐山市| 绥中县| 慈溪市| 玉门市| 长葛市| 大厂| 南城县| 扎兰屯市| 汉源县| 肇州县| 巩留县| 和龙市| 通江县| 昭觉县| 河源市| 沧源| 灵川县| 玉林市| 双牌县| 大埔区| 浙江省| 讷河市| 迁安市| 永春县| 清徐县|