Salt自然也是提供api的,使用api对自动化有极大的帮助,我们使用rest风格的api,当然大家都知道salt是python写的,那么自然也就提供了对应的api,但是并不建议使用,因为调用python api的程序是必须运行在master上的,并且此api对python3并不友好

 [root@linux-node1 ~]# yum install pyOpenSSL salt-api –y
[root@linux-node1 ~]# salt-call --local tls.create_self_signed_cert
local:
Created Private Key: "/etc/pki/tls/certs/localhost.key." Created Certificate: "/etc/pki/tls/certs/localhost.crt."
[root@linux-node1 ~]# vim /etc/salt/master
[root@linux-node1 ~]# grep "^[a-Z]" /etc/salt/master
default_include: master.d/*.conf # 打开这个
file_roots:
[root@linux-node1 master.d]# cd /etc/salt/master.d/
[root@linux-node1 master.d]# cat api.conf # 定义key存放位置与提供端口
rest_cherrypy:
port: 8000
ssl_crt: /etc/pki/tls/certs/localhost.crt
ssl_key: /etc/pki/tls/certs/localhost.key
[root@linux-node1 master.d]# cat auth.conf # 定义权限
external_auth:
pam:
saltapi:
- .*
- '@wheel'
- '@runner'
- '@wheel' [root@linux-node1 master.d]# systemctl restart salt-master.service
[root@linux-node1 master.d]# systemctl restart salt-api
[root@linux-node1 master.d]# netstat -tpln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 998/sshd
tcp 0 0 0.0.0.0:4505 0.0.0.0:* LISTEN 92795/python
tcp 0 0 0.0.0.0:4506 0.0.0.0:* LISTEN 92801/python
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 93821/python
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::22 :::* LISTEN 998/sshd
[root@linux-node1 master.d]# useradd -M -s /sbin/nologin saltapi # 正式环境指定guid
[root@linux-node1 master.d]# passwd saltapi
Changing password for user saltapi.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.

换台机器测试一下

 [root@linux-node2 tmp]# curl -sSk https://192.168.56.11:8000/login \
> -H 'Accept: application/x-yaml' \ # 返回yaml格式,读直观
> -d username='saltapi' \
> -d password='saltapi' \
> -d eauth='pam' # 认证模式是pam
return:
- eauth: pam
expire: 1511276286.304869 # 该token过期时间
perms: {}
start: 1511233086.304869
token: 9374cd95e861ba80cda73375b50917446d7a45f2 # 这个很重要
user: saltapi
[root@linux-node2 tmp]# curl -sSk https://192.168.56.11:8000 \
> -H 'Accept: application/x-yaml' \
> -H 'X-Auth-Token: 9374cd95e861ba80cda73375b50917446d7a45f2'\ # token
> -d client=local \
> -d tgt='*' \
> -d fun=test.ping
return: # 返回的信息很直观
- linux-node1.example.com: true
linux-node2.example.com: true
[root@linux-node3 ~]# curl -sSk https://192.168.56.11:8000/login \
> -H 'Accept: application/json' \ # 返回json格式,容易解析
> -d username='saltapi' \
> -d password='saltapi' \
> -d eauth=pam
{"return": [{"perms": [".*"], "start": 1511235669.459298, "token": "9374cd95e861ba80cda73375b50917446d7a45f2'", "expire": 1511278869.459298, "user": "saltapi", "eauth": "pam"}]}
[root@linux-node3 ~]# curl -sSk https://192.168.56.11:8000 \
> -H 'Accept: application/json' \
> -H 'X-Auth-Token: 9374cd95e861ba80cda73375b50917446d7a45f2'\
> -d client=local \
> -d tgt='*' \
> -d fun=test.ping
{"return": [{"linux-node1.example.com": true, "linux-node2.example.com": true}]}

然后就可以使用小北方的api啦

http://www.cnblogs.com/bfmq/p/7905044.html

saltstack api安装使用的更多相关文章

  1. saltstack自动化运维系列⑥SaltStack实践安装配置HAproxy的Keepalived

    saltstack自动化运维系列⑥SaltStack实践安装配置HAproxy的Keepalived 安装配置Keepalived 1.编写功能模块 #创建keepalived目录# mkdir -p ...

  2. saltstack自动化运维系列⑥SaltStack实践安装配置HAproxy

    saltstack自动化运维系列⑥SaltStack实践安装配置HAproxy 下载haproxy1.6.2.tar.gz下载地址:http://www.haproxy.org/download/1. ...

  3. Saltstack设置安装源为阿里源

    Saltstack设置安装源为官方源有时候在国内网络不好安装较慢或者安装不上,可设置为阿里源 比如对于 Centos 7 系统,在 saltstack 的官网提供的配置初始化手册是: sudo yum ...

  4. SaltStack自动化安装zabbix-server

    使用SaltStack自动化安装zabbix-server 1,设置ntp时间同步 2,安装zabbix-agent 3,安装zabbix-server 4,安装及配置mariadb(mariadb与 ...

  5. (转)CentOS6/7 使用saltstack源安装saltstack

    CentOS6/7 使用saltstack源安装saltstack 原文:https://blog.csdn.net/wh211212/article/details/77053708 CentOS ...

  6. saltstack API(一) 安装并测试

    python3 安装api # 首先安装python3 .tgz cd Python- . ./configure make make install mv /usr/bin/python /usr/ ...

  7. 深入解读saltstack的安装及配置1

    安装 一.安装方法:http://www.linuxeye.com/Linux/2765.html 二.建议安装epel后安装saltstack:http://www.a8z8.com/html/20 ...

  8. saltstack配置安装的一些关键步骤及安装时各种报错的分析

    以下其他仅做参考,官方网址才是安装重点:http://docs.saltstack.cn/topics/installation/rhel.html 与安装相关的一些文档或资料: 一.linux服务器 ...

  9. 新手!SDK Manager里找不到API安装的选项怎么办?

    只有Tools和EXTRAS文件夹的选项,没有API包安装,咋办呢?   回复讨论(解决方案) 网络有问题吗? 网络有问题吗? 就是不知道啊 你是在eclispe里面打开的?还是在外面直接打开的?没有 ...

随机推荐

  1. 在Linux的Eclipse下搭建Android环境

    http://blog.csdn.net/lyonte/article/details/6407242 一.Java环境安装配置详见<在Linux下搭建Java环境>http://blog ...

  2. nginx的源代码分析--间接回调机制的使用和类比

    nginx使用了间接回调机制.结合upstream机制的使用来说明一下,首先明白几个事实: 1)事实上ngxin和下游client的连接使用的是ngx_http_connection_t,每一个连接相 ...

  3. 压力测试工具ab,wrk,locust简介

    ab 无疑是目前最常见的压力测试工具.其典型用法如下: shell> ab -k -c 100 -t 10 http://domain/path 其中,参数「c」表示的是并发, 参数「t」表示的 ...

  4. Struts2 (三) (转载)

    前面一直在说Action可以是一个普通的Java类,与Servlet API完全分离,但是为了实现业务逻辑,Action需要使用HttpServletRequest内容.Struts 2设计的精巧之处 ...

  5. 两个经典的文件IO程序示例

    前言 本文分析两个经典的C++文件IO程序,提炼出其中文件IO的基本套路,留待日后查阅. 程序功能 程序一打印用户指定的所有文本文件,程序二向用户指定的所有文本文件中写入数据. 程序一代码及其注释 # ...

  6. LeetCode(16)题解--3Sum Closest

    https://leetcode.com/problems/3sum-closest/ 题目: Given an array S of n integers, find three integers ...

  7. iOS开发者必备:四款后端服务工具

    本文转载至 http://mobile.51cto.com/iphone-411917.htm 对于开发者来说,连接后端数据或许是一件特别痛苦的事情.但后端服务却能够帮助开发人员以更快的速度构建移动应 ...

  8. c#冒泡法排序

    1.通过冒泡法实现一个int数组的有小到大的排序 代码如下: //用for语句来实现排序功能,冒泡排序 static void Sort(int[] number) { ; i < number ...

  9. ​vmware虚拟机centos网络配置错误,执行/etc/init.d/network start 或 restart 提示Device eth0 has different MAC address than expected, ignoring

    vmware虚拟机centos网络配置错误,执行/etc/init.d/network start 或 restart 提示Device eth0 has different MAC address ...

  10. 如何设置Tomcat的JVM虚拟机内存大小

    我的是解压版的tomcat: 首先找到tomcat中bin目录下: catalina.bat 文件,打开这个文件,在 @echo off 下面一行,加上一行代码: set JAVA_OPTS=-ser ...