目标
- minion_id
salt '192.168.29.216'
- 通配符
match all minions:
salt '*' test.ping
match all minions in the example.net domain or any of the example domains:
salt '*.example.net' test.ping
salt 'wewb?.example.net' test.ping
salt 'wewb[1,3].example.net' test.ping
salt 'wewb[1-5].example.net' test.ping
- 匹配正则表达式
salt -E 'web-(prod|devel)' test.ping
- top.sls里怎么写
base:
'web1-(prod|devel)':
- match: pcre
- webserver
列表
salt -L 'web1,web2,web3' test.ping
IP
salt -S 192.168.29.216 test.ping
salt -S 192.168.29.216/20 test.ping
混合用法
salt -C 'S@192.168.29.216 and G@os:CentOS' test.ping
模块
service 模块
- 看当前服务能否运行
salt '*' service.available sshd
- 显示所有运行的服务
salt '*' service.get_all
- 重载服务
salt '*' service.reload httpd
- 服务器状态
salt '*' service.status httpd
- 停止服务
salt '*' service.stop httpd
- 启动服务
salt '*'service.start httpd
network模块
- 返回所有活动的tcp链接
salt '*' network.active_tcp
- 显示arp链接
salt '*' network.arp
- 检查链接
salt '*' network.connect archlinux.org 80
salt '*' network.connect archlinux.org 80 timeout=3
salt '*' network.connect archlinux.org 80 timeout=3 family=ipv4
在master里面有对模块的访问控制
vim /etc/salt/master
client_acl:
oldboy:
- test.ping
- network.*
oldboy 这个用户只有test.ping和network这个模块的执行
vim /etc/salt/master
client_acl:
oldboy:
- test.ping
- network.*
user01:
- 192.168.29.216:
- test.ping
user01这个用户只能在192.168.29.216这台机器上用test.ping
返回
测试MySQL
依赖python-mysqldb 这个包
CREATE DATABASE `salt`
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci;
USE `salt`;
--
-- Table structure for table `jids`
--
DROP TABLE IF EXISTS `jids`;
CREATE TABLE `jids` (
`jid` varchar(255) NOT NULL,
`load` mediumtext NOT NULL,
UNIQUE KEY `jid` (`jid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE INDEX jid ON jids(jid) USING BTREE;
--
-- Table structure for table `salt_returns`
--
DROP TABLE IF EXISTS `salt_returns`;
CREATE TABLE `salt_returns` (
`fun` varchar(50) NOT NULL,
`jid` varchar(255) NOT NULL,
`return` mediumtext NOT NULL,
`id` varchar(255) NOT NULL,
`success` varchar(10) NOT NULL,
`full_ret` mediumtext NOT NULL,
`alter_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
KEY `id` (`id`),
KEY `jid` (`jid`),
KEY `fun` (`fun`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Table structure for table `salt_events`
--
DROP TABLE IF EXISTS `salt_events`;
CREATE TABLE `salt_events` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`tag` varchar(255) NOT NULL,
`data` mediumtext NOT NULL,
`alter_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`master_id` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
KEY `tag` (`tag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;