Windows Service How-To

本文详细介绍了如何将 Apache Tomcat 10 配置为 Windows 服务进行运行,包括服务的安装、更新、删除及调试等操作。同时提供了多个实例的安装指南,以及如何通过命令行参数定制服务行为。

Tomcat Home
The Apache Software Foundation
Apache Tomcat 10
Version 10.0.0-M4, Apr 3 2020
Links

Docs Home
FAQ
User Comments

User Guide

1) Introduction
2) Setup
3) First webapp
4) Deployer
5) Manager
6) Host Manager
7) Realms and AAA
8) Security Manager
9) JNDI Resources
10) JDBC DataSources
11) Classloading
12) JSPs
13) SSL/TLS
14) SSI
15) CGI
16) Proxy Support
17) MBeans Descriptors
18) Default Servlet
19) Clustering
20) Load Balancer
21) Connectors
22) Monitoring and Management
23) Logging
24) APR/Native
25) Virtual Hosting
26) Advanced IO
27) Mavenized
28) Security Considerations
29) Windows Service
30) Windows Authentication
31) Tomcat's JDBC Pool
32) WebSocket
33) Rewrite
34) CDI 2 and JAX-RS
35) GraalVM Support

Reference

Release Notes
Configuration
Tomcat Javadocs
Servlet 5.0 Javadocs
JSP 3.0 Javadocs
EL 4.0 Javadocs
WebSocket 2.0 Javadocs
JASPIC 2.0 Javadocs
Annotations 2.0 Javadocs
JK 1.2 Documentation

Apache Tomcat Development

Building
Changelog
Status
Developers
Architecture
Functional Specs.
Tribes

Windows Service How-To
Table of Contents

Tomcat service application
Tomcat monitor application
Command line arguments
Command line parameters
Installing services
Updating services
Removing services
Debugging services
Multiple Instances

Tomcat service application

Tomcat10 is a service application for running Tomcat 10 as a Windows service.
Tomcat monitor application

Tomcat10w is a GUI application for monitoring and configuring Tomcat services.

The available command line options are:
//ES// Edit service configuration This is the default operation. It is called if the no option is provided but the executable is renamed to servicenameW.exe
//MS// Monitor service Put the icon in the system tray
Command line arguments

Each command line directive is in the form of //XX//ServiceName

The available command line options are:
//TS// Run the service as console application This is the default operation. It is called if the no option is provided. The ServiceName is the name of the executable without exe suffix, meaning Tomcat10
//RS// Run the service Called only from ServiceManager
//SS// Stop the service
//US// Update service parameters
//IS// Install service
//DS// Delete service Stops the service if running
Command line parameters

Each command line parameter is prefixed with --. If the command line parameter is prefixed with ++ then it’s value will be appended to the existing option. If the environment variable with the same name as command line parameter but prefixed with PR_ exists it will take precedence. For example:

set PR_CLASSPATH=xx.jar

is equivalent to providing

–Classpath=xx.jar

as command line parameter.
ParameterName Default Description
–Description Service name description (maximum 1024 characters)
–DisplayName ServiceName Service display name
–Install procrun.exe //RS//ServiceName Install image
–Startup manual Service startup mode can be either auto or manual
–DependsOn List of services that this service depend on. Dependent services are separated using either # or ; characters
–Environment List of environment variables that will be provided to the service in the form key=value. They are separated using either # or ; characters. If you need to use either the # or ; character within a value then the entire value must be enclosed inside single quotes.
–User User account used for running executable. It is used only for StartMode java or exe and enables running applications as service under account without LogonAsService privilege.
–Password Password for user account set by --User parameter
–JavaHome JAVA_HOME Set a different JAVA_HOME than defined by JAVA_HOME environment variable
–Jvm auto Use either auto (i.e. find the JVM from the Windows registry) or specify the full path to the jvm.dll. You can use the environment variable expansion here.
–JvmOptions -Xrs List of options in the form of -D or -X that will be passed to the JVM. The options are separated using either # or ; characters. If you need to embed either # or ; characters, put them inside single quotes. (Not used in exe mode.)
–JvmOptions9 List of options in the form of -D or -X that will be passed to the JVM when running on Java 9 or later. The options are separated using either # or ; characters. If you need to embed either # or ; characters, put them inside single quotes. (Not used in exe mode.)
–Classpath Set the Java classpath. (Not used in exe mode.)
–JvmMs Initial memory pool size in MB. (Not used in exe mode.)
–JvmMx Maximum memory pool size in MB. (Not used in exe mode.)
–JvmSs Thread stack size in KB. (Not used in exe mode.)
–StartMode One of jvm, Java or exe. The modes are:

jvm - start Java in-process. Depends on jvm.dll, see --Jvm.
Java - same as exe, but automatically uses the default Java executable, i.e. %JAVA_HOME%\bin\java.exe. Make sure JAVA_HOME is set correctly, or use --JavaHome to provide the correct location. If neither is set, procrun will try to find the default JDK (not JRE) from the Windows registry.
exe - run the image as a separate process

–StartImage Executable that will be run. Only applies to exe mode.
–StartPath Working path for the start image executable.
–StartClass Main Class that contains the startup method. Applies to the jvm and Java modes. (Not used in exe mode.)
–StartMethod main Method name if differs then main
–StartParams List of parameters that will be passed to either StartImage or StartClass. Parameters are separated using either # or ; character.
–StopMode One of jvm, Java or exe. See --StartMode for further details.
–StopImage Executable that will be run on Stop service signal. Only applies to exe mode.
–StopPath Working path for the stop image executable. Does not apply to jvm mode.
–StopClass Main Class that will be used on Stop service signal. Applies to the jvm and Java modes.
–StopMethod main Method name if differs then main
–StopParams List of parameters that will be passed to either StopImage or StopClass. Parameters are separated using either # or ; character.
–StopTimeout No Timeout Defines the timeout in seconds that procrun waits for service to exit gracefully.
–LogPath %SystemRoot%\System32\LogFiles\Apache Defines the path for logging. Creates the directory if necessary.
–LogPrefix commons-daemon Defines the service log filename prefix. The log file is created in the LogPath directory with .YEAR-MONTH-DAY.log suffix
–LogLevel Info Defines the logging level and can be either Error, Info, Warn or Debug. (Case insensitive).
–StdOutput Redirected stdout filename. If named auto then file is created inside LogPath with the name service-stdout.YEAR-MONTH-DAY.log.
–StdError Redirected stderr filename. If named auto then file is created inside LogPath with the name service-stderr.YEAR-MONTH-DAY.log.
–PidFile Defines the file name for storing the running process id. Actual file is created in the LogPath directory
Installing services

The safest way to manually install the service is to use the provided service.bat script. Administrator privileges are required to run this script. If necessary, you can use the /user switch to specify a user to use for the installation of the service.

NOTE: If User Account Control (UAC) is enabled you will be asked for additional privileges when ‘Tomcat10.exe’ is launched by the script.
If you want to pass additional options to service installer as PR_* environment variables, you have to either configure them globally in OS, or launch the program that sets them with elevated privileges (e.g. right-click on cmd.exe and select “Run as administrator”; on Windows 8 (or later) or Windows Server 2012 (or later), you can open an elevated command prompt for the current directory from the Explorer by clicking on the “File” menu bar). See issue 56143 for details.

Install the service named ‘Tomcat10’
C:> service.bat install

There is a 2nd optional parameter that lets you specify the name of the service, as displayed in Windows services.

Install the service named ‘MyService’
C:> service.bat install MyService

When installing the service with a non-default name, tomcat10.exe and tomcat10w.exe may be renamed to match the chosen service name. To do this, use the --rename option.

Install the service named ‘MyService’ with renaming
C:> service.bat install MyService --rename

If using tomcat10.exe, you need to use the //IS// parameter.

Install the service named ‘Tomcat10’
C:> tomcat10 //IS//Tomcat10 --DisplayName=“Apache Tomcat 10” ^
–Install=“C:\Program Files\Tomcat\bin\tomcat10.exe” --Jvm=auto ^
–StartMode=jvm --StopMode=jvm ^
–StartClass=org.apache.catalina.startup.Bootstrap --StartParams=start ^
–StopClass=org.apache.catalina.startup.Bootstrap --StopParams=stop

Updating services

To update the service parameters, you need to use the //US// parameter.

Update the service named ‘Tomcat10’
C:> tomcat10 //US//Tomcat10 --Description="Apache Tomcat Server - https://tomcat.apache.org/ " ^
–Startup=auto --Classpath=%JAVA_HOME%\lib\tools.jar;%CATALINA_HOME%\bin\bootstrap.jar

If you gave the service an optional name, you need to specify it like this:

Update the service named ‘MyService’
C:> tomcat10 //US//MyService --Description="Apache Tomcat Server - https://tomcat.apache.org/ " ^
–Startup=auto --Classpath=%JAVA_HOME%\lib\tools.jar;%CATALINA_HOME%\bin\bootstrap.jar

Removing services

To remove the service, you need to use the //DS// parameter.
If the service is running it will be stopped and then deleted.

Remove the service named ‘Tomcat10’
C:> tomcat10 //DS//Tomcat10

If you gave the service an optional name, you need to specify it like this:

Remove the service named ‘MyService’
C:> tomcat10 //DS//MyService

Debugging services

To run the service in console mode, you need to use the //TS// parameter. The service shutdown can be initiated by pressing CTRL+C or CTRL+BREAK. If you rename the tomcat10.exe to testservice.exe then you can just execute the testservice.exe and this command mode will be executed by default.

Run the service named ‘Tomcat10’ in console mode
C:> tomcat10 //TS//Tomcat10 [additional arguments]
Or simply execute:
C:> tomcat10

Multiple Instances

Tomcat supports installation of multiple instances. You can have a single installation of Tomcat with multiple instances running on different IP/port combinations, or multiple Tomcat versions, each running one or more instances on different IP/ports.

Each instance folder will need the following structure:

conf
logs
temp
webapps
work

At a minimum, conf should contain a copy of the following files from CATALINA_HOME\conf. Any files not copied and edited, will be picked up by default from CATALINA_HOME\conf, i.e. CATALINA_BASE\conf files override defaults from CATALINA_HOME\conf.

server.xml
web.xml

You must edit CATALINA_BASE\conf\server.xml to specify a unique IP/port for the instance to listen on. Find the line that contains <Connector port=“8080” … and add an address attribute and/or update the port number so as to specify a unique IP/port combination.

To install an instance, first set the CATALINA_HOME environment variable to the name of the Tomcat installation directory. Then create a second environment variable CATALINA_BASE and point this to the instance folder. Then run “service.bat install” command specifying a service name.

set CATALINA_HOME=c:\tomcat_10
set CATALINA_BASE=c:\tomcat_10\instances\instance1
service.bat install instance1

To modify the service settings, you can run tomcat10w //ES//instance1.

For additional instances, create additional instance folder, update the CATALINA_BASE environment variable, and run the “service.bat install” again.

set CATALINA_BASE=c:\tomcat_10\instances\instance2
service.bat install instance2

Copyright © 1999-2020, The Apache Software Foundation

Options: --networkMessageCompressors arg (=snappy,zstd,zlib) Comma-separated list of compressors to use for network messages General options: -h [ --help ] Show this usage information --version Show version information -f [ --config ] arg Configuration file specifying additional options --configExpand arg Process expansion directives in config file (none, exec, rest) --port arg Specify port number - 27017 by default --ipv6 Enable IPv6 support (disabled by default) --listenBacklog arg Set socket listen backlog size --maxConns arg (=1000000) Max number of simultaneous connections --pidfilepath arg Full path to pidfile (if not set, no pidfile is created) --timeZoneInfo arg Full path to time zone info directory, e.g. /usr/share/zoneinfo -v [ --verbose ] [=arg(=v)] Be more verbose (include multiple times for more verbosity e.g. -vvvvv) --quiet Quieter output --logpath arg Log file to send write to instead of stdout - has to be a file, not directory --logappend Append to logpath instead of over-writing --logRotate arg Set the log rotation behavior (rename|reopen) --timeStampFormat arg Desired format for timestamps in log messages. One of iso8601-utc or iso8601-local --setParameter arg Set a configurable parameter --extensions arg Specify paths to extensions to load --bind_ip arg Comma separated list of ip addresses to listen on - localhost by default --bind_ip_all Bind to all ip addresses --noauth Run without security --transitionToAuth For rolling access control upgrade. Attempt to authenticate over outgoing connections and proceed regardless of success. Accept incoming connections with or without authentication. --slowms arg (=100) Value of slow for profile and console log --slowTaskWaitTimeProfilingMs arg (=50) Value of slow wait time for tasks --slowOpSampleRate arg (=1) Fraction of slow ops to include in the profile and console log --profileFilter arg Query predicate to control which operations are logged and profiled --auth Run with security --clusterIpSourceAllowlist arg Network CIDR specification of permitted origin for `__system` access --profile arg 0=off 1=slow, 2=all --cpu Periodically show cpu and iowait utilization --sysinfo Print some diagnostic system information --noscripting Disable scripting engine --notablescan Do not allow table scans --proxyPort arg The port that accepts connections with a proxy protocol header. --keyFile arg Private key for cluster authentication --clusterAuthMode arg Authentication mode used for cluster authentication. Alternatives are (keyFile|sendKeyFile|sendX509|x509) Replication options: --oplogSize arg Size to use (in MB) for replication op log. default is 5% of disk space (i.e. large is good) Replica set options: --replSet arg arg is <setname>[/<optionalseedhostlist >] --replSetName arg arg is <setname> Serverless mode: --serverless arg Serverless mode implies replication is enabled, cannot be used with replSet or replSetName. Sharding options: --configsvr Assigns the config-server role to this node in a sharded cluster. The default listening port is 27019 and the default database directory is /data/configdb. --shardsvr Assigns the shard-server role to this node in a sharded cluster. The default listening port is 27018. --routerPort [=arg(=27016)] Assigns the router role to this node in a sharded cluster, and results in listening to a dedicated port (27016 by default) to serve routing requests. --maintenanceMode arg Allows this node to skip starting up sharding components or both replication and sharding components. This allows for performing maintenance on this node. To skip setting up just sharding components use --maintenanceMode=replic aSet. To skip setting up both sharding and replication components use --maintenanceMode=standalone. --replicaSetConfigShardMaintenanceMode Bypasses validation of configuration mismatches between startup parameters and the stored replSetConfig. Enables restarting the node as a configsvr even if the stored configuration is for a replica set, and vice versa. Storage options: --storageEngine arg What storage engine to use - defaults to wiredTiger if no data files present --dbpath arg Directory for datafiles - defaults to \data\db\ which is C:\data\db\ based on the current working drive --directoryperdb Each database will be stored in a separate directory --syncdelay arg Seconds between disk syncs --journalCommitInterval arg how often to group/batch commit (ms) --upgrade Upgrade db if needed --repair Run repair on all dbs --validate Run validation on all collections --restore This should only be used when restoring from a backup. Mongod will behave differently by handling collections with missing data files, allowing database renames, skipping oplog entries for collections not restored and more. --oplogMinRetentionHours arg (=0) Minimum number of hours to preserve in the oplog. Default is 0 (turned off). Fractions are allowed (e.g. 1.5 hours) TLS Options: --tlsOnNormalPorts Use TLS on configured ports --tlsMode arg Set the TLS operation mode (disabled|allowTLS|preferTLS|requireTLS ) --tlsCertificateKeyFile arg Certificate and key file for TLS. Certificate is presented in response to inbound connections always. Certificate is also presented for outbound connections if tlsClusterFile is not specified. --tlsCertificateKeyFilePassword arg Password to unlock key in the TLS certificate key file --tlsClusterFile arg Certificate and key file for internal TLS authentication. Certificate is presented on outbound connections if specified. --tlsClusterPassword arg Internal authentication key file password --tlsCAFile arg Certificate Authority file for TLS. Used to verify remote certificates presented in response to outbound connections. Also used to verify remote certificates from inbound connections if tlsClusterCAFile is not specified. --tlsClusterCAFile arg CA used for verifying remotes during inbound connections --tlsCRLFile arg Certificate Revocation List file for TLS --tlsDisabledProtocols arg Comma separated list of TLS protocols to disable [TLS1_0,TLS1_1,TLS1_2,TLS1_3 ] --tlsAllowConnectionsWithoutCertificates Allow client to connect without presenting a certificate --tlsAllowInvalidHostnames Allow server certificates to provide non-matching hostnames --tlsAllowInvalidCertificates Allow connections to servers with invalid certificates --tlsCertificateSelector arg TLS Certificate in system store --tlsClusterCertificateSelector arg SSL/TLS Certificate in system store for internal TLS authentication --tlsLogVersions arg Comma separated list of TLS protocols to log on connect [TLS1_0,TLS1_1,TLS1_2 ,TLS1_3] --tlsClusterAuthX509ExtensionValue arg If specified, clients who expect to be regarded as cluster members must present a valid X.509 certificate containing an X.509 extension for OID 1.3.6.1.4.1.34601.2.1.2 which contains the specified value. --tlsClusterAuthX509Attributes arg If specified, clients performing X.509 authentication must present a certificate with a subject name with the exact attributes and values provided in this config option to be treated as peer cluster nodes. AWS IAM Options: --awsIamSessionToken arg AWS Session Token for temporary credentials WiredTiger options: --wiredTigerCacheSizeGB arg Maximum amount of memory to allocate for cache in GB; Defaults to 1/2 of physical RAM. Only one of either wiredTigerCacheSizePct or wiredTigerCacheSizeGB can be provided --wiredTigerCacheSizePct arg Maximum amount of memory to allocate for cache as a percentage of physical RAM; Defaults to 1/2 of physical RAM and a minimum of 256MB. Only one of either wiredTigerCacheSizePct or wiredTigerCacheSizeGB can be provided --zstdDefaultCompressionLevel arg (=6) Default compression level for zstd compressor --wiredTigerJournalCompressor arg (=snappy) Use a compressor for log records [none|snappy|zlib|zstd] --wiredTigerDirectoryForIndexes Put indexes and data in different directories --wiredTigerLiveRestoreSource arg Path to the source for live restore. --wiredTigerLiveRestoreThreads arg (=8) Number of live restore background threads. --wiredTigerLiveRestoreReadSizeMB arg (=1) 'The read size for data migration, in MB, must be a power of two. This setting is a best effort. It does not force every read to be this size.' --wiredTigerCollectionBlockCompressor arg (=snappy) Block compression algorithm for collection data [none|snappy|zlib|zstd] --wiredTigerIndexPrefixCompression arg (=1) Use prefix compression on row-store leaf pages Windows Service Control Manager options: --install Install Windows service --remove Remove Windows service --reinstall Reinstall Windows service (equivalent to --remove followed by --install) --serviceName arg Windows service name --serviceDisplayName arg Windows service display name --serviceDescription arg Windows service description --serviceUser arg Account for service execution --servicePassword arg Password used to authenticate serviceUser
最新发布
11-22
ntopng 是一款功能强大的网络流量监控工具,作为 ntop 的下一代版本,它提供了基于 Web 的图形用户界面,能够实时分析和可视化网络流量数据。在 Windows 10 上安装 ntopng 需要依赖一些额外的组件和配置步骤,以下是详细的安装指南: ### 安装准备 1. **安装 WinPcap/Npcap** ntopng 依赖于 WinPcap 或其现代替代 Npcap 来捕获网络流量。 - 推荐下载并安装 [Npcap](https://nmap.org/npcap/)(由 Nmap 项目维护),它兼容 Windows 10 并支持最新的操作系统版本。 - 安装过程中请确保勾选“安装为 WinPcap 兼容模式”,以便 ntopng 能够识别该库。 2. **安装 Redis** ntopng 使用 Redis 作为其数据缓存和通信中间件。 - 可以通过 [Redis 官方网站](https://redis.io/)下载 Redis 并安装,或者使用 [Redis for Windows](https://github.com/microsoftarchive/redis) 的移植版本。 - 安装完成后确保 Redis 服务正在运行。 3. **安装 GeoIP 数据库(可选)** 为了支持地理定位功能,建议安装 MaxMind 的 GeoIP2 数据库。 - 下载 `GeoLite2-Country.mmdb` 和 `GeoLite2-City.mmdb` 文件,并将其放置在 ntopng 的配置目录中。 ### 安装 ntopng 1. **下载 Windows 版本的 ntopng** - 访问 [ntopng 官方下载页面](https://www.ntop.org/products/traffic-analysis/ntop/),选择适用于 Windows 的版本。 - 当前版本通常以 ZIP 压缩包形式提供。 2. **解压并配置** - 将 ZIP 文件解压到一个目录,例如 `C:\ntopng`。 - 编辑配置文件 `ntopng.conf`,根据需要调整参数,例如绑定的网络接口、Web 端口(默认为 `3000`)等。 3. **运行 ntopng** - 打开命令提示符,进入解压目录并运行以下命令启动 ntopng: ```bash ntopng.exe -i <interface_name> ``` 其中 `<interface_name>` 是你希望监控的网络接口名称(例如 `以太网` 或 `Wi-Fi`)。 4. **访问 Web 界面** - 打开浏览器,访问 `http://localhost:3000`,即可看到 ntopng 的 Web 界面。 - 初始用户名和密码均为 `admin`,首次登录后应立即更改密码。 ### 启动与服务配置(可选) 如果希望 ntopng 在系统启动时自动运行,可以将其注册为 Windows 服务。使用 `NSSM`(Non-Sucking Service Manager)工具将 ntopng 添加为服务,确保路径和参数正确设置。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值