本文介紹RDS Custom網路預設配置,以及如何配置自訂鏡像的網路初始化。
RDS Custom網路簡介
RDS Custom執行個體(雙網卡模式)預設配置了兩塊網卡,一塊主網卡(通常命名為eth0),另一塊彈性網卡(通常命名為eth1)。
-
eth0:建立於管控VPC下,由於安全性群組的限制,僅允許ECS管控網段100.100.0.0/16的流量通過eth0介面出。
說明100.100.2.136和100.100.2.138是內網DNS IP地址,需通過eth1進出。
-
eth1:建立於使用者VPC網路下,正常情況下,除ECS管控網段外,所有流量均通過eth1進出,使用者通過安全性群組管理進出流量。
正常情況下,串連RDS Custom執行個體後,其網卡、路由表和iptables防火牆規則如下:
-
執行
ip address show命令,查看執行個體網卡狀態。1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:16:3e:10:32:d8 brd ff:ff:ff:ff:ff:ff inet 20.xxx.xxx.xxx/16 brd 20.xxx.xxx.xxx scope global dynamic eth0 valid_lft 315357595sec preferred_lft 315357595sec inet6 fe80::xxx:xxx:xxx:xxx/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:16:3e:48:f2:e7 brd ff:ff:ff:ff:ff:ff inet 172.xxx.xxx.xxx/20 brd 172.xxx.xxx.xxx scope global dynamic eth1 valid_lft 315357597sec preferred_lft 315357597sec inet6 fe80::xxx:xxx:xxx:xxx/64 scope link valid_lft forever preferred_lft forever -
執行
route -n命令,查看執行個體路由表。流量僅通過eth1網卡進行傳輸。
Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 172.xxx.xxx.xxx 0.0.0.0 UG 0 0 0 eth1 100.100.0.0 20.xxx.xxx.xxx 255.255.0.0 UG 0 0 0 eth0 100.100.2.136 172.xxx.xxx.xxx 255.255.255.255 UGH 0 0 0 eth1 100.100.2.138 172.xxx.xxx.xxx 255.255.255.255 UGH 0 0 0 eth1 169.xxx.xxx.xxx 0.0.0.0 255.255.0.0 U 1003 0 0 eth1 172.xxx.xxx.xxx 0.0.0.0 255.255.240.0 U 0 0 0 eth1 -
執行
iptables -L -n命令,查看執行個體iptables預設配置。Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination
如果您對RDS Custom執行個體路由表、iptables防火牆規則及網卡配置(包括重啟eth0)等進行了操作,導致無法串連到RDS Custom執行個體,您可以通過重啟執行個體來初始化RDS Custom網路。
RDS Custom執行個體通過/etc/rds_custom_init.sh指令碼進行網路初始化,請勿刪除該指令碼,以免導致無法進行初始化。
配置自訂鏡像的網路初始化
通過自訂鏡像建立RDS Custom執行個體時,對於大多數的公用鏡像,RDS Custom會自動設定/etc/rds_custom_init.sh指令碼,實現網路初始化。目前支援的鏡像包括Alibaba Cloud Linux 3、Alibaba Cloud Linux 2、CentOS 8、CentOS 7、Debian 11、Debian 10.5、AlmaLinux 9.2、Ubuntu 22、Ubuntu 20和Ubuntu 16。如需使用其他自訂鏡像,在建立自訂鏡像前,需要在原鏡像執行個體中手動建立rds_custom_init.sh指令碼。
rds_custom_init.sh指令碼的主要功能是:
-
針對無法自動啟用彈性網卡的系統,執行eth1的網路設定,並啟動相關服務。
-
修改路由配置,將預設路由指向eth1,並將ECS管控網段100.100.0.0/16指向eth0。
-
修改路由配置,將內網DNS IP地址100.100.2.136和100.100.2.138指向eth1。
啟動RDS Custom執行個體時,系統會將eth0的網關記錄在/etc/eth0_gateway,並對大多數的公用鏡像自動設定/etc/rds_custom_init.sh指令碼。如果您計劃對RDS Custom執行個體進行網路相關的初始化,請確保在網路初始化完成後,手動執行/etc/rds_custom_init.sh指令碼。如果發現eth1無法服務(例如IP地址未被識別),請聯絡我們,或對網路進行配置,以確保eth1正常運行。
手動建立指令碼並設定開機自啟動
-
在/etc目錄下建立
rds_custom_init.sh指令碼,指令碼的具體內容如下。 -
執行
chmod a+x /etc/rds_custom_init.sh為該指令碼授予可執行許可權。 -
編輯
/etc/rc.local,將rds_custom_init.sh指令碼配置為開機自啟動。-
若系統非Ubuntu,請在
/etc/rc.local中增加/etc/rds_custom_init.sh,並為/etc/rc.local授予相應許可權。chmod 777 /etc/rc.local -
若系統為Ubuntu,請配置並開啟
rc-local.service服務。-
編輯
/lib/systemd/system/rc-local.service,增加如下內容。[Install] WantedBy=multi-user.target -
將
rc-local.service服務配置為開機自啟動。#設定為開機自啟動服務 systemctl enable rc-local.service #檢查開機自啟動服務 systemctl is-enabled rc-local.service -
啟動
rc-local.service服務。#啟動服務 systemctl start rc-local.service #檢查服務 systemctl status rc-local.service
說明Ubuntu20.04、22.04和24.04預設支援自動設定綁定的輔助彈性網卡。如自動設定未能成功,請執行以下手動設定步驟。
-
-