After the server 1 (Master) is pushed to the minion, the minion will save the push information for 24 hours. However, in order to view the push information in the future, we should store the information for a long time, which is a good choice in the database. Now we use two methods to store the information, the latter is more commonly used:
server1 is master
Server 2,3,4 is minion
Method 1:
1. Install the database on server1 (master)
yum install -y mysql-server
2. Log in the database and authorize the salt user
grant all on salt.* to salt@'172.25.1.%' identified by 'jay';
3. Install MySQL Python on the minion side (sevr2) to be backed up
yum install MySQL-python -y
4. Configure the minion file of server2
810 #return:
811 # - mysql
812 # - hipchat
813 # - slack
814 mysql.host: '172.25.1.1' # The host of mysql database (master)
815 mysql.user: 'salt' # Users logging in the database
816 mysql.pass: 'jay' # salt user password
817 mysql.db: 'salt' # Database for push information
818 mysql.port: 3306
Reopen minion: / etc/init.d/salt-minion restart
5. Import data in mysql database of server1:
mysql < test.sql
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;
6. Push to server2 at sever1 end, and view in the salt database Salt & returns table of the database
salt 'server2' test.ping --return mysql # Push ping command and return the result to mysql database
Method two:
All operations are performed in server1 (master), and MySQL Python is also installed on server1
1. Install MySQL Python on server1
yum install MySQL-python
2. Authorize the local localhost user in the database (the mysql hungry python module in the database is on the server1 side, so only authorize the localhost user)
grant all on salt.* to salt@'localhost' identified by 'jay';
3. Edit the master file of server1
#return: mysql
master_job_cache: mysql
mysql.host: 'localhost'
mysql.user: 'salt'
mysql.pass: 'jay'
mysql.db: 'salt'
mysql.port: 3306
4. Push salt server3 cmd.run 'df -h' to server2 or 3 or 4 on server1
5. View in database