共计 2608 个字符,预计需要花费 7 分钟才能阅读完成。
influxdb 从 0.12 版本开始不再将其 cluster 源码开源。
基于 influxdb 1.6.0 单机版源码分支,将 0.12 的 cluster 源码 cherry-pick 过去,能够失去 v1.6.0 版本的集群版源码。
分布式 InfluxDB 集群有两种节点:meta 节点和 data 节点:
- meta 节点负责管理集群的元数据信息,比方 database/retention policy 等;
- data 节点负责保留集群的时序数据;
分布式 InfluxDB 集群的一致性来说:
- meta 节点要求强一致性,即在节点间始终保持统一,通过 Raft 实现;
- data 节点要求最终一致性,即时序数据最终保障统一即可,通过 hh,anti-entropy 实现;
在理论部署中,如果节点较少,通常 1 个节点同时负责 meta 和 data 的职责,看一下它的整体构造:
每个节点应用 4 个端口:
- 8086:负责接管解决 client 的 /query 和 /write 操作;
- 8084:负责接管解决 client 的集群治理操作,比方增加 / 删除节点等;
- 8088:负责底层 Raft 的 RPC 通信 (TCP),传入 Raft lib 即可;
- 8091:负责节点间 HTTP 查问和操作 Raft 信息,比方 /join、/execute 等;
端口 8086
配置文件中指定:
[http] | |
# Determines whether HTTP endpoint is enabled. | |
# enabled = true | |
# The bind address used by the HTTP service. | |
bind-address = "0.0.0.0:8086" |
代码中应用该端口:
//services/httpd/service.go | |
// NewService returns a new instance of Service. | |
func NewService(c Config) *Service { | |
s := &Service{ | |
addr: c.BindAddress, | |
https: c.HTTPSEnabled, | |
cert: c.HTTPSCertificate, | |
key: c.HTTPSPrivateKey, | |
limit: c.MaxConnectionLimit, | |
err: make(chan error), | |
unixSocket: c.UnixSocketEnabled, | |
unixSocketPerm: uint32(c.UnixSocketPermissions), | |
bindSocket: c.BindSocket, | |
Handler: NewHandler(c), | |
Logger: zap.NewNop(),} | |
..... | |
} |
端口 8084
次要负责集群治理 API,比方 show-nodes/add-data/add-meta 等:
配置文件中指定:
[admin_cluster] | |
enabled = true | |
bind-address = ":8084" | |
https-enabled = true |
代码中应用端口:
//services/admin_cluster/config.go | |
const ( | |
// DefaultBindAddress is the default bind address for the HTTP server. | |
DefaultBindAddress = ":8084" | |
} | |
// NewConfig returns an instance of Config with defaults. | |
func NewConfig() Config { | |
return Config{ | |
BindAddress: DefaultBindAddress, | |
AuthEnabled: false, | |
HTTPSEnabled: false, | |
HTTPSCertificate: "/etc/ssl/influxdb.pem", | |
MaxKeepCopyShard: DefaultMaxKeepCopyShard, | |
} | |
} |
端口 8088 和 8091
代码中的默认端口:
//services/meta/config.go | |
const ( | |
// DefaultRaftBindAddress is the default address to bind to. | |
DefaultRaftBindAddress = ":8088" | |
// DefaultHTTPBindAddress is the default address to bind the API to. | |
DefaultHTTPBindAddress = ":8091" | |
) | |
// NewConfig builds a new configuration with default values. | |
func NewConfig() *Config { | |
return &Config{ | |
Enabled: true, // enabled by default | |
BindAddress: DefaultRaftBindAddress, | |
HTTPBindAddress: DefaultHTTPBindAddress, | |
RetentionAutoCreate: true, | |
ElectionTimeout: toml.Duration(DefaultElectionTimeout), | |
HeartbeatTimeout: toml.Duration(DefaultHeartbeatTimeout), | |
LeaderLeaseTimeout: toml.Duration(DefaultLeaderLeaseTimeout), | |
CommitTimeout: toml.Duration(DefaultCommitTimeout), | |
RaftPromotionEnabled: DefaultRaftPromotionEnabled, | |
LeaseDuration: toml.Duration(DefaultLeaseDuration), | |
LoggingEnabled: DefaultLoggingEnabled, | |
JoinPeers: []string{}, | |
} | |
} |
应用这 2 个端口创立 meta 服务:
//services/meta/service.go | |
func NewService(c *Config) *Service { | |
s := &Service{ | |
config: c, | |
httpAddr: c.HTTPBindAddress, | |
raftAddr: c.BindAddress, | |
https: c.HTTPSEnabled, | |
cert: c.HTTPSCertificate, | |
err: make(chan error), | |
Logger: zap.NewNop(),} | |
return s | |
} |
正文完