Linux自动化工具之SaltStack return(mysql)
2020-02-24自动化运维90root457°c
A+ A-1 . 安装mysql服务
master:
[[email protected] ~]# yum -y install MySQL-python myslq-server
minion:
[[email protected] ~]# yum -y install MySQL-python
[[email protected] ~]# yum -y install MySQL-python
2 . 启动mysql服务
[[email protected] ~]# /etc/init.d/mysqld start
3 . 创建salt数据库和表
[[email protected] ~]# mysql -uroot -p mysql> CREATE DATABASE `salt` -> DEFAULT CHARACTER SET utf8 -> DEFAULT COLLATE utf8_general_ci; mysql> use salt; Database changed mysql> CREATE TABLE `jids` ( -> `jid` varchar(255) NOT NULL, -> `load` mediumtext NOT NULL, -> UNIQUE KEY `jid` (`jid`) -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 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` varchar(1024) NOT NULL, -> `alter_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -> PRIMARY KEY (`id`), -> KEY `tag` (`tag`) -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8; mysql> grant all on salt.* to [email protected]'%' identified by 'salt'; mysql> flush privileges;
4 . 修改master、minion的salt配置文件
[[email protected] ~]# vim /etc/salt/master #文件末尾添加
mysql.host: '192.168.15.11'
mysql.user: 'salt'
mysql.pass: 'salt'
mysql.db: 'salt'
mysql.port: 3306
[[email protected] ~]# /etc/init.d/salt-master restart #重启服务
[[email protected] ~]# vim /etc/salt/minion #文件末尾添加
mysql.host: '192.168.15.11'
mysql.user: 'salt'
mysql.pass: 'salt'
mysql.db: 'salt'
mysql.port: 3306
[[email protected] ~]# vim /etc/salt/minion #文件末尾添加
mysql.host: '192.168.15.11'
mysql.user: 'salt'
mysql.pass: 'salt'
mysql.db: 'salt'
mysql.port: 3306
[[email protected] ~]# salt '*' service.restart salt-minion --return mysql
[[email protected] ~]# mysql -uroot -p

salt_returns 表记录master操作日志。 前提执行salt后面加上--return mysql
5 . master端增加master_job_cache
[[email protected] ~]# vim /etc/salt/master #末尾增加
master_job_cache: mysql
[[email protected] ~]# /etc/init.d/salt-master restart
[[email protected] ~]# salt '*' service.restart salt-minion
