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
Cluster URL for solicited routes. Format:
nats://host:portCluster URL from which members can solicit routes.
Comma-separated list of routes to solicit and connect to.
Cluster name. If not set, one will be dynamically generated.
Cluster URL to advertise to other servers. Useful when behind NAT.
Do not advertise known cluster information to clients.
Number of connect retries for implicit routes.
Configuration File Options
Basic Cluster Configuration
Cluster name identifier.
Host address to bind for cluster connections.
Port for cluster connections. Default is 6222.
Combined host:port listen specification.
Route Configuration
Array of route URLs to connect to other cluster members.
URL to advertise to other servers in the cluster.
Prevent advertising cluster information to clients.
Authentication
Username for route authentication.
Password for route authentication.
Route permissions configuration.
Advanced Options
Number of times to retry connecting to discovered routes.
Number of pooled connections per route. -1 means automatic.
Compression configuration for cluster connections.Available modes:
s2_auto, s2_fast, s2_better, s2_best, disabledInterval for pinging route connections.
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