搜索
首页数据库mysql教程Saltstack 新特性测试之proxy minion

salt 目前主要的应用场景是Linux OS下,另外还有Windows Client(Win下没用过,但是看官方issue,应该……),最近关注到官方的一个小模块提到了Proxy minion,群里也多有提及,便想着看看到底是啥存在。 任何设备均可被salt托管 salt proxy minion的出现,

salt 目前主要的应用场景是Linux OS下,另外还有Windows Client(Win下没用过,但是看官方issue,应该……),最近关注到官方的一个小模块提到了Proxy minion,群里也多有提及,便想着看看到底是啥存在。

任何设备均可被salt托管

salt proxy minion的出现,使得网管设备或者哑设备(比如sms gateway)均可被salt统一管理,而实际的管理模块或通讯接口均由用户自行编写好,具体操作内容请参见salt 官网对应的 Proxy Minion 介绍

开发中的新特性

首先需要注意一点,Proxy minion是2014.1.x版本引进的新特性,并且到目前为止仍处于开发阶段,仅可用作测试用途。

测试环境的准备

本人的PC环境:

  • vbox下ubuntu 14.04 LTS Server
  • Salt master & minion 2014.1.7(配置test.ping通,不多说了)

准备好基础环境之后,需要从github下载salt官方开发人员用于测试Proxy Minion的一个小程序(Rest Server,模拟网管设备的管理接口),名字是 salt-proxy-rest。

这个程序可能依赖两个python库,bottle和requests(其实就是web server需要的组件……),安装一下即可。

使用 python rest.py 运行该程序,可以将此作为一个网管设备的Web管理接口:

alt

尝试运行!

至此,准备工作算是完成。在当前环境下,salt-master和salt-minion稳定运行,并且有一个提供REST接口的网管设备在独立工作,我们需要做的便是将其拉进Salt的阵营。

配置pillar

鄙人的minion id是docker,对应的pillar的top.sls内容配置为:

root@docker:/srv/pillar# cat top.sls
base:
  docker:
    - proxyminion

而proxyminion.sls内容则是对应网管设备的描述:

root@docker:/srv/pillar# cat proxyminion.sls 
proxy:
  rest_sample:
    proxytype: rest_sample
    url: http://127.0.0.1:8080/
    id: proxy_docker

这里需要注意的是,proxytype必须是在salt/proxy下已经预先定义好的,而其他的一些参数则是自己网管设备通信需要的一些数据,不一定相同。

定义好pillar数据之后,需要为之添加对应的proxy conn class和grains数据,这里鄙人使用官方sample,就偷个懒:

root@docker:/srv/pillar# cat /usr/lib/python2.7/dist-packages/salt/proxy/rest_sample.py
# -*- coding: utf-8 -*-
'''
This is a simple proxy-minion designed to connect to and communicate with
the bottle-based web service contained in salt/tests/rest.py.
Note this example needs the 'requests' library.
Requests is not a hard dependency for Salt
'''
……

放心,2014.1.7版本已经默认有这个sample代码。 接下来,直接test.ping试试吧!

root@docker:/srv/pillar# salt '*' test.ping -v
Executing job with jid 20140720110315049478
-------------------------------------------
docker:
    True
rest_sample-localhost:
    True

诶,等一下,为什么多出来个key?为什么还能test.ping通?没错!这个就是ProxyMinion,而salt默认已经配置了test.ping方法兼容proxy minion了,只要写好对应的ping模块,就可以使用常规的test.ping来探测!(本例的ping代码如下)

def ping(self):
    '''
    Is the REST server up?
    '''
    r = requests.get(self.url+'ping')
    try:
        if r.status_code == 200:
            return True
        else:
            return False
    except Exception:
        return False

rest_sample还提供很多function,比如鄙人测试的一个service_status,修改对应的模块代码即可使之兼容proxy minion(代码路径为/usr/lib/python2.7/dist-packages/salt/modules/service.py):

def status(name, sig=None):
    '''
    Return the status for a service, 
    returns the PID or an empty string if the
    service is running or not, pass a signature
    to use to find the service via ps
    CLI Example:
    .. code-block:: bash
    salt '*' service.status  [service signature]
    '''
    #wjx add, denote it to work!!
    #if 'proxyobject' in __opts__:
    #    return __opts['proxyobject'].service_status(sig if sig else name)
    return __salt__['status.pid'](sig if sig else name)

那么这时候再看看当前proxy minion管理的服务状态咋样了:

root@docker:/srv/pillar# salt '*' service.status apache
rest_sample-localhost:
    ----------
    comment:
        stopped
    ret:
        True
docker:
    False

完全和普通minion兼容!!rest_sample本身还配置了grain数据,代码位于/usr/lib/python2.7/dist-packages/salt/grains/rest_sample.py,直接敲命令看看:

root@docker:/srv/pillar# salt 'rest_sample-localhost' grains.items
rest_sample-localhost:
    housecat: Are you kidding?
    kernel: 0.0000001
    location: In this darn virtual machine.  Let me out!
    os: RestExampleOS
    os_family: proxy

Awesome!!这样一来,一个基本的salt proxy minion就算是配置完成,Proxy Minion 的类定义代码位于/usr/lib/python2.7/dist-packages/salt/minion.py,有兴趣可以看看。

可能的bug

鄙人在本机测试时,Minion Docker在尝试fork出一个ProxyMinion过程中间报错,说_running参数没有配置,在添加代码后通过(即位于minion.py代码里)

class ProxyMinion(Minion):
'''
This class instantiates a 'proxy' minion--a minion that does not manipulate
the host it runs on, but instead manipulates a device that cannot run a minion.
'''
def __init__(self, opts, timeout=60, safe=True):  # pylint: disable=W0231
    '''
    Pass in the options dict
    '''
    #wjx add, maybe a bug
    self._running = None
    # Warn if ZMQ 
<h4 id="聊聊Proxy-Minion">聊聊Proxy Minion</h4>
<p>Proxy minion使得salt针对网管设备的配置管理成为可能,不过想要实现一个ProxyType的ProxyMinion的完全管理,可能需要编写很多额外的module去支持它的运行。</p>
<p>在大公司复杂的网络环境下,完全可以针对此编写对应SNMP管理模块或者针对OVS编写对应的管理模块,尔后通过salt统一托管,毕竟Salt有一套完善的配置管理体系啊!</p>
    <p class="copyright">
        原文地址:Saltstack 新特性测试之proxy minion, 感谢原作者分享。
    </p>
    
    


声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
MySQL字符串类型:存储,性能和最佳实践MySQL字符串类型:存储,性能和最佳实践May 10, 2025 am 12:02 AM

mySqlStringTypesimpactStorageAndPerformanCeaseAsfollows:1)长度,始终使用theSamestoragespace,whatcanbefasterbutlessspace-felfficity.2)varCharisvariable varcharisvariable length,morespace-morespace-morespace-effficitybuteftife buteftife butfority butfority textifforlyslower.3)

了解MySQL字符串类型:VARCHAR,文本,char等了解MySQL字符串类型:VARCHAR,文本,char等May 10, 2025 am 12:02 AM

mySqlStringTypesIncludeVarChar,文本,char,enum和set.1)varCharisVersAtileForvariable-lengthStringStringSuptOptoPeptoPepecifientlimit.2)textisidealforlargetStortStorStoverStorextorewiteWithoutAdefinedLengthl.3)charlisfixed-Length

MySQL中的字符串数据类型是什么?MySQL中的字符串数据类型是什么?May 10, 2025 am 12:01 AM

MySQLoffersvariousstringdatatypes:1)CHARforfixed-lengthstrings,2)VARCHARforvariable-lengthtext,3)BINARYandVARBINARYforbinarydata,4)BLOBandTEXTforlargedata,and5)ENUMandSETforcontrolledinput.Eachtypehasspecificusesandperformancecharacteristics,sochoose

如何向新的MySQL用户授予权限如何向新的MySQL用户授予权限May 09, 2025 am 12:16 AM

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

如何在MySQL中添加用户:逐步指南如何在MySQL中添加用户:逐步指南May 09, 2025 am 12:14 AM

toadduserInmysqleffectection andsecrely,theTheSepsps:1)USEtheCreateuserStattoDaneWuser,指定thehostandastrongpassword.2)GrantNectalRevileSaryPrivilegesSustate,usiveleanttatement,AdheringTotheTeprinciplelastPrevilegege.3)

mysql:添加具有复杂权限的新用户mysql:添加具有复杂权限的新用户May 09, 2025 am 12:09 AM

toaddanewuserwithcomplexpermissionsinmysql,loldtheSesteps:1)创建eTheEserWithCreateuser'newuser'newuser'@''localhost'Indedify'pa ssword';。2)GrantreadAccesstoalltablesin'mydatabase'withGrantSelectOnMyDatabase.to'newuser'@'localhost';。3)GrantWriteAccessto'

mysql:字符串数据类型和coltrationsmysql:字符串数据类型和coltrationsMay 09, 2025 am 12:08 AM

MySQL中的字符串数据类型包括CHAR、VARCHAR、BINARY、VARBINARY、BLOB、TEXT,排序规则(Collations)决定了字符串的比较和排序方式。1.CHAR适合固定长度字符串,VARCHAR适合可变长度字符串。2.BINARY和VARBINARY用于二进制数据,BLOB和TEXT用于大对象数据。3.排序规则如utf8mb4_unicode_ci忽略大小写,适合用户名;utf8mb4_bin区分大小写,适合需要精确比较的字段。

MySQL:我应该在Varchars上使用什么长度?MySQL:我应该在Varchars上使用什么长度?May 09, 2025 am 12:06 AM

最佳的MySQLVARCHAR列长度选择应基于数据分析、考虑未来增长、评估性能影响及字符集需求。1)分析数据以确定典型长度;2)预留未来扩展空间;3)注意大长度对性能的影响;4)考虑字符集对存储的影响。通过这些步骤,可以优化数据库的效率和扩展性。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )专业的PHP集成开发工具

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

Dreamweaver Mac版

Dreamweaver Mac版

视觉化网页开发工具