通過上一篇博客(剖析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.csdn.net/u010511236/article/details/52386229