通过上一篇博客(剖析etcd)已经对etcd有初步了解了,那么就动手实践安装吧。本次系统环境了是在vmware下安装了2个centos7系统(使用NAT方式,ip分别是192.168.174.128和192.168.174.129)。登录用户用root。
1.下载安装
https://github.com/coreos/etcd/releases 在这网页,你可以看到有多个版本共选择,也有不同OS下的下载方式例子,点击进去看就OK了。
使用curl -L下载curl -L https://github.com/coreos/etcd/releases/download/v3.1.0-alpha.1/etcd-v3.1.0-alpha.1-linux-amd64.tar.gz -o etcd-v3.1.0-alpha.1-linux-amd64.tar.gz 3.1.0是目前最新版本。
解压后,会看到etcd,etcdctl,将它们复制到/usr/local/bin或/usr/bin下
运行 etcd,将默认组建一个两个节点的集群。数据库服务端默认监听在 2379 和 4001 端口,etcd 实例监
听在 2380 和 7001 端口。显示类似如下的信息:
检查etcd是否正常了,那就通过etcdctl操作一些命令。注意操作前请先看看READ-etcdctl.ME和READv2-etcdctl.ME文件,其中READ-etcdctl.ME开头有句话。
就是说,要在环境变量中设置ETCDCTL_API=3.否则使用etcdctl时会报错(我一开始就没注意)
通过etcdctl --help查看有哪些命令
[root@localhost etcd-v3.1.0-alpha.1-linux-amd64]# etcdctl --help
NAME:
etcdctl - A simple command line client for etcd3.
USAGE:
etcdctl
VERSION:
3.1.0-alpha.1
COMMANDS:
get Gets the key or a range of keys
put Puts the given key into the store
del Removes the specified key or range of keys [key, range_end)
txn Txn processes all the requests in one transaction
compaction Compacts the event history in etcd
alarm disarm Disarms all alarms
alarm list Lists all alarms
defrag Defragments the storage of the etcd members with given endpoints
endpoint health Checks the healthiness of endpoints specified in `--endpoints` flag
endpoint status Prints out the status of endpoints specified in `--endpoints` flag
watch Watches events stream on keys or prefixes
version Prints the version of etcdctl
lease grant Creates leases
lease revoke Revokes leases
lease timetolive Get lease information
lease keep-alive Keeps leases alive (renew)
member add Adds a member into the cluster
member remove Removes a member from the cluster
member update Updates a member in the cluster
member list Lists all members in the cluster
snapshot save Stores an etcd node backend snapshot to a given file
snapshot restore Restores an etcd member snapshot to an etcd directory
snapshot status Gets backend snapshot status of a given file
make-mirror Makes a mirror at the destination etcd cluster
migrate Migrates keys in a v2 store to a mvcc store
lock Acquires a named lock
elect Observes and participates in leader election
auth enable Enables authentication
auth disable Disables authentication
user add Adds a new user
user delete Deletes a user
user get Gets detailed information of a user
user list Lists all users
user passwd Changes password of user
user grant-role Grants a role to a user
user revoke-role Revokes a role from a user
role add Adds a new role
role delete Deletes a role
role get Gets detailed information of a role
role list Lists all roles
role grant-permission Grants a key to a role
role revoke-permission Revokes a key from a role
help Help about any command
OPTIONS:
--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)
--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 (json, proto, simple, table)
[root@localhost etcd-v3.1.0-alpha.1-linux-amd64]#
通过查看.md文件,里面有非常多关于etcdctl相关的操作命令,并且举例子说明,内容很多,这里就不贴了.测试
[root@localhost etcd-v3.1.0-alpha.1-linux-amd64]# etcdctl put testkey 'hello word'
OK
[root@localhost etcd-v3.1.0-alpha.1-linux-amd64]# etcdctl get testkey
testkey
hello word
说明安装成功了。
再另一台机器也是如此安装。
2.集群配置
上面的安装都是在单台服务上的。下面说说集群的安装。
转载自http://blog.youkuaiyun.com/u010511236/article/details/52386229