Centos7 安装 Etcd

这篇具有很好参考价值的文章主要介绍了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都将被自动删除。文章来源地址https://www.toymoban.com/news/detail-719610.html

#生成
[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

到了这里,关于Centos7 安装 Etcd的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • 一起学习ETCD系列——简单安装

    在微服务中服务发现是必不可少的,此时ETCD中间件就是一种可选项,其实ETCD除了服务发现功能,还有: 元数据存储,比如存储服务配置等数据,以实现配置中心化,进行统一的,有版本记录的变更管理; 分布式锁; 选主,master-slave的软件架构中可以通过etcd快速实现选主的

    2024年01月25日
    浏览(10)
  • windows Etcd的安装与使用

    windows Etcd的安装与使用

    一、简介 etcd是一个分布式一致性键值存储,其主要用于分布式系统的共享配置和服务发现。 etcd由Go语言编写 二、下载并安装 1.下载地址: https://github.com/coreos/etcd/releases 解压后的目录如下:其中etcd.exe是服务端,etcdctl.exe是客户端   二、简单实用 点击etcd.exe运行etcd服务 客户

    2024年02月11日
    浏览(1)
  • ETCD安装部署与etcdctl常用命令

    ETCD安装部署与etcdctl常用命令

    以3.5.1为例:https://github.com/etcd-io/etcd/releases/tag/v3.5.1 虚机部署 检查etcdserver版本 docker部署 多节点集群化部署,启动方式包含静态配置和服务发现, 适用于线下环境,由于etcd集群中各member需要互相感知对方,因此在启动时会对集群有一定要求,包含: 集群节点个数已知 集群

    2024年02月10日
    浏览(6)
  • K8s组件:etcd安装、使用及原理(Linux)

    K8s组件:etcd安装、使用及原理(Linux)

    1.1 介绍 分布式系统架构中对一致性要求很高,etcd就满足了分布式系统中的一致性要求。 实现了分布式一致性键值对存储的中间件,支持跨平台,有活跃的社区。 etcd 是基于go实现的一个分布式键值对存储(类比Redis),设计用来可靠而快速的保存关键数据并提供访问。通过分布

    2024年02月03日
    浏览(11)
  • CentOS7安装SQLServer数据库服务

    CentOS7安装SQLServer数据库服务

    1.1、下载 Microsoft SQL Server 2019 Red Hat 存储库配置文件 1.2、安装 SQL Server 1.3、安装完成后,运行 mssql-conf setup,按照提示设置 SA 密码并选择版本。 1.4、完成配置后,验证服务是否正在运行 1.5、若要允许远程连接,请在 RHEL 的防火墙上打开 SQL Server 端口。 默认的 SQL Server 端口为

    2024年02月04日
    浏览(10)
  • 基于CentOS7安装MySQL数据库并远程访问

    基于CentOS7安装MySQL数据库并远程访问

    MySQL是目前最为流行的开放源码的数据库,是完全网络化的跨平台的关系型数据库系统,它是由瑞典MySQLAB公司开发,目前属于Oracle公司。任何人都能从Internet下载MySQL软件,而无需支付任费用,并且“开放源码”意味着任何人都可以使用和修改该软件。下面我们来学习如何在

    2024年02月11日
    浏览(13)
  • openGauss数据库安装,配置连接 完整版Centos7

    openGauss数据库安装,配置连接 完整版Centos7

    服务器版本:Centos7.6 || 7.9 数据库版本:openGauss-5.0.0-CentOS-64bit.tar.bz2  极简版 目录 修改系统参数 安装环境 安装openGauss数据库 配置连接数据库 使用navicat连接数据库 ##修改 /etc/selinux/config 文件中的“SELINUX”值为“disabled”。 vi  /etc/selinux/config SELINUX=disabled 关闭防火墙 ##检查

    2024年02月09日
    浏览(9)
  • 运维笔记之centos7安装mysql数据库

    如果使用的4.1以上版本的rpm的话,除了import mysql的公钥到个人用户的配置中,还需要import mysql的公钥到RPM的配置中

    2024年02月04日
    浏览(17)
  • K8S:二进制安装K8S(单台master)安装etcd和master

    K8S:二进制安装K8S(单台master)安装etcd和master

    ` 注意:该操作在所有node节点上进行,为k8s集群提供适合的初始化部署环境 主从时间要更新一致 master节点时间 node1节点时间 node2节点时间 ①etcd简介 etcd是CoreOS团队于2013年6月发起的开源项目,它的目标是构建一个高可用的分布式键值(key-value)数据库。etcd内部采用raft协议作

    2024年02月11日
    浏览(14)
  • centos7.9-RPM安装MySQL 8.0.34数据库教程

    centos7.9-RPM安装MySQL 8.0.34数据库教程

    使用命令 或者 ` 查看操作系统信息,我的系统版本是el7 即liunx/centos 7系列。 下载地址: https://dev.mysql.com/downloads/mysql/ 下载时,要注意自己系统的版本,我的Linux版本是 el7 ,要下载对应的版本。 用上传工具将下载的安装包上传至指定存放目录;我专门存放安装包的目录是

    2024年02月07日
    浏览(23)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包