命令格式
salt '<操作目标>' <方法>[参数]
查看被控主机内存使用情况
[root@node1 ~]# salt '*' cmd.run 'free -h'
node2:
total used free shared buff/cache available
Mem: 727M 127M 406M 5.1M 194M 473M
Swap: .5G 0B .5G
查看以node开头的主机IP是否联通
[root@node1 ~]# salt -E '^node' test.ping
node2:
True
node3:
True
查看minion的相关状态
[root@node1 ~]# salt-run manage.status
down:
up:
- node2
- node3
查看哪些系统任务还在处理中
[root@node1 ~]# salt-run jobs.active
查询所有接收到的证书
[root@node1 ~]# salt-key -L
Accepted Keys:
node2
node3
Denied Keys:
Unaccepted Keys:
Rejected Keys:
删除单个证书(删除 node2 )
[root@node1 ~]# salt-key -d node2
The following keys are going to be deleted:
Accepted Keys:
node2
Proceed? [N/y] y
Key for minion node2 deleted
删除所有证书
[root@node1 ~]# salt-key -D
接受所有证书
[root@node1 ~]# salt-key -A
The following keys are going to be accepted:
Unaccepted Keys:
node2
Proceed? [n/Y] Y
Key for minion node2 accepted.
接受单个证书
[root@node1 ~]# salt-key -d nobe2
显示node2 主机的软件包版本列表
[root@node1 ~]# salt '*' pkg.list_pkgs
node3:
----------
GeoIP:
1.5.-.el7
NetworkManager:
:1.0.-.git20150121.b4ea599c.el7
NetworkManager-libnm:
:1.0.-.git20150121.b4ea599c.el7
显示 Python 软件包版本信息
[root@node1 ~]# salt '*' pkg.version python
node3:
2.7.-.el7
node2:
2.7.-.el7
安装软件包
[root@node1 ~]# salt '*' pkg.install httpd
node3:
----------
node2:
----------
查看mysql服务状态
[root@node1 ~]# salt '*' service.status mysql
node2:
True
node3:
False
启动 node2 主机 mysql 服务器
[root@node1 ~]# salt 'node2' cmd.run 'service mysql start'
node2:
Redirecting to /bin/systemctl start mysql.service
查看 node2 主机 mysql 详细状态
[root@node1 ~]# salt 'node2' cmd.run 'service mysql status'
node2:
Redirecting to /bin/systemctl status mysql.service
mysqld.service - MySQL Community Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled)
Active: active (running) since Wed -- :: EDT; 3min 17s ago
Process: ExecStartPost=/usr/bin/mysql-systemd-start post (code=exited, status=/SUCCESS)
Process: ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=/SUCCESS)
Main PID: (mysqld_safe)