码迷,mamicode.com
首页 > Windows程序 > 详细

salt-api安装与配置

时间:2016-07-04 12:03:33      阅读:420      评论:0      收藏:0      [点我收藏+]

标签:salt-api

1、安装依赖

yum -y install kernel-firmware kernel-headers perf e2fsprogs libyaml PyYAML

yum install salt-api

pip install cherrypy==3.2.3  //需要安装pip


2、配置openssl证书

cd /etc/pki/tls/certs

/usr/bin/openssl genrsa -aes128 2048 > /etc/pki/tls/private/localhost.key

Generating RSA private key, 2048 bit long modulus

........................................+++

...............+++

e is 65537 (0x10001)

Enter pass phrase:(此处输入一个test)

Verifying - Enter pass phrase:(再次确认你输入的)

/usr/bin/openssl req -utf8 -new -key /etc/pki/tls/private/localhost.key (也输入你上次输入那个

此时../private/的文件夹中多了个localhost.key

openssl rsa -in localhost.key -out localhost_nopass.key

回车输入上次输入的


3、创建api访问用户,但是不能登录系统

useradd -M -s /sbin/nologin test

passwd test  //设置密码


4、配置salt-api、并重启服务

[root@localhost salt]# pwd
/etc/salt
[root@localhost salt]# egrep -v "^$|^#" master
default_include: master.d/*.conf           //开启配置路径
interface: 192.168.24.66
auto_accept: True
file_roots:
  base:
    - /srv/salt
pillar_roots:
  base:
    - /srv/salt/pillar


[root@localhost master.d]# pwd
/etc/salt/master.d
[root@localhost master.d]# cat api.conf 
rest_cherrypy:
  host: 192.168.24.66
  port: 8000
  disable_ssl: True                                        //不使用https
  ssl_crt: /etc/pki/tls/certs/localhost.crt                //指定证书路径
  ssl_key: /etc/pki/tls/private/localhost_nopass.key
[root@localhost master.d]# cat eauth.conf 
external_auth:
  pam:
    test:                                                  //指定salt-api用户
      - .*
      - ‘@wheel‘
      - ‘@runner‘


[root@localhost ~]# /etc/init.d/salt-api restart
Stopping salt-api daemon:                                  [  OK  ]
Starting salt-api daemon:                                  [  OK  ]
[root@localhost ~]# 
[root@localhost ~]# /etc/init.d/salt-master restart
Stopping salt-master daemon:                               [  OK  ]
Starting salt-master daemon:                               [  OK  ]


5、测试salt-api

(1)首先登录获取Token

[root@localhost ~]#  curl  -k http://192.168.24.66:8000/login -H  "Accept: application/json"  -d username=‘test‘ -d password=‘test‘ -d eauth=‘pam‘ -d tgt=‘*‘ -d fun=‘status.diskusage‘ |jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
265   196  196   196    0    69    786    276 --:--:-- --:--:-- --:--:--   522
{
  "return": [
    {
      "eauth": "pam",
      "user": "test",
      "expire": 1467643424.707126,
      "token": "0ea7c9ad559bc45b68507aee80aad0bf095ba56e",
      "start": 1467600224.707125,
      "perms": [
        ".*",
        "@wheel",
        "@runner"
      ]
    }
  ]
}

(2)使用salt-api获取minion端内存信息、自此后登录就不需要密码

[root@localhost ~]#  curl -k http://192.168.24.66:8000/ -H "Accpet:application/json" -H "X-Auth-Token:0ea7c9ad559bc45b68507aee80aad0bf095ba56e" -d client=‘local‘ -d tgt=‘*‘ -d fun=‘cmd.run‘ -d arg=‘free -m‘|jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
112   522  104   522    0    42   2267    182 --:--:-- --:--:-- --:--:--  2142
{
  "return": [
    {
      "192.168.24.68": "             total       used       free     shared    buffers     cached\nMem:          3696       1451       2245          0         76       1145\n-/+ buffers/cache:        229       3467 \nSwap:         5999          0       5999",
      "192.168.24.67": "             total       used       free     shared    buffers     cached\nMem:          3696       1451       2245          0         76       1144\n-/+ buffers/cache:        229       3466 \nSwap:         5999          0       5999"
    }
  ]
}
[root@localhost ~]# curl -k http://192.168.24.66:8000/jobs -H "Accpet:application/json" -H "X-Auth-Token:0ea7c9ad559bc45b68507aee80aad0bf095ba56e" -d client=‘runner‘ -d fun=‘manage.status‘|jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0    68    0    68    0    31    131     59 --:--:-- --:--:-- --:--:--    71
{
  "return": [
    {
      "up": [
        "192.168.24.67",
        "192.168.24.68"
      ],
      "down": []
    }
  ]
}


6、使用Jenkins调用salt-api测试

技术分享

可以看到返回信息

技术分享

salt-api安装与配置

标签:salt-api

原文地址:http://tianruyun.blog.51cto.com/4549660/1795528

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!