Deployment guide

NATS 2

Overview

NATS is a high-performance distributed messaging system, originally developed at Apcera and now a CNCF graduated project. The SecureAnyCloud image installs the latest NATS 2.x server as a single Go binary (about 20 MB resident).

JetStream is enabled, and the image uses a per-VM rotating sac/admin password.

What you get:

  • NATS 2.x single Go binary at /usr/local/bin/nats-server
  • JetStream persistence enabled (file storage at /var/lib/nats/jetstream)
  • Client port 4222, monitoring HTTP port 8222 (JSON endpoints such as /varz, /connz and /subsz), and cluster route port 6222
  • A per-VM SecureAnyCloud user password, rotated at first boot with openssl rand -hex 16
  • Authentication required, with anonymous connections rejected
  • nats.service running as nats:nats
  • 24/7 SecureAnyCloud support

Prerequisites

You need an active Azure subscription, an SSH key, and a VNet with a subnet.

The recommended size is Standard_B2s, because NATS is very efficient.

Step 1-3: Deploy + SSH (standard pattern)

ssh azureuser@<vm-ip>
sudo systemctl status nats.service --no-pager
4

Retrieve the Password

sudo cat /stage/scripts/nats-credentials.log curl -fsS http://localhost:8222/varz | head -10
5

Pub/Sub Round-Trip

The NATS protocol is plain text, so you can do a round trip with bash and /dev/tcp alone. Subscribe in the first terminal:

PASS=$(sudo grep '^NATS_PASSWORD=' /stage/scripts/nats-credentials.log | cut -d= -f2-)
# Subscribe (run in one terminal) exec 3<>/dev/tcp/localhost/4222 printf 'CONNECT {"user":"sac","pass":"'"${PASS}"'"}\r\n' >&3 printf 'SUB hello 1\r\n' >&3 cat <&3

In another terminal: printf 'PUB hello 5\r\nworld\r\n' | bash -c 'exec 3<>/dev/tcp/localhost/4222 && cat >&3'. The first terminal will print MSG hello 1 5\nworld.

For real applications, use the official client libraries (Go, Java, JavaScript, Python, Rust, .NET).

6

Components

Component Path

Binary /usr/local/bin/nats-server

Config /etc/nats/nats-server.conf

JetStream /var/lib/nats/jetstream/

Systemd unit /etc/systemd/system/nats.service

Firstboot /usr/local/sbin/nats-firstboot.sh

Credentials /stage/scripts/nats-credentials.log (mode 0600)

/usr/local/bin/nats-server --version
7

Security

  • Restrict the NSG so that port 4222 only reaches your client networks.
  • Enable TLS with tls { cert_file: ..., key_file: ... } in nats-server.conf.
  • Migrate to NSC accounts for fine-grained, per-application JWT authentication.
  • Patch monthly with apt-get update && apt-get upgrade && reboot.
8

Support and Licensing

NATS is released under the Apache 2.0 licence and is free. SecureAnyCloud provides commercial support separately.

  • Email: sales@secureanycloud.com
  • Support hours: 24/7, 24h response SLA

Deploy on Azure

Launch NATS 2 with 24/7 support from SecureAnyCloud. View on Marketplace.

Deploy on Azure

Launch NATS 2 on Ubuntu 24.04 LTS on Azure with 24/7 support from SecureAnyCloud.

View this image

Need Help?

Our support team is available 24/7.

sales@secureanycloud.com

Deploy on Azure