跳到主要内容

etcd 安装

单机部署

Mac

ETCD_VER=v3.3.0-rc.2 #这里可以选择任意一个etcd版本
GITHUB_URL=https://github.com/coreos/etcd/releases/download

DOWNLOAD_URL=${GITHUB_URL}

rm -f /tmp/etcd-${ETCD_VER}-darwin-amd64.zip
rm -rf /tmp/etcd-download-test && mkdir -p /tmp/etcd-download-test
curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-darwin-amd64.zip -o /tmp/etcd-${ETCD_VER}-darwin-amd64.zip
unzip /tmp/etcd-${ETCD_VER}-darwin-amd64.zip -d /tmp && rm -f /tmp/e七cd­ ${ETCD_VER}-darwin-amd64.zip
mv /tmp/e七cd-${ETCD_VER}-darwin-amd64/* /tmp/etcd-download-test && rm -rf mv /tmp/etcd-${ETCD_VER}-darwin-amd64


#运行etcd server
/tmp/etcd-download-test/etcd
#检查etcd server版本
/tmp/etcd-download-test/etcd --version
#检查etcd命令行工具版本
ETCDCTL_API=3 /tmp/etcd-downloadtest/etcdctl version

docker 安装

docker run\
-p 2379:2379\
-p 2380:2380\
--mount type=bind,source=/tmp/etcd-data.tmp,destination=/etcd-data\ --name etcd-gcr-v3.3.0-rc.2\ gcr.io/etcd-development/etcd:v3.3.0-rc.2\
/usr/local/bin/etcd\
--name sl\
--da七a-dir /etcd-data\
--listen-client-urls http://0.0.0.0:2379\
一-advertise-client-urls http : / / 0.0.0.0 : 2379 \ --1工sten-peer-urls http://0.0.0.0:2380 \
initial-advertise-peer-urls s http://0.0.0.0:2380 \ --initial-cluster s1=http://0.0.0.0::2380 \ --initial- cluster-token tkn \
--initial-cluster-state new

#检查 etcd server版本
docker exec etcd-gcr-v3.3.0-rc.2 /bin/sh c ”/usr/local/bin/etcd -- version ”


#检查etcd命令行工具版本
docker exec etcd- gcr- v3 . 3 . 0- rc . 2 /bin/ sh
-c
" ETCDCTL
API=3
/usr/local/
bin/etcdctl version "

#通过 etcd命令行检查 etcd每个节点的健康状况
docker exec etcd- gcr- v3.3.0-rc.2 /bin/sh
- c
"ETCDCTL
API=3
/usr/local/
bin/etcdctl endpoint health"

#测试向 etcd读写数据
docker exec etcd-gcr-v3.3.0 rc.2 /bin/sh -c "ETCDCTL API=3 /usr/local/ bin/etcdctl put foo bar”
docker exec etcd-gcr-v3.3.0-rc.2 /bin/sh -c "ETCDCTL API=3 /usr/localI bin/etcdctl get fo”

linux环境

ETCD_VER=v3.3.0-rc.2 
GITHUB_URL=https://github.corn/coreos/etcd/releases/download
DOWNLOAD URL=${GITHUB_URL}
mkdir -p /tmp/etcd-download-test

# 下载
curl -L $(DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz

# 解压
curl -L $(DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz

# 移除安装包
rm -f /tmp/etcd-${ETCD_VER}一linux-amd64.tar.gz

# 启动程序
/tmp/etcd-download-test/etcd
#检查etcd server版本
/tmp/etcd-download-test/etcd --version

启动的etcd进程默认在2379端口监听来自客户端的请求。 用户可以使用 etcd 的命令行工具 etcdctl 与 etcd server 进行交互, 具体命令如下所示:

#写入一个键值对, {foo: bar}
ETCDCTL_API=3 /tmp/etcd-download-test/etcdctl --endpoints=localhost:2379 put foo bar
OK

#读取键为foo的值
ETCDCTL API=3 /tmp/etcd-download-test/etcdctl --endpoints=localhost: 2379 get foo
bar