当前位置: 首页 > news >正文

Centos7 安装 Etcd

        Github上下载并解压安装包

wget https://github.com/coreos/etcd/releases/download/v3.4.10/etcd-v3.4.10-linux-amd64.tar.gz
tar xzvf etcd-v3.4.10-linux-amd64.tar.gz
mv etcd-v3.4.10-linux-amd64 /opt/etcd

        解压后是一些文档和两个二进制文件etcd和etcdctl。etcd是server端,etcdctl是客户端。

        测试环境,启动一个单节点的etcd服务,只需要运行etcd命令就行。

./etcd

配置信息

        为了可以使用系统命令运行etcd,将文件夹下的二进制文件复制到bin下

cp /opt/etcd/etcd* /usr/local/bin/

        设定etcd配置文件

mkdir -p /var/lib/etcd/
mkdir -p /opt/etcd/config/
chmod 700 /var/lib/etcd #注意修改权限,否则无法启动

        创建etcd配置文件

cat <<EOF | sudo tee /opt/etcd/config/etcd.conf
#节点名称
ETCD_NAME=$(hostname -s)
#数据存放位置
ETCD_DATA_DIR=/var/lib/etcd
EOF

        创建systemd配置文件

cat <<EOF | sudo tee /etc/systemd/system/etcd.service[Unit]
Description=Etcd Server
Documentation=https://github.com/coreos/etcd
After=network.target[Service]
User=root
Type=notify
EnvironmentFile=-/opt/etcd/config/etcd.conf
ExecStart=/opt/etcd/etcd
Restart=on-failure
RestartSec=10s
LimitNOFILE=40000[Install]
WantedBy=multi-user.target
EOF

        启动etcd

systemctl daemon-reload && systemctl enable etcd && systemctl start etcd

基本操作

etcdctl -h
NAME:etcdctl - A simple command line client for etcd3.USAGE:etcdctl [flags]VERSION:3.4.10API VERSION:3.4COMMANDS:alarm disarm		Disarms all alarmsalarm list		Lists all alarmsauth disable		Disables authenticationauth enable		Enables authenticationcheck datascale		Check the memory usage of holding data for different workloads on a given server endpoint.check perf		Check the performance of the etcd clustercompaction		Compacts the event history in etcddefrag			Defragments the storage of the etcd members with given endpointsdel			Removes the specified key or range of keys [key, range_end)elect			Observes and participates in leader electionendpoint hashkv		Prints the KV history hash for each endpoint in --endpointsendpoint health		Checks the healthiness of endpoints specified in `--endpoints` flagendpoint status		Prints out the status of endpoints specified in `--endpoints` flagget			Gets the key or a range of keyshelp			Help about any commandlease grant		Creates leaseslease keep-alive	Keeps leases alive (renew)lease list		List all active leaseslease revoke		Revokes leaseslease timetolive	Get lease informationlock			Acquires a named lockmake-mirror		Makes a mirror at the destination etcd clustermember add		Adds a member into the clustermember list		Lists all members in the clustermember promote		Promotes a non-voting member in the clustermember remove		Removes a member from the clustermember update		Updates a member in the clustermigrate			Migrates keys in a v2 store to a mvcc storemove-leader		Transfers leadership to another etcd cluster member.put			Puts the given key into the storerole add		Adds a new rolerole delete		Deletes a rolerole get		Gets detailed information of a rolerole grant-permission	Grants a key to a rolerole list		Lists all rolesrole revoke-permission	Revokes a key from a rolesnapshot restore	Restores an etcd member snapshot to an etcd directorysnapshot save		Stores an etcd node backend snapshot to a given filesnapshot status		Gets backend snapshot status of a given filetxn			Txn processes all the requests in one transactionuser add		Adds a new useruser delete		Deletes a useruser get		Gets detailed information of a useruser grant-role		Grants a role to a useruser list		Lists all usersuser passwd		Changes password of useruser revoke-role	Revokes a role from a userversion			Prints the version of etcdctlwatch			Watches events stream on keys or prefixesOPTIONS:--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-d, --discovery-srv=""			domain name to query for SRV records describing cluster endpoints--discovery-srv-name=""			service name to query when using DNS discovery--endpoints=[127.0.0.1:2379]		gRPC endpoints-h, --help[=false]				help for etcdctl--hex[=false]				print byte strings as hex encoded strings--insecure-discovery[=true]		accept insecure SRV records describing cluster endpoints--insecure-skip-tls-verify[=false]	skip server certificate verification (CAUTION: this option should be enabled only for testing purposes)--insecure-transport[=true]		disable transport security for client connections--keepalive-time=2s			keepalive time for client connections--keepalive-timeout=6s			keepalive timeout for client connections--key=""					identify secure client using this TLS key file--password=""				password for authentication (if this option is used, --user option shouldn't include password)--user=""					username[:password] for authentication (prompt if password is not supplied)-w, --write-out="simple"			set the output format (fields, json, protobuf, simple, table)

        输入、查看、更新、删除k-v:

[root@localhost ~] etcdctl put /testkey "Hello world"
OK
[root@localhost ~] etcdctl get /testkey "Hello world"
/testkey
Hello world
[root@localhost ~] etcdctl put /testkey "Hello"
OK
[root@localhost ~] etcdctl get /testkey "Hello"
/testkey
Hello
[root@localhost ~] etcdctl del /testkey 
1

        获取json输出:

[root@localhost ~] etcdctl get key1 -w json
{"header":{"cluster_id":14841639068965178418,"member_id":10276657743932975437,"revision":6,"raft_term":2},"kvs":[{"key":"a2V5MQ==","create_revision":5,"mod_revision":5,"version":1,"value":"dmFsdWUx"}],"count":1}
[root@localhost ~] etcdctl get key1
key1
value1
[root@localhost ~] echo dmFsdWUx|base64 -d
value1[root@localhost ~]# 

        watch操作:在一个终端运行:

[root@localhost etcd] etcdctl watch key1
PUT
key1
valuex
PUT
key1
valuez

        在另一个终端:

[root@localhost ~] etcdctl put key1 valuex
OK
[root@localhost ~] etcdctl put key1 valuez
OK

        租约
        lease。etcd支持申请定时器,申请一个lease,会返回一个lease ID标识定时器。如果在put一个key的同时携带lease ID,就实现了一个自动过期的key。在etcd中,一个lease可以关联任意多的key,当lease过期后所有关联的key都将被自动删除。

#生成
[root@localhost etcd] etcdctl lease grant 300
lease 694d73749a9d0515 granted with TTL(300s)
#关联到key
[root@localhost etcd] etcdctl put key3 300 --lease=694d73749a9d0515
OK
#维持租约
[root@localhost etcd] etcdctl lease keep-alive 694d73749a9d0515
lease 694d73749a9d0515 keepalived with TTL(300)
#撤销租约
[root@localhost ~] etcdctl lease revoke 694d73749a9d0515
lease 694d73749a9d0515 revoked
http://www.lryc.cn/news/205311.html

相关文章:

  • powerjob基于springboot2.1.6.RELEASE版本的问题研究
  • 【AI视野·今日CV 计算机视觉论文速览 第270期】Wed, 18 Oct 2023
  • uni-app小程序,uview-ui组件样式无法穿透修改的解决办法
  • Codeforces Round 515
  • Linux shell编程学习笔记15:定义数组、获取数组元素值和长度
  • k8s部署kafka,并使用zookeeper做注册中心
  • 关于Nginx缓存
  • 为什么Open3D可视化TensorFlow张量速度超慢
  • 使用element-UI Cascader组件,实现第一级单选选,第二级,第三级,子级可以多选
  • 防止消息丢失与消息重复——Kafka可靠性分析及优化实践
  • 【Linux】Linux中Crontab(定时任务)命令详解及使用教程
  • 计算机毕设 flink大数据淘宝用户行为数据实时分析与可视化
  • 8.2 矢量图层点要素单一符号使用一
  • SQL企业微信群机器人消息推送
  • vscode远程连接ubuntu
  • Positive Technologies 在迪拜宣布与地区网络安全解决方案提供商开展合作
  • Pyside6 QTextEdit
  • Hadoop核心机制详细解析
  • Chromium源码由浅入深(一)
  • Spring Authorization Server 1.1 扩展 OAuth2 密码模式与 Spring Cloud Gateway 整合实战
  • UE4 UltraDynamicSky 天气与水体交互
  • Liunx 实时调度策略 SCHED_RR SCHED_FIFO 区别 适用情况
  • mac上使用虚拟机vm, 里面的镜像挂起会占用电脑的内存吗, 挂起和关机的区别是什么, 会影响正常电脑的内存和硬盘使用吗
  • AIGC时代 浪潮信息积极推动存储产品创新
  • 【PG】PostgreSQL字符集
  • 力扣:137. 只出现一次的数字 II(Python3)
  • orb-slam3编译手册(Ubuntu20.04)
  • 升级 Xcode 15模拟器 iOS 17.0 Simulator(21A328) 下载失败
  • PHP 函数、PHP 简单后门
  • 前端实现菜单按钮级权限