Overview
Cluster options enable multiple NATS servers to communicate and share message routing information, creating a distributed system with high availability and horizontal scalability.Command Line Flags
string
Cluster URL for solicited routes. Format:
nats://host:portstring
Cluster URL from which members can solicit routes.
string
Comma-separated list of routes to solicit and connect to.
string
Cluster name. If not set, one will be dynamically generated.
string
Cluster URL to advertise to other servers. Useful when behind NAT.
boolean
Do not advertise known cluster information to clients.
integer
Number of connect retries for implicit routes.
Configuration File Options
Basic Cluster Configuration
string
Cluster name identifier.
string
default:"0.0.0.0"
Host address to bind for cluster connections.
integer
default:"6222"
Port for cluster connections. Default is 6222.
string
Combined host:port listen specification.
Route Configuration
array
Array of route URLs to connect to other cluster members.
string
URL to advertise to other servers in the cluster.
boolean
default:"false"
Prevent advertising cluster information to clients.
Authentication
string
Username for route authentication.
string
Password for route authentication.
object
Route permissions configuration.
Advanced Options
integer
default:"0"
Number of times to retry connecting to discovered routes.
integer
default:"-1"
Number of pooled connections per route. -1 means automatic.
object
Compression configuration for cluster connections.Available modes:
s2_auto, s2_fast, s2_better, s2_best, disabledduration
default:"30s"
Interval for pinging route connections.
duration
Write deadline for route connections.
Configuration Examples
Three-Node Cluster
Server 1 Configuration:Cluster with Authentication
Cluster Behind NAT
Cluster with Compression
Cluster Management
Verifying Cluster Status
Check cluster status via monitoring endpoint:Dynamic Cluster Growth
New servers can join by configuring routes to existing members:Best Practices
- Cluster Name: Use consistent cluster names across all servers
- Full Mesh: Configure routes to all other cluster members for fastest convergence
- Odd Numbers: Use odd numbers of servers (3, 5, 7) for better consensus
- Authentication: Always use authentication for route connections in production
- Network Isolation: Keep cluster traffic on dedicated network interfaces when possible
- Compression: Enable compression for geo-distributed clusters to reduce bandwidth
- Monitoring: Monitor route connections through
/routezendpoint - DNS/Discovery: Use DNS or service discovery for dynamic cluster membership
Troubleshooting
Connection Issues
- Verify firewall rules allow port 6222 (or custom cluster port)
- Check that routes are using correct URLs and authentication
- Review server logs for connection errors
Split Brain Prevention
- Ensure consistent cluster names across all servers
- Configure routes to multiple cluster members
- Monitor cluster connectivity via
/routez
Related Configuration
Server Options
Core server configuration
TLS Options
Secure cluster connections with TLS
JetStream Options
Cluster JetStream for distributed persistence