saltstack遠程執行
阿新 • • 發佈:2018-12-01
log python srv https cache 無效 time ren rep
目標
https://docs.saltstack.com/en/latest/
模塊
https://docs.saltstack.com/en/latest/ref/modules/all/index.html
salt ‘*‘ service.available sshd 驗證sshd服務
[root@master ~]# grep -v ‘^$‘ /etc/salt/master |grep -v ‘#‘
client_acl: #客戶端開啟模塊限制
luo: #用戶名
- test.ping
- network.*
file_roots:
base:
- /srv/salt
pillar_roots:
base:
- /srv/pillar
[root@master ~]# systemctl restart salt-master
給用戶授權
[root@master ~]# useradd luo
useradd:用戶“luo”已存在
[root@master ~]# passwd luo
更改用戶 luo 的密碼 。
新的 密碼:
無效的密碼: 密碼少於 8 個字符
重新輸入新的 密碼:
passwd:所有的身份驗證令牌已經成功更新。
[root@master ~]# su - luo
[luo@master ~]$ salt ‘*‘ test.ping
[WARNING ] Failed to open log file, do you have permission to write to /var/log/salt/master?
192.168.43.71:
True
192.168.43.118:
True
返回
把返回結果,放進數據庫:https://docs.saltstack.com/en/latest/ref/returners/all/salt.returners.mysql.html#module-salt.returners.mysql
[root@master ~]# mysql -pMyNewPass4!
mysql>CREATE DATABASE `salt`
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci;
USE `salt`;
mysql>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;
mysql>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;
mysql>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;
mysql> use salt;
Database changed
mysql> show tables;
+----------------+
| Tables_in_salt |
+----------------+
| jids |
| salt_events |
| salt_returns |
+----------------+
mysql> grant all on salt.* to salt@‘%‘ identified by ‘Myq1231!‘;
[root@master ~]# yum -y install MySQL-python #minion返回,所有minion都裝
[root@master ~]# grep -v ‘^$‘ /etc/salt/master |grep -v ‘#‘
client_acl:
luo:
- test.ping
- network.*
file_roots:
base:
- /srv/salt
pillar_roots:
base:
- /srv/pillar
mysql.host: ‘192.168.43.118‘
mysql.user: ‘salt‘
mysql.pass: ‘Myq1231!‘
mysql.db: ‘salt‘
mysql.port: 3306
[root@master ~]# systemctl restart salt-master
[root@master ~]# salt ‘*‘ test.ping --return mysql
[root@slave ~]#grep -v ‘^$‘ /etc/salt/minion |grep -v ‘#‘
master_job_cache: mysql
master: 192.168.43.118
mysql.host: ‘192.168.43.118‘
mysql.user: ‘salt‘
mysql.pass: ‘Myq1231!‘
mysql.db: ‘salt‘
mysql.port: 3306
[root@master ~]# grep -v ‘^$‘ /etc/salt/minion |grep -v ‘#‘
master_job_cache: mysql
master: 192.168.43.118
mysql.host: ‘192.168.43.118‘
mysql.user: ‘salt‘
mysql.pass: ‘Myq1231!‘
mysql.db: ‘salt‘
mysql.port: 3306
[root@master ~]# systemctl restart salt-minion
mysql> select * from salt_returns;
saltstack遠程執行