Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature](network interface) Support network interface #16617

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions be/src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ CONF_Int32(single_replica_load_brpc_num_threads, "64");
// If no ip match this rule, will choose one randomly.
CONF_String(priority_networks, "");

CONF_String(network_interfaces, "");

// memory mode
// performance or compact
CONF_String(memory_mode, "moderate");
Expand Down
55 changes: 52 additions & 3 deletions be/src/service/backend_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

#include "service/backend_options.h"

#include <arpa/inet.h>
#include <ifaddrs.h>

#include <algorithm>

#include "common/config.h"
Expand All @@ -31,14 +34,19 @@ namespace doris {
static const std::string PRIORITY_CIDR_SEPARATOR = ";";

std::string BackendOptions::_s_localhost;
std::vector<std::string> BackendOptions::_s_network_interfaces;
std::vector<CIDR> BackendOptions::_s_priority_cidrs;
bool BackendOptions::_bind_ipv6 = false;
const char* _service_bind_address = "0.0.0.0";

bool BackendOptions::init() {
if (!analyze_priority_cidrs()) {
bool interfaceResult = get_network_interfaces();
bool cidrResult = analyze_priority_cidrs();

if (!interfaceResult && !cidrResult) {
return false;
}

std::vector<InetAddress> hosts;
Status status = get_hosts(&hosts);

Expand All @@ -56,7 +64,11 @@ bool BackendOptions::init() {
std::vector<InetAddress>::iterator addr_it = hosts.begin();
for (; addr_it != hosts.end(); ++addr_it) {
VLOG_CRITICAL << "check ip=" << addr_it->get_host_address();
if (!_s_priority_cidrs.empty()) {
if (!_s_network_interfaces.empty()) {
if (is_in_network_interface(addr_it->get_host_address())) {
_s_localhost = addr_it->get_host_address();
}
} else if (!_s_priority_cidrs.empty()) {
// Whether to use IPV4 or IPV6, it's configured by CIDR format.
// If both IPV4 and IPV6 are configured, the config order decides priority.
if (is_in_prior_network(addr_it->get_host_address())) {
Expand Down Expand Up @@ -118,6 +130,43 @@ bool BackendOptions::analyze_priority_cidrs() {
return true;
}

bool BackendOptions::get_network_interfaces() {
if (config::network_interfaces == "") {
return true;
}
LOG(INFO) << "network interfaces in conf: " << config::network_interfaces;

struct ifaddrs* if_addr_struct = nullptr;
void* tmp_addr_ptr = nullptr;
getifaddrs(&if_addr_struct);

std::vector<std::string> nic_names =
strings::Split(config::network_interfaces, PRIORITY_CIDR_SEPARATOR);
bool flag = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

found may be a better name here.


for (auto& nic_name : nic_names) {
for (; if_addr_struct != nullptr; if_addr_struct = if_addr_struct->ifa_next) {
if (nic_name == if_addr_struct->ifa_name) {
tmp_addr_ptr = &((struct sockaddr_in*)if_addr_struct->ifa_addr)->sin_addr;
char address_buffer[INET_ADDRSTRLEN];
inet_ntop(AF_INET, tmp_addr_ptr, address_buffer, INET_ADDRSTRLEN);
_s_network_interfaces.push_back(address_buffer);
flag = true;
}
}
}
return flag;
}

bool BackendOptions::is_in_network_interface(const std::string& ip) {
for (auto& interface_ip : _s_network_interfaces) {
if (interface_ip == ip) {
return true;
}
}
return false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


bool BackendOptions::is_in_prior_network(const std::string& ip) {
for (auto& cidr : _s_priority_cidrs) {
CIDR _ip;
Expand All @@ -129,4 +178,4 @@ bool BackendOptions::is_in_prior_network(const std::string& ip) {
return false;
}

} // namespace doris
} // namespace doris
3 changes: 3 additions & 0 deletions be/src/service/backend_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ class BackendOptions {
static const char* get_service_bind_address();

private:
static bool get_network_interfaces();
static bool analyze_priority_cidrs();
static bool is_in_prior_network(const std::string& ip);
static bool is_in_network_interface(const std::string& ip);

static std::vector<std::string> _s_network_interfaces;
static std::string _s_localhost;
static std::vector<CIDR> _s_priority_cidrs;
static bool _bind_ipv6;
Expand Down
4 changes: 4 additions & 0 deletions conf/be.conf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ brpc_port = 8060
# Default value is empty.
# priority_networks = 10.10.10.0/24;192.168.0.0/16

# Use network interface name, e.g. eth0
# Default value is empty.
# network_interfaces = eth0;docker0

# data root path, separate by ';'
# you can specify the storage medium of each root path, HDD or SSD
# you can add capacity limit at the end of each root path, separate by ','
Expand Down
4 changes: 4 additions & 0 deletions conf/fe.conf
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ mysql_service_nio_enabled = true
# Default value is empty.
# priority_networks = 10.10.10.0/24;192.168.0.0/16

# Use network interface name, e.g. eth0
# Default value is empty.
# network_interfaces = eth0;docker0

# Advanced configurations
# log_roll_size_mb = 1024
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

# sys_log_dir = ${DORIS_HOME}/log
Expand Down
5 changes: 5 additions & 0 deletions docs/en/docs/admin-manual/config/be-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ There are two ways to configure BE configuration items:
* Description: Declare a selection strategy for those servers with many IPs. Note that at most one ip should match this list. This is a semicolon-separated list in CIDR notation, such as 10.10.10.0/24. If there is no IP matching this rule, one will be randomly selected
* Default value: blank

#### `network_interfaces`

* Description: Declare a selection strategy for those servers with many IPs. Note that at most one network interface name should match this list. This is a semicolon-separated list represented by the network interface name, such as `eth0`. Doris will prioritize IPs that match this rule and only match `priority_networks` if no matching IPs are found.
* Default value: blank

#### `storage_root_path`

* Type: string
Expand Down
9 changes: 8 additions & 1 deletion docs/en/docs/admin-manual/config/fe-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,14 @@ Default value: 0.0.0.0

Default:none

Declare a selection strategy for those servers have many ips. Note that there should at most one ip match this list. this is a list in semicolon-delimited format, in CIDR notation, e.g. 10.10.10.0/24 , If no ip match this rule, will choose one randomly..
Declare a selection strategy for those servers have many ips. Note that there should at most one ip match this list. this is a list in semicolon-delimited format, in CIDR notation, e.g. 10.10.10.0/24 , If no ip match this rule, will choose one randomly.

#### `network_interfaces`

Default: none

Declare a selection strategy for those servers with many IPs. Note that at most one network interface name should match this list. This is a semicolon-separated list represented by the network interface name, such as `eth0`. Doris will prioritize IPs that match this rule and only match `priority_networks` if no matching IPs are found.


#### `http_port`

Expand Down
25 changes: 20 additions & 5 deletions docs/en/docs/get-starting/get-starting.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,28 @@ Go to the `apache-doris-x.x.x/fe` directory
cd apache-doris-x.x.x/fe
```

Modify the FE configuration file `conf/fe.conf`, here we mainly modify two parameters: `priority_networks` and `meta_dir`, if you need more optimized configuration, please refer to [FE parameter configuration](../admin-manual/config/fe-config.md) for instructions on how to adjust them.
Modify the FE configuration file `conf/fe.conf`, here we mainly modify two parameters: `priority_networks` or `network_interfaces` and `meta_dir`, if you need more optimized configuration, please refer to [FE parameter configuration](../admin-manual/config/fe-config) for instructions on how to adjust them.

1. add priority_networks parameter

```
priority_networks=172.23.16.0/24
```

2. add network_interfaces parameter

```
network_interfaces=eth0
```

>Note:
>
>This parameter we have to configure during installation, especially when a machine has multiple IP addresses, we have to specify a unique IP address for FE.
>At least one of these parameters must be configured during installation(`network_interfaces` takes precedence over `priority_networks`), especially when a machine has multiple IP addresses, we have to specify a unique IP address for FE.

>Assuming that your node IP is `172.23.16.32`, we can configure it using the mask as `172.23.16.0/24`.
>If the `network_interfaces` are configured correctly, they will be given priority over `priority_networks` even if they are already configured.

2. Adding a metadata directory
3. Adding a metadata directory

```
meta_dir=/path/your/doris-meta
Expand Down Expand Up @@ -175,17 +184,23 @@ Go to the `apache-doris-x.x.x/be` directory
cd apache-doris-x.x.x/be
```

Modify the BE configuration file `conf/be.conf`, here we mainly modify two parameters: `priority_networks'` and `storage_root`, if you need more optimized configuration, please refer to [BE parameter configuration](../admin-manual/config/be-config.md) instructions to make adjustments.
Modify the BE configuration file `conf/be.conf`, here we mainly modify two parameters: `priority_networks` or `network_interfaces` and `storage_root`, if you need more optimized configuration, please refer to [BE parameter configuration](../admin-manual/config/be-config) instructions to make adjustments.

1. Add priority_networks parameter

```
priority_networks=172.23.16.0/24
```

2. add network_interfaces parameter

```
network_interfaces=eth0
```

>Note:
>
>This parameter we have to configure during installation, especially when a machine has multiple IP addresses, we have to assign a unique IP address to the BE.
>At least one of these parameters must be configured during installation(`network_interfaces` takes precedence over `priority_networks`), especially when a machine has multiple IP addresses, we have to assign a unique IP address to the BE.

2. Configure the BE data storage directory

Expand Down
8 changes: 6 additions & 2 deletions docs/en/docs/install/install-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,18 @@ Doris instances communicate directly over the network. The following table shows

#### IP Binding

Because of the existence of multiple network cards, or the existence of virtual network cards caused by the installation of docker and other environments, the same host may have multiple different IPs. Currently Doris does not automatically identify available IPs. So when you encounter multiple IPs on the deployment host, you must specify the correct IP via the `priority_networks` configuration item.
Because of the existence of multiple network cards, or the existence of virtual network cards caused by the installation of docker and other environments, the same host may have multiple different IPs. Currently Doris does not automatically identify available IPs. So when you encounter multiple IPs on the deployment host, you must specify the correct IP via the `priority_networks` or `network_interfaces` configuration item(note that `network_interfaces` takes priority over `priority_networks`).

`priority_networks` is a configuration item that both FE and BE have. It needs to be written in fe.conf and be.conf. It is used to tell the process which IP should be bound when FE or BE starts. Examples are as follows:
`priority_networks` and `network_interfaces` are configurations item that both FE and BE have. It needs to be written in fe.conf and be.conf. It is used to tell the process which IP should be bound when FE or BE starts. Examples are as follows:

`priority_networks=10.1.3.0/24`

This is a representation of [CIDR](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing). FE or BE will find the matching IP based on this configuration item as their own local IP.

`network_interfaces=eth0`

This is a representation method using the network card name. FE or BE will look for a matching IP based on this configuration item as its `localIP`. If this configuration item does not match any IP, `priority_networks` configuration item will be executed instead.

**Note**: Configuring `priority_networks` and starting FE or BE only ensure the correct IP binding of FE or BE. You also need to specify the same IP in ADD BACKEND or ADD FRONTEND statements, otherwise the cluster cannot be created. For example:

BE is configured as `priority_networks = 10.1.3.0/24'.`.
Expand Down
5 changes: 5 additions & 0 deletions docs/zh-CN/docs/admin-manual/config/be-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ BE 重启后该配置将失效。如果想持久化修改结果,使用如下
* 描述: 为那些有很多 ip 的服务器声明一个选择策略。 请注意,最多应该有一个 ip 与此列表匹配。 这是一个以分号分隔格式的列表,用 CIDR 表示法,例如 10.10.10.0/24 , 如果没有匹配这条规则的ip,会随机选择一个。
* 默认值: 空

#### `network_interfaces`

* 描述: 同样为那些有很多 ip 的服务器声明一个选择策略。 请注意,最多应该有一个网卡名与此列表匹配。 这是一个以分号分隔格式的列表,用网卡名称表示,例如 `eth0` 。 Doris会优先匹配符合这条规则的ip,如果匹配没有匹配到ip,才会匹配 `priority_networks` 配置。
* 默认值: 空

#### `storage_root_path`

* 类型:string
Expand Down
6 changes: 6 additions & 0 deletions docs/zh-CN/docs/admin-manual/config/fe-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,12 @@ Doris FE 通过 mysql 协议查询连接端口

为那些有很多 ip 的服务器声明一个选择策略。 请注意,最多应该有一个 ip 与此列表匹配。 这是一个以分号分隔格式的列表,用 CIDR 表示法,例如 10.10.10.0/24。 如果没有匹配这条规则的ip,会随机选择一个。

#### `network_interfaces`

默认值:空

同样为那些有很多 ip 的服务器声明一个选择策略。 请注意,最多应该有一个网卡名与此列表匹配。 这是一个以分号分隔格式的列表,用网卡名称表示,例如 `eth0` 。 Doris会优先匹配符合这条规则的ip,如果匹配没有匹配到ip,才会匹配 `priority_networks` 配置。

#### `http_port`

默认值:8030
Expand Down
29 changes: 21 additions & 8 deletions docs/zh-CN/docs/get-starting/get-starting.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,28 @@ tar zxf apache-doris-x.x.x.tar.gz
cd apache-doris-x.x.x/fe
```

修改 FE 配置文件 `conf/fe.conf` ,这里我们主要修改两个参数:`priority_networks` 及 `meta_dir` ,如果你需要更多优化配置,请参考 [FE 参数配置](../admin-manual/config/fe-config.md)说明,进行调整。
修改 FE 配置文件 `conf/fe.conf` ,这里我们主要修改两个参数:`priority_networks` 或 `network_interfaces` 及 `meta_dir` ,如果你需要更多优化配置,请参考 [FE 参数配置](../admin-manual/config/fe-config)说明,进行调整。

1. 添加 priority_networks 参数

```
priority_networks=172.23.16.0/24
```

2. 添加 network_interfaces 参数

```
network_interfaces=eth0
```

>注意:
>
>这个参数我们在安装的时候是必须要配置的,特别是当一台机器拥有多个IP地址的时候,我们要为 FE 指定唯一的IP地址。
>这两个参数我们在安装的时候必须至少配置其中一个(`network_interfaces` 优先级高于 `priority_networks`),特别是当一台机器拥有多个IP地址的时候,我们要为 FE 指定唯一的IP地址。

> 这里假设你的节点 IP 是 `172.23.16.32`,那么我们可以通过掩码的方式配置为 `172.23.16.0/24`。
>这里假设你的节点 IP 是 `172.23.16.32`,那么我们可以通过掩码的方式配置为 `172.23.16.0/24`。
>假设配置完正确的 `network_interfaces`,那么我们配置后会优先使用 `network_interfaces` 的配置,而不是选择 `priority_networks`,尽管你已经配置了。

2. 添加元数据目录
3. 添加元数据目录

```
meta_dir=/path/your/doris-meta
Expand Down Expand Up @@ -179,19 +186,25 @@ Doris FE 的停止可以通过下面的命令完成
cd apache-doris-x.x.x/be
```

修改 BE 配置文件 `conf/be.conf` ,这里我们主要修改两个参数:`priority_networks` 及 `storage_root` ,如果你需要更多优化配置,请参考 [BE 参数配置](../admin-manual/config/be-config.md)说明,进行调整。
修改 BE 配置文件 `conf/be.conf` ,这里我们主要修改两个参数:`priority_networks` 或 `network_interfaces` 及 `storage_root` ,如果你需要更多优化配置,请参考 [BE 参数配置](../admin-manual/config/be-config)说明,进行调整。

1. 添加 priority_networks 参数

```
priority_networks=172.23.16.0/24
```

>注意:
2. 添加 network_interfaces 参数

```
network_interfaces=eth0
```

>注意:
>
>这个参数我们在安装的时候是必须要配置的,特别是当一台机器拥有多个IP地址的时候,我们要为 BE 指定唯一的IP地址。
>这两个参数我们在安装的时候必须至少配置其中一个(`network_interfaces` 优先级高于 `priority_networks`),特别是当一台机器拥有多个IP地址的时候,我们要为 BE 指定唯一的IP地址。

2. 配置 BE 数据存储目录
3. 配置 BE 数据存储目录


```
Expand Down
11 changes: 8 additions & 3 deletions docs/zh-CN/docs/install/install-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,20 @@ Doris 各个实例直接通过网络进行通讯。以下表格展示了所有

#### IP 绑定

因为有多网卡的存在,或因为安装过 docker 等环境导致的虚拟网卡的存在,同一个主机可能存在多个不同的 ip。当前 Doris 并不能自动识别可用 IP。所以当遇到部署主机上有多个 IP 时,必须通过 priority\_networks 配置项来强制指定正确的 IP。
因为有多网卡的存在,或因为安装过 docker 等环境导致的虚拟网卡的存在,同一个主机可能存在多个不同的 ip。当前 Doris 并不能自动识别可用 IP。所以当遇到部署主机上有多个 IP 时,必须通过 priority\_networks 或 network\_interfaces (注意 network\_interfaces 优先于 priority\_networks) 配置项来强制指定正确的 IP。

priority\_networks 是 FE 和 BE 都有的一个配置,配置项需写在 fe.conf 和 be.conf 中。该配置项用于在 FE 或 BE 启动时,告诉进程应该绑定哪个IP。示例如下:
priority\_networks 跟 network\_interfaces 是 FE 和 BE 都有的一个配置,配置项需写在 fe.conf 和 be.conf 中。该配置项用于在 FE 或 BE 启动时,告诉进程应该绑定哪个IP。示例如下:

`priority_networks=10.1.3.0/24`

这是一种 [CIDR](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) 的表示方法。FE 或 BE 会根据这个配置项来寻找匹配的IP,作为自己的 localIP。

**注意**:当配置完 priority\_networks 并启动 FE 或 BE 后,只是保证了 FE 或 BE 自身的 IP 进行了正确的绑定。而在使用 ADD BACKEND 或 ADD FRONTEND 语句中,也需要指定和 priority\_networks 配置匹配的 IP,否则集群无法建立。举例:
`network_interfaces=eth0`

这里使用网卡名的表示方法。FE或BE会优先根据这个配置项来寻找匹配的IP,作为自己的 localIP,如果该配置项没有匹配到IP,才会执行 priority\_networks 配置项。


**注意**:当配置完 priority\_networks 或 network\_interfaces 并启动 FE 或 BE 后,只是保证了 FE 或 BE 自身的 IP 进行了正确的绑定。而在使用 ADD BACKEND 或 ADD FRONTEND 语句中,也需要指定和 priority\_networks 或 network\_interfaces 配置匹配的 IP,否则集群无法建立。举例:

BE 的配置为:`priority_networks=10.1.3.0/24`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ public class Config extends ConfigBase {
*/
@ConfField public static String priority_networks = "";

@ConfField public static String network_interfaces = "";

/**
* If true, FE will reset bdbje replication group(that is, to remove all electable nodes info)
* and is supposed to start as Master.
Expand Down
Loading