首頁>科技>

#程式設計師# #DevOps# #自動化運維# #乾貨#

組成

一個syndic node包含2個元件

a salt-syndic daemona salt-master daemon配置

CONFIGURING THE SYNDIC

The id option is used by the salt-syndic daemon to identify with the Master node and if unset will default to the hostname or IP address of the Syndic just as with a Minion.

CONFIGURING THE SYNDIC WITH MULTIMASTER

If the master_id value is set in the master config on the higher level masters, job results are returned to the master that originated the request in a best effort fashion. Events/jobs without a master_id are returned to any available master.命令和結果的傳遞Permalink

詳情參考 https://docs.saltstack.com/en/latest/topics/topology/syndic.html#topology

SYNDIC WAITPermalinksyndic_wait: master等待syndic返回結果的時間, 預設是5s. 該選項在傳送指令的master上/etc/salt/master檔案裡配置.Debug執行日誌Permalink

傳送一條指令

[root@master vagrant]# salt 'client.jacky.com' cmd.run 'uptime'client.jacky.com:     11:43:21 up  2:56,  1 user,  load average: 0.00, 0.00, 0.00

Master

Syndic

Minion

原始碼分析Permalink

salt程式碼版本是2015.8.

Syndic的原始碼在/salt/salt/minion.py中class Syndic. 核心主邏輯在tune_in方法.

    .    # Syndic Tune In    def tune_in(self, start=True):        '''        Lock onto the publisher. This is the main event loop for the syndic        '''        signal.signal(signal.SIGTERM, self.clean_die)        log.debug('Syndic {0!r} trying to tune in'.format(self.opts['id']))        if start:            self.sync_connect_master() # 以'sub'的角色連線到master的pub埠.        # Instantiate the local client # 例項化LocalClient物件        self.local = salt.client.get_local_client(self.opts['_minion_conf_file'])        self.local.event.subscribe('')        self.local.opts['interface'] = self._syndic_interface        # add handler to subscriber        self.pub_channel.on_recv(self._process_cmd_socket) # 在連線上添加回調函式, 只要接到新命令就解密, 並且轉發給local的master.                                                           # `_process_cmd_socket`呼叫了`_handle_decoded_payload`, 又呼叫了`self.syndic_cmd(data)`                                                           # 在`syndic_cmd`方法裡呼叫了`self.local.pub`將從上級Master接收的指令透過LocalClient轉發給本地                                                           # 的Master.        # register the event sub to the poller        self._reset_event_aggregation()        self.local_event_stream = zmq.eventloop.zmqstream.ZMQStream(self.local.event.sub, io_loop=self.io_loop)        self.local_event_stream.on_recv(self._process_event) # 監聽本地的event pub介面獲取minion的命令執行結果        # forward events every syndic_event_forward_timeout        self.forward_events = tornado.ioloop.PeriodicCallback(self._forward_events, # 透過`_forward_events`方法呼叫`self._return_pub`將結果轉發回上級Master.                                                              self.opts['syndic_event_forward_timeout'] * 1000,                                                              io_loop=self.io_loop)        self.forward_events.start()         # Send an event to the master that the minion is live        self._fire_master_syndic_start()        # Make sure to gracefully handle SIGUSR1        enable_sigusr1_handler()        if start:            self.io_loop.start() 
任務非同步Permalink

提交非同步任務: salt 'client.jacky.com' cmd.run 'uptime' --async --show-jid

執行結果非同步化接收的方法有如下幾種, 參考 這裡

Default Job Cache (大規模架構下不適合)使用 Master Job Cache(MASTER-SIDE RETURNER)使用 EXTERNAL JOB CACHE(MINION-SIDE RETURNER)

基於Syndic的架構, 將執行結果非同步化可以減小最頂級Master的壓力. 方法也有兩種

在最頂層Master(也就是MoM)使用returner在syndic的Master上使用returner

考慮到擴充套件性, 方法2是最合適的. 以returner為’mysql’為例, 預測到這種情況下, 多個syndic-master會同時寫jid和event, 所以會碰到duplicated key的問題, 不過這種情況並不影響資料的完整性.

參考資料PermalinkSaltstack 高可用架構漫談, 作者聯絡方式Salt中Syndic那點事

10
  • 整治雙十一購物亂象,國家再次出手!該跟這些套路說再見了
  • 華為手機新款上市!麒麟9000GPU核心數量達到24?