實驗端:
server7:172.25.23.7
安裝mysql
yum install mysql-server -y
yum install MySQL-python
vim /etc/salt/master
master_job_cache: mysql
mysql.host: 'localhost'
mysql.user: 'salt'
mysql.pass: 'westos'
mysql.db: 'salt'
mysql.port: 3306
/etc/init.d/salt.master restart
數據庫操作
mysql -p
mysql> grant all on salt.* to salt@'172.25.23.%' identified by 'westos';
mysql> grant all on salt.* to salt@localhost identified by 'westos';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
[root@server7 ~]# vim test.sql
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;
導入數據庫並且查看測試:
[root@server7 ~]# mysql < test.sql
[root@server7 ~]# salt server8 cmd.run 'df -h'
server8:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 19G 987M 17G 6% /
tmpfs 499M 16K 499M 1% /dev/shm
/dev/vda1 485M 33M 427M 8% /boot
[root@server7 ~]# mysql -p
Enter password:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| salt |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> use salt
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+----------------+
| Tables_in_salt |
+----------------+
| jids |
| salt_events |
| salt_returns |
+----------------+
3 rows in set (0.00 sec)
mysql> select * from salt_returns;
| cmd.run | 20180818151509749402 | "Filesystem Size Used Avail Use% Mounted on\n/dev/mapper/VolGroup-lv_root 19G 987M 17G 6% /\ntmpfs 499M 32K 499M 1% /dev/shm\n/dev/vda1 485M 33M 427M 8% /boot" | server8 | 1 | {"fun_args": ["df -h"], "jid": "20180818151509749402", "return": "Filesystem Size Used Avail Use% Mounted on\n/dev/mapper/VolGroup-lv_root 19G 987M 17G 6% /\ntmpfs 499M 32K 499M 1% /dev/shm\n/dev/vda1 485M 33M 427M 8% /boot", "retcode": 0, "success": true, "cmd": "_return", "_stamp": "2018-08-18T07:15:09.926424", "fun": "cmd.run", "id": "server8"} | 2018-08-18 15:15:09 |
| saltutil.sync_modules | 20180818153305505497 | ["modules.my_disk"]