1、 背景
機器遷移到雲端,使用機器名方式統一命名規範,更加易於集羣管理、運維管理工作。往往根據機器可以得知,機器所屬地區、部門、業務、集羣等信息,有利於記憶辨認。網絡上還是以IP地址形式通信,統一命名規範要求機器名與網絡地址映射支持。
早期使用本機hosts進行機器名解析,主機不斷增多時,hosts文件管理變得複雜,解析性能也在下降;使用第三方域名服務,方便快捷不在需要調研開發等工作,只是處理問題變得繁瑣,域名信息暴露給第三方,存在安全信息泄漏等隱患;如果機器數量達到成千上萬級別,可以考慮自建DNS服務集羣。
bind域名服務支持各種測試工具,包括壓測工具。服務端要求與客戶端時間保持一致性,大量配置文件也增加了使用難度,對高可用集羣支持性不好。skydns+etcd方式,從成功項目摘出來的模塊。配置簡單,服務穩定。支持高可用集羣,靈活性高,這樣也導致etcd集羣配置管理變得過於複雜。
2、 調研目的與結果
l Dns服務集羣結構
基於skydns與etcd配合的Dns模型,skydns負責域名解析,etcd集羣保存域名記錄,skydns與etcd出自同一個項目,兩者之間有良好的配合接口。
l Dns服務集羣高可用性
搭建skydns域名解析集羣,提供域名解析服務負載均衡功能;內部搭建etcd集羣,爲skydns提供域名解析記錄服務;每一個skydns可以訪問多個etcd服務器獲取域名記錄,同集羣的etcd數據一致性同步。
l Dns服務集羣穩定性
經過測試,skydns服務長期穩定運行,可以支撐大量域名請求涌入;etcd集羣數據同步到全部節點,穩定的集羣管理協議,leader與節點出現故障對集羣正常工作沒有影響。
l DnS服務數據一致性
etcd集羣擴縮容對數據一致性沒有影響;etcd集羣中故障節點恢複對數據一致性沒有影響;etcd集羣peers同步協議,維護集羣數據一致性。
l Dns服務集羣靈活性
etcd集羣擴縮容靈活性高,可以跨機房或者多機房部署etcd集羣,集羣節點數據一致性同步;skydns同機房部署集羣,統一管理機器就近訪問dns服務。
l Dns服務集羣管理
主要是etcd集羣管理,集羣創建、集羣擴縮容等
l Dns服務域名解析性能
正常情況下,可以支撐成千上萬級別機器域名服務功能。
3、 網絡拓撲圖
客戶端發送dns域名解析請求到skydns負載服務器,負載服務器把請求代理到各個skydns子節點。skydns接受域名解析請求,使用接口到etcd集羣查詢域名記錄,把域名解析請求結果返回到客戶端。
域名記錄存儲服務集羣(etcd集羣),下面可以部署多臺etcd服務器。分別對應同機房部署、跨機房部署、多機房部署幾種方式。多機房部署優勢,把數據信息同步到不同機房,各臺機器上面。不同機房搭建不同skydns服務集羣,使用相同etcd集羣保存的域名記錄信息,也就保證了不同skydns域名解析記錄一致性同步。不同機房搭建不同skydns服務原因是:同機房訪問節省了跨機房網絡訪問時間。etcd跨機房集羣對網絡響應時間並不高,保證數據一致性同步即可。
4、 服務性能分析
高可用、穩定性、靈活性、數據一致性、成千上萬級別域名解析;
etcd集羣管理複雜性,需要後期調研解決該問題;
壓測性能詳細數據分析參考壓測文檔;
5、 etcd集羣管理
l 創建
A、靜態創建:
需要提前使用IP構成集羣創建,在需要加入依次執行下面命令,ip1、ip2、ip3換成真是ip地址。具體命令:
./etcd -name infra0 -initial-advertise-peer-urls http://ip1:2380 -listen-client-urls http://0.0.0.0:4001 -advertise-client-urls http://0.0.0.0:4001 -listen-peer-urls http://ip1:2380 -data-dir '/root/dns/my.etcd' -initial-cluster-token etcd-cluster-1 -initial-cluster infra0=http://ip1:2380,infra1=http://ip2:2380,infra2=http://ip3:2380 -initial-cluster-state new
|
./etcd -name infra1 -initial-advertise-peer-urls http://ip2:2380 -listen-client-urls http://0.0.0.0:4001 -advertise-client-urls http://0.0.0.0:4001 -listen-peer-urls http://ip2:2380 -data-dir '/root/dns/my.etcd' -initial-cluster-token etcd-cluster-1 -initial-cluster infra0=http://ip1:2380,infra1=http://ip2:2380,infra2=http://ip3:2380 -initial-cluster-state new
|
./etcd -name infra2 -initial-advertise-peer-urls http://ip3:2380 -listen-client-urls http://0.0.0.0:4001 -advertise-client-urls http://0.0.0.0:4001 -listen-peer-urls http://ip3:2380 -data-dir '/root/dns/my.etcd' -initial-cluster-token etcd-cluster-1 -initial-cluster infra0=http://ip1:2380,infra1=http://ip2:2380,infra2=http://ip3:2380 -initial-cluster-state new
|
其中參數含義:
-initial-cluster-token etcd-cluster-1創建集羣名稱
-data-dir '/root/dns/my.etcd' etcd數據保存目錄,創建新集羣使用新目錄
-initial-advertise-peer-urls 集羣使用同步,地址:端口形式
-advertise-client-urls 集羣使用客戶端,地址:端口形式
-listen-peer-urls 用戶使用同步,地址:端口形式
-listen-client-urls 用戶使用客戶端,地址:端口形式
B、動態創建:
需要在一個已經存在的集羣,創建新集羣的key,把key寫入到etcd數據庫同時,設置新集羣容量,新集羣節點加入集羣URL等。各個節點使用動態發現集羣方式,帶上URl參數,加入新集羣。等待其他節點完全加入新集羣,集羣真正創建成功。具體命令如下:
創建一個token服務器或者集羣:
./etcd -name infra0 -initial-advertise-peer-urls http://tokenip:2380 -listen-client-urls http://0.0.0.0:4001 -advertise-client-urls http://0.0.0.0:4001 -listen-peer-urls http:// tokenip:2380 -data-dir '/root/dns/keys.etcd' -initial-cluster-token etcd-cluster-1 -initial-cluster infra0=http:// tokenip:2380 -initial-cluster-state new |
在token服務器生產key
uuidgen |
設置token。使token生效,其他etcd使用discovery協議,加入token對應集羣。
curl -X PUT http:// tokenip:4001/v2/keys/_etcd/registry/90b885c6-9cb1-46e3-b044-82b75d67e0ae/_config/size -d value=3
|
其他節點加入動態集羣:
./etcd -name infra1 -initial-advertise-peer-urls http://ip1:2380 -listen-client-urls http://0.0.0.0:4001 -advertise-client-urls http://0.0.0.0:4001 -listen-peer-urls http://ip1:2380 -data-dir '/root/dns/dhcp.etcd' -discovery http:// tokenip:4001/v2/keys/_etcd/registry/90b885c6-9cb1-46e3-b044-82b75d67e0ae
|
./etcd -name infra2 -initial-advertise-peer-urls http://ip2:2380 -listen-client-urls http://0.0.0.0:4001 -advertise-client-urls http://0.0.0.0:4001 -listen-peer-urls http://ip2:2380 -data-dir '/root/dns/dhcp.etcd' -discovery http:// tokenip:4001/v2/keys/_etcd/registry/90b885c6-9cb1-46e3-b044-82b75d67e0ae
|
./etcd -name infra3 -initial-advertise-peer-urls http://ip3:2380 -listen-client-urls http://0.0.0.0:4001 -advertise-client-urls http://0.0.0.0:4001 -listen-peer-urls http://ip3:2380 -data-dir '/root/dns/dhcp.etcd' -discovery http:// tokenip:4001/v2/keys/_etcd/registry/90b885c6-9cb1-46e3-b044-82b75d67e0ae
|
爲了保證集羣穩定性、數據一致性維護,token服務器需要長期存在。
l 擴縮容
A、添加一個節點:集羣中需要同步新添加節點信息,新加節點加入集羣。
集羣中任意節點同步新加節點信息:
./etcdctl member add infra3 http://ip4:2380 |
新節點加入集羣:
./etcd -name infra4 -initial-advertise-peer-urls http://ip4:2380 -listen-client-urls http://0.0.0.0:4001 -advertise-client-urls http://0.0.0.0:4001 -listen-peer-urls http://ip4:2380 -data-dir '/root/dns/1q.etcd' -initial-cluster-token etcd-cluster-1 -initial-cluster infra0=http://ip0:2380,infra1=http:// ip1:2380,infra2=http:// ip2:2380,infra3=http:// ip3:2380, infra3=http://ip4:2380 -initial-cluster-state existing |
B、刪除一個節點:集羣中同步刪除節點信息即可
etcdctl member remove a8266ecf031671f3 |
a8266ecf031671f3 是被刪除節點ID
l 數據穩定性驗證
A、集羣停止各個節點,各個節點再次重啓,數據依然存在;
B、集羣刪除各個節點,再次添加各個節點,數據已經不存在;
C、關閉leader情況:
其他節點選舉新leader;
重啓前leader會以普通節點角色正常運行;
下一次leader選舉時,前leader仍然參加leader選舉;
D、關閉任意節點情況:
其他節點繼續正常工作;
重啓後該節點正常加入集羣;
重啓節點前插入數據,該節點重啓後會同步數據;
該節點重啓後同步集羣數據;
l 數據一致性驗證
節點加入集羣同步集羣原有數據;
節點加入集羣插入數據會同步到新節點;
刪除節點原有數據,新節點同步刪除
新插入數據,新節點同步更新;
l 不同集羣間數據遷移
使用數據備份與恢復的方式遷移,目前,在A集羣備份數據,B集羣以備份數據新建集羣,啓動成功。存在問題,備份數據配置信息校驗,導致新建集羣節點服務IP地址不可設置情況,節點強制以localhost啓動。
6、 域名服務監控
l sykdns監控:
監聽skydns端口;
監聽skydns功能:使用dig命令方式,探測skydns健康狀態;
l etcd監控
提供集羣健康狀態詢問接口:
./etcdctl cluster-health |
l 趨勢圖與報警
把skydns、etcd監控信息發送到監控平臺,生成趨勢圖,配合相應規則,出現異常時觸發報警。