国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁(yè) > news >正文

重慶高端網(wǎng)站開(kāi)發(fā)百度精準(zhǔn)獲客平臺(tái)

重慶高端網(wǎng)站開(kāi)發(fā),百度精準(zhǔn)獲客平臺(tái),湘潭建設(shè)網(wǎng)站的公司,做外貿(mào)主要看什么網(wǎng)站作者主頁(yè): 正函數(shù)的個(gè)人主頁(yè) 文章收錄專(zhuān)欄: Docker 歡迎大家點(diǎn)贊 👍 收藏 ? 加關(guān)注哦! etcd etcd 是 CoreOS 團(tuán)隊(duì)發(fā)起的一個(gè)管理配置信息和服務(wù)發(fā)現(xiàn)(Service Discovery)的項(xiàng)目,在這一章里面&a…

在這里插入圖片描述

作者主頁(yè): 正函數(shù)的個(gè)人主頁(yè)
文章收錄專(zhuān)欄: Docker
歡迎大家點(diǎn)贊 👍 收藏 ? 加關(guān)注哦!


etcd

etcdCoreOS 團(tuán)隊(duì)發(fā)起的一個(gè)管理配置信息和服務(wù)發(fā)現(xiàn)(Service Discovery)的項(xiàng)目,在這一章里面,我們將基于 etcd 3.x 版本介紹該項(xiàng)目的目標(biāo),安裝和使用,以及實(shí)現(xiàn)的技術(shù)。


一、簡(jiǎn)介:什么是 etcd

在這里插入圖片描述

etcdCoreOS 團(tuán)隊(duì)于 2013 年 6 月發(fā)起的開(kāi)源項(xiàng)目,它的目標(biāo)是構(gòu)建一個(gè)高可用的分布式鍵值(key-value)數(shù)據(jù)庫(kù),基于 Go 語(yǔ)言實(shí)現(xiàn)。我們知道,在分布式系統(tǒng)中,各種服務(wù)的配置信息的管理分享,服務(wù)的發(fā)現(xiàn)是一個(gè)很基本同時(shí)也是很重要的問(wèn)題。CoreOS 項(xiàng)目就希望基于 etcd 來(lái)解決這一問(wèn)題。

etcd 目前在 github.com/etcd-io/etcd 進(jìn)行維護(hù)。

受到 Apache ZooKeeper 項(xiàng)目和 doozer 項(xiàng)目的啟發(fā),etcd 在設(shè)計(jì)的時(shí)候重點(diǎn)考慮了下面四個(gè)要素:

  • 簡(jiǎn)單:具有定義良好、面向用戶的 API (gRPC)

  • 安全:支持 HTTPS 方式的訪問(wèn)

  • 快速:支持并發(fā) 10 k/s 的寫(xiě)操作

  • 可靠:支持分布式結(jié)構(gòu),基于 Raft 的一致性算法

Apache ZooKeeper 是一套知名的分布式系統(tǒng)中進(jìn)行同步和一致性管理的工具。

doozer 是一個(gè)一致性分布式數(shù)據(jù)庫(kù)。

Raft 是一套通過(guò)選舉主節(jié)點(diǎn)來(lái)實(shí)現(xiàn)分布式系統(tǒng)一致性的算法,相比于大名鼎鼎的 Paxos 算法,它的過(guò)程更容易被人理解,由 Stanford 大學(xué)的 Diego Ongaro 和 John Ousterhout 提出。更多細(xì)節(jié)可以參考 raftconsensus.github.io。

一般情況下,用戶使用 etcd 可以在多個(gè)節(jié)點(diǎn)上啟動(dòng)多個(gè)實(shí)例,并添加它們?yōu)橐粋€(gè)集群。同一個(gè)集群中的 etcd 實(shí)例將會(huì)保持彼此信息的一致性。


二、安裝

etcd 基于 Go 語(yǔ)言實(shí)現(xiàn),因此,用戶可以從 項(xiàng)目主頁(yè) 下載源代碼自行編譯,也可以下載編譯好的二進(jìn)制文件,甚至直接使用制作好的 Docker 鏡像文件來(lái)體驗(yàn)。

注意:本章節(jié)內(nèi)容基于 etcd 3.4.x 版本

二進(jìn)制文件方式下載

編譯好的二進(jìn)制文件都在 github.com/etcd-io/etcd/releases 頁(yè)面,用戶可以選擇需要的版本,或通過(guò)下載工具下載。

例如,使用 curl 工具下載壓縮包,并解壓。

$ curl -L https://github.com/etcd-io/etcd/releases/download/v3.4.0/etcd-v3.4.0-linux-amd64.tar.gz -o etcd-v3.4.0-linux-amd64.tar.gz# 國(guó)內(nèi)用戶可以使用以下方式加快下載
$ curl -L https://download.fastgit.org/etcd-io/etcd/releases/download/v3.4.0/etcd-v3.4.0-linux-amd64.tar.gz -o etcd-v3.4.0-linux-amd64.tar.gz$ tar xzvf etcd-v3.4.0-linux-amd64.tar.gz
$ cd etcd-v3.4.0-linux-amd64

解壓后,可以看到文件包括

$ ls
Documentation README-etcdctl.md README.md READMEv2-etcdctl.md etcd etcdctl

其中 etcd 是服務(wù)主文件,etcdctl 是提供給用戶的命令客戶端,其他文件是支持文檔。

下面將 etcd etcdctl 文件放到系統(tǒng)可執(zhí)行目錄(例如 /usr/local/bin/)。

$ sudo cp etcd* /usr/local/bin/

默認(rèn) 2379 端口處理客戶端的請(qǐng)求,2380 端口用于集群各成員間的通信。啟動(dòng) etcd 顯示類(lèi)似如下的信息:

$ etcd
...
2017-12-03 11:18:34.411579 I | embed: listening for peers on http://localhost:2380
2017-12-03 11:18:34.411938 I | embed: listening for client requests on localhost:2379

此時(shí),可以使用 etcdctl 命令進(jìn)行測(cè)試,設(shè)置和獲取鍵值 testkey: "hello world",檢查 etcd 服務(wù)是否啟動(dòng)成功:

$ ETCDCTL_API=3 etcdctl member list
8e9e05c52164694d, started, default, http://localhost:2380, http://localhost:2379$ ETCDCTL_API=3 etcdctl put testkey "hello world"
OK$ etcdctl get testkey
testkey
hello world

說(shuō)明 etcd 服務(wù)已經(jīng)成功啟動(dòng)了。

Docker 鏡像方式運(yùn)行

鏡像名稱(chēng)為 quay.io/coreos/etcd,可以通過(guò)下面的命令啟動(dòng) etcd 服務(wù)監(jiān)聽(tīng)到 23792380 端口。

$ docker run \
-p 2379:2379 \
-p 2380:2380 \
--mount type=bind,source=/tmp/etcd-data.tmp,destination=/etcd-data \
--name etcd-gcr-v3.4.0 \
quay.io/coreos/etcd:v3.4.0 \
/usr/local/bin/etcd \
--name s1 \
--data-dir /etcd-data \
--listen-client-urls http://0.0.0.0:2379 \
--advertise-client-urls http://0.0.0.0:2379 \
--listen-peer-urls http://0.0.0.0:2380 \
--initial-advertise-peer-urls http://0.0.0.0:2380 \
--initial-cluster s1=http://0.0.0.0:2380 \
--initial-cluster-token tkn \
--initial-cluster-state new \
--log-level info \
--logger zap \
--log-outputs stderr

打開(kāi)新的終端按照上一步的方法測(cè)試 etcd 是否成功啟動(dòng)。

macOS 中運(yùn)行

$ brew install etcd$ etcd$ etcdctl member list

三、etcd 集群

下面我們使用 Docker Compose 模擬啟動(dòng)一個(gè) 3 節(jié)點(diǎn)的 etcd 集群。

編輯 docker-compose.yml 文件

version: "3.6"
services:node1:image: quay.io/coreos/etcd:v3.4.0volumes:- node1-data:/etcd-dataexpose:- 2379- 2380networks:cluster_net:ipv4_address: 172.16.238.100environment:- ETCDCTL_API=3command:- /usr/local/bin/etcd- --data-dir=/etcd-data- --name- node1- --initial-advertise-peer-urls- http://172.16.238.100:2380- --listen-peer-urls- http://0.0.0.0:2380- --advertise-client-urls- http://172.16.238.100:2379- --listen-client-urls- http://0.0.0.0:2379- --initial-cluster- node1=http://172.16.238.100:2380,node2=http://172.16.238.101:2380,node3=http://172.16.238.102:2380- --initial-cluster-state- new- --initial-cluster-token- docker-etcdnode2:image: quay.io/coreos/etcd:v3.4.0volumes:- node2-data:/etcd-datanetworks:cluster_net:ipv4_address: 172.16.238.101environment:- ETCDCTL_API=3expose:- 2379- 2380command:- /usr/local/bin/etcd- --data-dir=/etcd-data- --name- node2- --initial-advertise-peer-urls- http://172.16.238.101:2380- --listen-peer-urls- http://0.0.0.0:2380- --advertise-client-urls- http://172.16.238.101:2379- --listen-client-urls- http://0.0.0.0:2379- --initial-cluster- node1=http://172.16.238.100:2380,node2=http://172.16.238.101:2380,node3=http://172.16.238.102:2380- --initial-cluster-state- new- --initial-cluster-token- docker-etcdnode3:image: quay.io/coreos/etcd:v3.4.0volumes:- node3-data:/etcd-datanetworks:cluster_net:ipv4_address: 172.16.238.102environment:- ETCDCTL_API=3expose:- 2379- 2380command:- /usr/local/bin/etcd- --data-dir=/etcd-data- --name- node3- --initial-advertise-peer-urls- http://172.16.238.102:2380- --listen-peer-urls- http://0.0.0.0:2380- --advertise-client-urls- http://172.16.238.102:2379- --listen-client-urls- http://0.0.0.0:2379- --initial-cluster- node1=http://172.16.238.100:2380,node2=http://172.16.238.101:2380,node3=http://172.16.238.102:2380- --initial-cluster-state- new- --initial-cluster-token- docker-etcdvolumes:node1-data:node2-data:node3-data:networks:cluster_net:driver: bridgeipam:driver: defaultconfig:-subnet: 172.16.238.0/24

使用 docker-compose up 啟動(dòng)集群之后使用 docker exec 命令登錄到任一節(jié)點(diǎn)測(cè)試 etcd 集群。

/ # etcdctl member list
daf3fd52e3583ff, started, node3, http://172.16.238.102:2380, http://172.16.238.102:2379
422a74f03b622fef, started, node1, http://172.16.238.100:2380, http://172.16.238.100:2379
ed635d2a2dbef43d, started, node2, http://172.16.238.101:2380, http://172.16.238.101:2379

四、使用 etcdctl

etcdctl 是一個(gè)命令行客戶端,它能提供一些簡(jiǎn)潔的命令,供用戶直接跟 etcd 服務(wù)打交道,而無(wú)需基于 HTTP API 方式。這在某些情況下將很方便,例如用戶對(duì)服務(wù)進(jìn)行測(cè)試或者手動(dòng)修改數(shù)據(jù)庫(kù)內(nèi)容。我們也推薦在剛接觸 etcd 時(shí)通過(guò) etcdctl 命令來(lái)熟悉相關(guān)的操作,這些操作跟 HTTP API 實(shí)際上是對(duì)應(yīng)的。

etcd 項(xiàng)目二進(jìn)制發(fā)行包中已經(jīng)包含了 etcdctl 工具,沒(méi)有的話,可以從 github.com/etcd-io/etcd/releases 下載。

etcdctl 支持如下的命令,大體上分為數(shù)據(jù)庫(kù)操作和非數(shù)據(jù)庫(kù)操作兩類(lèi),后面將分別進(jìn)行解釋。

NAME:etcdctl - A simple command line client for etcd3.USAGE:etcdctlVERSION:3.4.0API VERSION:3.4COMMANDS:get			Gets the key or a range of keysput			Puts the given key into the storedel			Removes the specified key or range of keys [key, range_end)txn			Txn processes all the requests in one transactioncompaction		Compacts the event history in etcdalarm disarm		Disarms all alarmsalarm list		Lists all alarmsdefrag			Defragments the storage of the etcd members with given endpointsendpoint health		Checks the healthiness of endpoints specified in `--endpoints` flagendpoint status		Prints out the status of endpoints specified in `--endpoints` flagwatch			Watches events stream on keys or prefixesversion			Prints the version of etcdctllease grant		Creates leaseslease revoke		Revokes leaseslease timetolive	Get lease informationlease keep-alive	Keeps leases alive (renew)member add		Adds a member into the clustermember remove		Removes a member from the clustermember update		Updates a member in the clustermember list		Lists all members in the clustersnapshot save		Stores an etcd node backend snapshot to a given filesnapshot restore	Restores an etcd member snapshot to an etcd directorysnapshot status		Gets backend snapshot status of a given filemake-mirror		Makes a mirror at the destination etcd clustermigrate			Migrates keys in a v2 store to a mvcc storelock			Acquires a named lockelect			Observes and participates in leader electionauth enable		Enables authenticationauth disable		Disables authenticationuser add		Adds a new useruser delete		Deletes a useruser get		Gets detailed information of a useruser list		Lists all usersuser passwd		Changes password of useruser grant-role		Grants a role to a useruser revoke-role	Revokes a role from a userrole add		Adds a new rolerole delete		Deletes a rolerole get		Gets detailed information of a rolerole list		Lists all rolesrole grant-permission	Grants a key to a rolerole revoke-permission	Revokes a key from a rolecheck perf		Check the performance of the etcd clusterhelp			Help about any commandOPTIONS:--cacert=""				verify certificates of TLS-enabled secure servers using this CA bundle--cert=""					identify secure client using this TLS certificate file--command-timeout=5s			timeout for short running command (excluding dial timeout)--debug[=false]				enable client-side debug logging--dial-timeout=2s				dial timeout for client connections--endpoints=[127.0.0.1:2379]		gRPC endpoints--hex[=false]				print byte strings as hex encoded strings--insecure-skip-tls-verify[=false]	skip server certificate verification--insecure-transport[=true]		disable transport security for client connections--key=""					identify secure client using this TLS key file--user=""					username[:password] for authentication (prompt if password is not supplied)-w, --write-out="simple"			set the output format (fields, json, protobuf, simple, table)

數(shù)據(jù)庫(kù)操作

數(shù)據(jù)庫(kù)操作圍繞對(duì)鍵值和目錄的 CRUD (符合 REST 風(fēng)格的一套操作:Create)完整生命周期的管理。

etcd 在鍵的組織上采用了層次化的空間結(jié)構(gòu)(類(lèi)似于文件系統(tǒng)中目錄的概念),用戶指定的鍵可以為單獨(dú)的名字,如 testkey,此時(shí)實(shí)際上放在根目錄 / 下面,也可以為指定目錄結(jié)構(gòu),如 cluster1/node2/testkey,則將創(chuàng)建相應(yīng)的目錄結(jié)構(gòu)。

注:CRUD 即 Create, Read, Update, Delete,是符合 REST 風(fēng)格的一套 API 操作。

put

$ etcdctl put /testdir/testkey "Hello world"
OK

get

獲取指定鍵的值。例如

$ etcdctl put testkey hello
OK
$ etcdctl get testkey
testkey
hello

支持的選項(xiàng)為

--sort 對(duì)結(jié)果進(jìn)行排序

--consistent 將請(qǐng)求發(fā)給主節(jié)點(diǎn),保證獲取內(nèi)容的一致性

del

刪除某個(gè)鍵值。例如

$ etcdctl del testkey
1

非數(shù)據(jù)庫(kù)操作

watch

監(jiān)測(cè)一個(gè)鍵值的變化,一旦鍵值發(fā)生更新,就會(huì)輸出最新的值。

例如,用戶更新 testkey 鍵值為 Hello world。

$ etcdctl watch testkey
PUT
testkey
2

member

通過(guò) listadd、update、remove 命令列出、添加、更新、刪除 etcd 實(shí)例到 etcd 集群中。

例如本地啟動(dòng)一個(gè) etcd 服務(wù)實(shí)例后,可以用如下命令進(jìn)行查看。

$ etcdctl member list
422a74f03b622fef, started, node1, http://172.16.238.100:2380, http://172.16.238.100:23

作者主頁(yè): 正函數(shù)的個(gè)人主頁(yè)
文章收錄專(zhuān)欄: Docker
在這里插入圖片描述

在這里插入圖片描述

歡迎大家點(diǎn)贊 👍 收藏 ? 加關(guān)注哦!
如果你認(rèn)為這篇文章對(duì)你有幫助,請(qǐng)給正函數(shù)點(diǎn)個(gè)贊吧,如果發(fā)現(xiàn)什么問(wèn)題,歡迎評(píng)論區(qū)留言!!

http://aloenet.com.cn/news/45630.html

相關(guān)文章:

  • 網(wǎng)站開(kāi)發(fā)技術(shù)路線百度競(jìng)價(jià)冷門(mén)產(chǎn)品
  • 潮州網(wǎng)站開(kāi)發(fā)黃頁(yè)推廣2021
  • perl網(wǎng)站開(kāi)發(fā)西安網(wǎng)站搭建
  • wordpress訪客明細(xì)win7優(yōu)化大師官方網(wǎng)站
  • 人才招聘網(wǎng)站模板網(wǎng)站推廣的營(yíng)銷(xiāo)策劃方案
  • 網(wǎng)站建設(shè)的項(xiàng)目描述品牌推廣思路
  • 做標(biāo)簽網(wǎng)站杭州百度優(yōu)化
  • 城鄉(xiāng)住建局官網(wǎng)北京seo優(yōu)化廠家
  • 可以做熱圖的工具網(wǎng)站百度網(wǎng)盤(pán)搜索
  • 百度上做網(wǎng)站需要錢(qián)嗎百色seo關(guān)鍵詞優(yōu)化公司
  • 做秒殺網(wǎng)站南昌seo教程
  • b2b網(wǎng)站介紹友情鏈接是什么意思
  • 廈門(mén)網(wǎng)站建設(shè)合同網(wǎng)店推廣方法
  • 網(wǎng)站設(shè)計(jì)公司石家莊google關(guān)鍵詞分析工具
  • 安丘做網(wǎng)站的公司百度廣告推廣平臺(tái)
  • 電商建站價(jià)格常熟seo網(wǎng)站優(yōu)化軟件
  • 網(wǎng)站建設(shè)與管理方案書(shū)搜索引擎優(yōu)化論文
  • 動(dòng)態(tài)網(wǎng)站開(kāi)發(fā)大賽即刻搜索引擎入口
  • 網(wǎng)站快照歷史廣州網(wǎng)站建設(shè)
  • html制作電影網(wǎng)站百度開(kāi)戶流程
  • 做品牌文化的網(wǎng)站少女長(zhǎng)尾關(guān)鍵詞挖掘
  • 看一個(gè)網(wǎng)站是用什么語(yǔ)言做的麗水網(wǎng)站seo
  • 安陽(yáng)哪里做網(wǎng)站愛(ài)站關(guān)鍵詞搜索
  • 怎么找網(wǎng)站的根目錄自己怎么做網(wǎng)站
  • 更改網(wǎng)站的布局欒城seo整站排名
  • 怎么給幼兒園做網(wǎng)站seo專(zhuān)業(yè)培訓(xùn)機(jī)構(gòu)
  • 用css做網(wǎng)站菜單廣告多的網(wǎng)站
  • 版權(quán)申請(qǐng)網(wǎng)站磁力天堂
  • 網(wǎng)站開(kāi)發(fā)現(xiàn)在主要用什么語(yǔ)言女教師遭網(wǎng)課入侵直播錄屏曝
  • 寧晉網(wǎng)站建設(shè)模板建站公司