機器:master上操做便可python
1:salt-API 安裝git
1) yumgithub
yum install salt-apivim
2) pipcentos
wget https://pypi.python.org/packages/source/p/pip/pip-1.5.6.tar.gz#md5=01026f87978932060cc86c1dc527903e --no-check-certificateapi
tar xvfz pip-1.5.6.tar.gzapp
cd pip-1.5.6curl
python setup.py build測試
python setup.py installui
安裝完成後能夠用pip freeze查看已安裝的packages
pip freeze
pip install cherrypy==3.2.3
pip install salt-api==0.8.3
2:建立證書與祕鑰
cd /etc/pki/tls/certs
[root@GZ-newzzb-207 certs]# make testcert
umask 77 ; \
/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:
Verifying - Enter pass phrase:
umask 77 ; \
/usr/bin/openssl req -utf8 -new -key /etc/pki/tls/private/localhost.key -x509 -days 365 -out /etc/pki/tls/certs/localhost.crt -set_serial 0
Enter pass phrase for /etc/pki/tls/private/localhost.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:guangzhou
Locality Name (eg, city) [Default City]:tianhe
Organization Name (eg, company) [Default Company Ltd]:bw
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:
Email Address []:
[root@GZ-newzzb-207 certs]#
cd ../private/
openssl rsa -in localhost.key -out localhost_nopass.key
useradd -M -s /sbin/nologin saltapi
passwd saltapi
3:建立文件並添加內容:
vim etc/salt/master.d/eauth.conf
external_auth:
pam:
saltapi:
- .*
vim /etc/salt/master.d/api.conf
rest_cherrypy:
port: 8888
ssl_crt: /etc/pki/tls/certs/localhost.crt
ssl_key: /etc/pki/tls/private/localhost_nopass.key
4:低版本的centos系統能夠下載啓動腳本
##下載壓縮包,salt-api-0.8.4.1.tar.gz\salt-api-0.8.4.1\pkg\rpm此目錄下有啓動腳本
https://github.com/saltstack/salt-api/tags
5:啓動服務,驗證
重啓master和salt-API服務
systemctl restart salt-master.service
systemctl restart salt-api.service
master上測試
salt \* test.ping
172.16.0.*:
True
172.16.0.*:
True
172.16.0.*:
True
###返回結果true代表正常
###獲取token
curl -k https://192.168.186.134:8888/login -H "Accept: application/x-yaml" -d username='saltapi' -d password='password' -d eauth='pam'
return:
- eauth: pam
expire: 1479416422.718242
perms:
- .*
start: 1479373222.718241
token: 6cc874de22fbfb9fa601cb2c775b2a9e40668a24
user: saltapi
###根據token獲取機器的詳細信息
curl -k https://172.16.0.*:8888/minions/172.16.0.* -H "Accept: application/x-yaml" -H "X-Auth-Token: 7844c6fd3a6c49915ad4dfa6c9e9aa51c6484edd"