day58——Saltstack二次开发(二)

Saltstack的httpapi

1.在官网跟新yum源信息:

2.yum安装

yum install -y gcc make python-devel libffi-devel salt-api openssl

pip install cherrypy

生成证书:

#cd /etc/salt

#mkdir keycrt

#cd keycrt

#openssl genrsa –out key.pem 4098

#openssl req –new –x 509 –key key.pem –out cert.pem –days 1826

3. 配置用户以及权限:

a.首先需要在master上检查配置文件:

default_include: master.d/*.conf

interface: 192.168.48.128

conf_file: /etc/salt/master

pki_dir: /etc/salt/pki/master

auto_accept: True

file_roots:

    base:

        - /srv/salt/

log_file: /var/log/salt/master

log_level_logfile: debug

b. 配置salt-api的配置文件:

[root@localhost master.d]# cd /etc/salt/master.d/

[root@localhost master.d]# ls api.conf eauth.conf

[root@localhost master.d]#

[root@localhost master.d]# cat api.conf

rest_cherrypy:

    port: 8000

    ssl_crt: /etc/salt/keycrt/cert.pem

    ssl_key: /etc/salt/keycrt/key.pem

[root@localhost master.d]# cat eauth.conf

external_auth:

    pam:

    saltapi:

        - .*

        - '@wheel'

        - '@runner'

创建用户:

c. 创建用户

useradd -M -s /sbin/nologin/ saltapi

echo “saltapi” |passwd saltapi --stdin

注意这个应用名和上面的saltapi要对应一致。

启动salt-api

systemctl restart salt-api

netstat –anp |grep 8000

对于ubuntu系统,我们可能使用https也是没法使用,我们可以使用http协议,具体的配置如下:

root@ling-virtual-machine:/etc/salt/master.d# cat api.conf

rest_cherrypy:

    port: 8000

    disable_ssl: True

    #ssl_crt: /etc/salt/keycrt/cert.pem

    #ssl_key: /etc/salt/keycrt/key.pem

注意以上的: disable_ssl: True

然后把ssl秘钥和公钥注释掉,eauth.conf不发生变化

获取tocken: http协议的
curl -X POST -k http://192.168.48.134:8000/login -d username='saltapi' -d password='saltapi' -d eauth='pam' |python -mjson.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 240 100 197 100 43 45 9 0:00:04 0:00:04 --:--:-- 45
{
    "return": [
        {
            "eauth": "pam",
            "expire": 1517235285.554001,
            "perms": [
                ".*",
                "@wheel",
                "@runner"
            ],
            "start": 1517192085.554001,
            "token": "105ee1f28109d67855ce7898e75e173a678f5174",
            "user": "saltapi"
        }
    ]
}

 1 获取tocken:   https协议的(centos7)
 2 [root@localhost master.d]# curl -X POST -k https://192.168.48.131:8000/login -d username='saltapi' -d password='saltapi' -d eauth='pam' |python -mjson.tool
 3   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
 4                                  Dload  Upload   Total   Spent    Left  Speed
 5 100   240  100   197  100    43    908    198 --:--:-- --:--:-- --:--:--   912
 6 {
 7     "return": [
 8  { 9 "eauth": "pam", 10 "expire": 1517235312.537542, 11 "perms": [ 12 ".*", 13 "@wheel", 14 "@runner" 15  ], 16 "start": 1517192112.537541, 17 "token": "bd5922438e9ae10db039816728c2b86f9462a0bb", 18 "user": "saltapi" 19  } 20  ] 21 }

Headers里面是用来存放headers的信息的

Body里面来存放数据的,常用的data数据就是x-www-

form-urlencoded form-data 是用来存放页面form表单数据的

只要salt-api不重启,tocken就不会过期,salt-api重启以后,tocken就会过期

通过postman来获取执行module:

 

 

通过curl来获取执行module:
root@ling-virtual-machine:/etc/salt/master.d# curl -k http://192.168.48.134:8000 -H "Accept: application/x-yaml" -H "X-Auth-Token: ec623ed62de7dd62cfdadb94ad0044b7f46c9549" -d client='local' -d tgt='*' -d fun='test.ping'
return:
192.168.48.129: true

运行runner
root@ling-virtual-machine:/etc/salt/master.d# curl -k http://192.168.48.134:8000 -H "Accept: application/x-yaml" -H "X-Auth-Token: ec623ed62de7dd62cfdadb94ad0044b7f46c9549" -d client='runner' -d fun='manage.status' 
return:
- down: []
up:
- 192.168.48.129

 

 

1.自定义一些module

2. 线上使用runner的实例

 

转载于:https://www.cnblogs.com/yangjinbiao/p/8416963.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值