jericho0702 发表于 2018-7-31 07:57:31

深入理解SaltStack远程执行

(1)所有minion需要安装MySQL-python  # salt '*' cmd.run 'yum install -y MySQL-python'
  # salt '*' pkg.install MySQL-python    #使用pkg模块安装MySQL-python
  (2)安装mariadb
  # yum install -y mariadb-server
  # systemctl start mariadb
  (3)创建salt库,创建jid、salt_returns、salt_events表,授权
  # mysql -uroot -p
  Enter password:
  MariaDB [(none)]> CREATE DATABASE`salt`
  ->   DEFAULT CHARACTER SET utf8
  ->   DEFAULT COLLATE utf8_general_ci;
  Query OK, 1 row affected (0.00 sec)
  MariaDB [(none)]> USE `salt`;
  Database changed
  MariaDB > CREATE TABLE `jids` (
  ->   `jid` varchar(255) NOT NULL,
  ->   `load` mediumtext NOT NULL,
  ->   UNIQUE KEY `jid` (`jid`)
  -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  Query OK, 0 rows affected (0.00 sec)
  MariaDB > 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;
  Query OK, 0 rows affected (0.03 sec)
  MariaDB > 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;
  Query OK, 0 rows affected (0.02 sec)
  MariaDB > show tables;
  +----------------+
  | Tables_in_salt |
  +----------------+
  | jids         |
  | salt_events    |
  | salt_returns   |
  +----------------+
  3 rows in set (0.00 sec)

  MariaDB > grant all on salt.* to salt@'%'>  Query OK, 0 rows affected (0.00 sec)
  (4)修改salt-minion,配置MySQL链接
  # vim /etc/salt/minion
  ######      Returnersettings      ######
  ############################################
  mysql.host: '192.168.56.11'
  mysql.user: 'salt'
  mysql.pass: 'salt'
  mysql.db: 'salt'
  mysql.port: 3306
  # systemctl restart salt-minion
  # vim /etc/salt/minion
  ######      Returnersettings      ######
  ############################################
  mysql.host: '192.168.56.11'
  mysql.user: 'salt'
  mysql.pass: 'salt'
  mysql.db: 'salt'
  mysql.port: 3306
  # systemctl restart salt-minion
  (5)测试,并在数据库查看返回结果
  # salt '*' test.ping --return mysql
  linux-node2.example.com:
  True
  linux-node1.example.com:
  True
  MariaDB > select * from salt_returns;
  +-----------+----------------------+--------+-------------------------+---------+-----------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+

  | fun       | jid                  | return |>  +-----------+----------------------+--------+-------------------------+---------+-----------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+
  | test.ping | 20180118093222060862 | true   | linux-node2.example.com | 1       | {"fun_args": [], "jid": "20180118093222060862", "return": true, "retcode": 0, "success": true, "fun": "test.ping", "id": "linux-node2.example.com"} | 2018-01-18 09:32:22 |
  | test.ping | 20180118093222060862 | true   | linux-node1.example.com | 1       | {"fun_args": [], "jid": "20180118093222060862", "return": true, "retcode": 0, "success": true, "fun": "test.ping", "id": "linux-node1.example.com"} | 2018-01-18 09:32:24 |
  +-----------+----------------------+--------+-------------------------+---------+-----------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+
  2 rows in set (0.00 sec)
页: [1]
查看完整版本: 深入理解SaltStack远程执行