serf  簡單使用


1. 介紹
// 以下為官方介紹,說白了就是進行系統的集群節點管理
Serf uses an efficient gossip protocol to solve three major problems:

Membership: Serf maintains cluster membership lists and is able to execute custom handler scripts when that membership changes. For example, Serf can maintain the list of web servers for a load balancer and notify that load balancer whenever a node comes online or goes offline.

Failure detection and recovery: Serf automatically detects failed nodes within seconds, notifies the rest of the cluster, and executes handler scripts allowing you to handle these events. Serf will attempt to recover failed nodes by reconnecting to them periodically.

Custom event propagation: Serf can broadcast custom events and queries to the cluster. These can be used to trigger deploys, propagate configuration, etc. Events are simply fire-and-forget broadcast, and Serf makes a best effort to deliver messages in the face of offline nodes or network partitions. Queries provide a simple realtime request/response mechanism.
 
2. 使用
// 測試的是連個節點的模式

a. download
https://www.serf.io/downloads.html
b. start up 
serf agent 實際使用為  serf agent -node=node-name -bind=bindaddress
c. join cluster
serf join nodebindaddress
d. members
serf members
e. leave cluster 
stop the serf agent 
 
3.  擴展
// event handler
foo.sh - The script "foo.sh" will be invoked for any/every event.

member-join=foo.sh - The script "foo.sh" will only be invoked for the "member-join" event.

member-join,member-leave=foo.sh - The script "foo.sh" will be invoked for either member-join or member-leave events. Any combination of events may be specified in this way.

user=foo.sh - The script "foo.sh" will be invoked for all user events.

user:deploy=foo.sh - The script "foo.sh" will be invoked only for "deploy" user events.

query=foo.sh - The script "foo.sh" will be invoked for all queries.

query:load=uptime - The uptime command will be invoked only for "load" queries.
 
4. 實際案例
// web-site loadbalance
https://github.com/hashicorp/serf/tree/master/demo/web-load-balancer


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM