版權聲明:本文為部落客chszs的原創文章,未經部落客允許不得轉載。 https://blog.csdn.net/chszs/article/details/51026728
NATS伺服器配置詳解
作者:chszs,未經部落客允許不得轉載。經許可的轉載需注明作者和部落格首頁: http://blog.csdn.net/chszs
盡管NATS可以無配置的運作,但也可以使用配置檔案配置NATS伺服器。
1)配置項包括
- 用戶端監聽器端口 Client listening port
- HTTP監聽器端口 HTTP monitoring port
- 用戶端認證 Client auth
- 叢集定義 Cluster definitions
- 叢集路由 Cluster routes
- 日志 Logging
- 最大用戶端連接配接數 Max client connections
- 最大有效負載 Max payload
- 慢消費者閥值 Slow consumer threshold
2)配置檔案的文法
NATS伺服器配置檔案的格式比較靈活,結合了傳統的JSON格式和新的YAML格式的風格。
NATS配置檔案格式支援以下文法:
- Mixed Arrays: […]
- Nested Maps: {…}
- Multiple comment types: # and //
-
Key value assigments using:
Equals sign (foo = 2)
Colon (foo: 2)
Whitespace (foo 2)
- Maps can be assigned with no key separator
- Semicolons as value terminators in key/value assignments are optional
注:YAML不是标記語言,而是一種語言中立的、對閱讀友好的資料序列化标準。YAML語言發展了三個版本,1.0、1.1、1.2,
3)NATS伺服器配置檔案示例
下面是一個完整的NATS伺服器配置檔案樣例:
port: 4242 # 供用戶端連接配接的監聽端口
net: apcera.me # 監聽的網絡位址
http_port: 8222 # HTTP監控端口
# 用戶端連接配接的認證資訊
authorization {
user: derek
password: T0pS3cr3t
timeout: 1
}
# 叢集定義
cluster {
host: '127.0.0.1' # 主機位址
port: 4244 # 路由連接配接的入站(inbound)端口
# 路由連接配接的認證資訊
authorization {
user: route_user
password: T0pS3cr3tT00!
timeout: 0.5
}
# Routes are actively solicited and connected to from this server.
# Other servers can connect to us if they supply the correct credentials
# in their routes definitions from above.
routes = [
nats-route://user1:[email protected]:4245
nats-route://user2:[email protected]:4246
]
}
# 日志選項
debug: false
trace: true
logtime: false
log_file: "/tmp/gnatsd.log"
# PID程序檔案
pid_file: "/tmp/gnatsd.pid"
# 一些系統屬性
# 用戶端最大連接配接數
max_connections: 100
# 最大協定控制行
max_control_line: 512
# 最大的有效負載
max_payload: 65536
# 慢消費者閥值
max_pending_size: 10000000