Running and deploying a NATS Server
The nats-server has many command line options. To get started, you don't have to specify anything. In the absence of any flags, the NATS server will start listening for NATS client connections on port 4222. By default, security is disabled.
Standalone
When the server starts it will print some information including where the server is listening for client connections:
Docker
If you are running your NATS server in a docker container:
Running nats-server as a systemd service on Linux
You can easily and quickly use systemd
to start (and restart if needed) the nats-server
process.
Exit Status
As a long-running service, it's important for administrators to understand what guarantees the nats-server
makes about how it exits and what that means.
The approach chosen by nats-server
is that "exited cleanly after being asked to shutdown" is a successful exit. Even on platforms where that shutdown request is a POSIX signal. It is not an error to successfully exit when asked to shut down.
When configuring a service manager, whether systemd
or any other, we recommend that it be configured to restart the nats-server
on non-zero exit status or death by signal or any other abnormal exit, so that the service manager does what service managers do best: keeping essential services available when wanted. The service manager probably should not restart the nats-server
if it exits successfully. If your environment does not provide any means to interact with the nats-server
except through the service agent, then it doesn't matter either way; this distinction only becomes noticeable when something other than the service manager asked the nats-server
to shut down.
JetStream
Remember that in order to enable JetStream and all the functionalities that use it you need to enable it on at least one of your servers
Command Line
Enable JetStream by specifying the -js
flag when starting the NATS server.
$ nats-server -js
Configuration File
You can also enable JetStream through a configuration file. By default, the JetStream subsytem will store data in the /tmp directory. Here's a minimal file that will store data in a local "nats" directory, suitable for development and local testing.
Last updated
Was this helpful?