1 [root@salt100 ~]# salt --version 2 salt 2018.3.3 (Oxygen) 3 [root@salt100 ~]# salt-minion --version 4 salt-minion 2018.3.3 (Oxygen)
https://docs.saltstack.com/en/latest/ref/returners/index.html
https://docs.saltstack.com/en/latest/ref/returners/all/index.html#all-salt-returners
修改了master或者minion的配置文件,那麼必須重啓對應的服務。html
根據規劃在 salt100 部署mariadb 數據庫python
1 # 數據庫安裝 2 yum install -y mariadb mariadb-server 3 # 啓動數據庫 4 systemctl start mariadb.service # 若是有必要能夠設置爲開機自啓動 5 # 在「其餘」機器安裝,用於測試遠程是否能夠鏈接 6 yum install -y mariadb
配置文件也要修改mysql
1 [root@salt100 ~]# mysql 2 Welcome to the MariaDB monitor. Commands end with ; or \g. 3 Your MariaDB connection id is 2 4 Server version: 5.5.60-MariaDB MariaDB Server 5 6 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. 7 8 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 9 10 MariaDB [(none)]> show variables like '%char%'; 11 +--------------------------+----------------------------+ 12 | Variable_name | Value | 13 +--------------------------+----------------------------+ 14 | character_set_client | utf8 | 15 | character_set_connection | utf8 | 16 | character_set_database | latin1 | 17 | character_set_filesystem | binary | 18 | character_set_results | utf8 | 19 | character_set_server | latin1 | 20 | character_set_system | utf8 | 21 | character_sets_dir | /usr/share/mysql/charsets/ | 22 +--------------------------+----------------------------+ 23 8 rows in set (0.00 sec) 24 25 MariaDB [(none)]> set character_set_database=utf8; 26 Query OK, 0 rows affected (0.00 sec) 27 28 MariaDB [(none)]> set character_set_server=utf8; 29 Query OK, 0 rows affected (0.00 sec) 30 31 MariaDB [(none)]> show variables like '%char%'; 32 +--------------------------+----------------------------+ 33 | Variable_name | Value | 34 +--------------------------+----------------------------+ 35 | character_set_client | utf8 | 36 | character_set_connection | utf8 | 37 | character_set_database | utf8 | 38 | character_set_filesystem | binary | 39 | character_set_results | utf8 | 40 | character_set_server | utf8 | 41 | character_set_system | utf8 | 42 | character_sets_dir | /usr/share/mysql/charsets/ | 43 +--------------------------+----------------------------+ 44 8 rows in set (0.01 sec)
1 # 建立數據庫 2 MariaDB [(none)]> CREATE DATABASE `salt` 3 DEFAULT CHARACTER SET utf8 4 DEFAULT COLLATE utf8_general_ci; 5 Query OK, 1 row affected (0.00 sec) 6 7 MariaDB [(none)]> show create database salt; 8 +----------+---------------------------------------------------------------+ 9 | Database | Create Database | 10 +----------+---------------------------------------------------------------+ 11 | salt | CREATE DATABASE `salt` /*!40100 DEFAULT CHARACTER SET utf8 */ | 12 +----------+---------------------------------------------------------------+ 13 1 row in set (0.00 sec) 14 15 # 建立用戶並受權 16 MariaDB [(none)]> grant all on salt.* to salt@'%' identified by 'salt'; # 用於遠程訪問 17 Query OK, 0 rows affected (0.00 sec) 18 19 MariaDB [(none)]> grant all on salt.* to salt@'salt100' identified by 'salt'; # 用於本地訪問 20 Query OK, 0 rows affected (0.00 sec) 21 22 MariaDB [(none)]> flush privileges; 23 Query OK, 0 rows affected (0.00 sec) 24 25 MariaDB [(none)]> select user,host,password from mysql.user where user = 'salt'; 26 +------+---------+-------------------------------------------+ 27 | user | host | password | 28 +------+---------+-------------------------------------------+ 29 | salt | % | *36F75ABC6D500DFA6E905046FD8BE5E115812DD0 | 30 | salt | salt100 | *36F75ABC6D500DFA6E905046FD8BE5E115812DD0 | 31 +------+---------+-------------------------------------------+ 32 2 rows in set (0.00 sec)
1 mysql -hsalt100 -usalt -psalt 2 # 或者 3 mysql -h172.16.1.100 -usalt -psalt
https://docs.saltstack.com/en/latest/ref/returners/all/salt.returners.mysql.html#module-salt.returners.mysql
1 use salt; 2 3 -- 4 -- Table structure for table `jids` 5 -- 6 DROP TABLE IF EXISTS `jids`; 7 CREATE TABLE `jids` ( 8 `jid` varchar(255) NOT NULL, 9 `load` mediumtext NOT NULL, 10 UNIQUE KEY `jid` (`jid`) 11 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 12 13 -- 14 -- Table structure for table `salt_returns` 15 -- 16 DROP TABLE IF EXISTS `salt_returns`; 17 CREATE TABLE `salt_returns` ( 18 `fun` varchar(50) NOT NULL, 19 `jid` varchar(255) NOT NULL, 20 `return` mediumtext NOT NULL, 21 `id` varchar(255) NOT NULL, 22 `success` varchar(10) NOT NULL, 23 `full_ret` mediumtext NOT NULL, 24 `alter_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 25 KEY `id` (`id`), 26 KEY `jid` (`jid`), 27 KEY `fun` (`fun`) 28 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 29 30 -- 31 -- Table structure for table `salt_events` 32 -- 33 DROP TABLE IF EXISTS `salt_events`; 34 CREATE TABLE `salt_events` ( 35 `id` BIGINT NOT NULL AUTO_INCREMENT, 36 `tag` varchar(255) NOT NULL, 37 `data` mediumtext NOT NULL, 38 `alter_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 39 `master_id` varchar(255) NOT NULL, 40 PRIMARY KEY (`id`), 41 KEY `tag` (`tag`) 42 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1 salt '*' state.single pkg.installed name=MySQL-python 2 或者 3 salt '*' cmd.run 'yum install -y MySQL-python'
由 minion 端直接返回到 MySQL 數據庫,不須要通過 master 端。sql
https://docs.saltstack.com/en/latest/topics/jobs/external_cache.html
1 [root@salt03 ~]# vim /etc/salt/minion 2 ………… 3 mysql.host: 'salt100' 4 mysql.user: 'salt' 5 mysql.pass: 'salt' 6 mysql.db: 'salt' 7 mysql.port: 3306 8 9 [root@salt03 ~]# systemctl restart salt-minion.service # 修改了配置,須要重啓 minion
1 [root@salt100 ~]# vim /etc/salt/master 2 ………… 3 ext_job_cache: mysql 4 mysql.host: 'salt100' 5 mysql.user: 'salt' 6 mysql.pass: 'salt' 7 mysql.db: 'salt' 8 mysql.port: 3306 9 10 [root@salt100 ~]# systemctl restart salt-master.service # 修改了配置,須要重啓 master
1 # 說明: 帶了 --return mysql ,適合上面的方式一,在minion端配置 2 # 若是沒有帶 --return mysql ,適合上面的方式二,在master端配置 3 [root@salt100 ~]# salt '*' test.ping --return mysql 4 salt03: 5 True 6 salt01: 7 True 8 salt02: 9 True 10 salt100: 11 True 12 [root@salt100 ~]# salt 'salt0*' cmd.run 'df -h' --return mysql 13 salt03: 14 Filesystem Size Used Avail Use% Mounted on 15 /dev/sda3 18G 2.0G 16G 12% / 16 devtmpfs 901M 0 901M 0% /dev 17 tmpfs 911M 12K 911M 1% /dev/shm 18 tmpfs 911M 9.6M 902M 2% /run 19 tmpfs 911M 0 911M 0% /sys/fs/cgroup 20 /dev/sda1 197M 113M 85M 58% /boot 21 tmpfs 183M 0 183M 0% /run/user/1001 22 salt01: 23 Filesystem Size Used Avail Use% Mounted on 24 /dev/sda3 18G 2.1G 16G 12% / 25 devtmpfs 901M 0 901M 0% /dev 26 tmpfs 911M 12K 911M 1% /dev/shm 27 tmpfs 911M 9.6M 902M 2% /run 28 tmpfs 911M 0 911M 0% /sys/fs/cgroup 29 /dev/sda1 197M 113M 85M 58% /boot 30 tmpfs 183M 0 183M 0% /run/user/1001 31 salt02: 32 Filesystem Size Used Avail Use% Mounted on 33 /dev/sda3 18G 2.0G 16G 12% / 34 devtmpfs 901M 0 901M 0% /dev 35 tmpfs 911M 12K 911M 1% /dev/shm 36 tmpfs 911M 9.6M 902M 2% /run 37 tmpfs 911M 0 911M 0% /sys/fs/cgroup 38 /dev/sda1 197M 113M 85M 58% /boot 39 tmpfs 183M 0 183M 0% /run/user/1001
數據從minion端返回到master以後,再由master寫入MySQL數據庫
https://docs.saltstack.com/en/latest/topics/jobs/external_cache.html
1 [root@salt100 ~]# vim /etc/salt/master 2 ………… 3 master_job_cache: mysql 4 mysql.host: 'salt100' 5 mysql.user: 'salt' 6 mysql.pass: 'salt' 7 mysql.db: 'salt' 8 mysql.port: 3306 9 10 [root@salt100 ~]# systemctl restart salt-master.service # 修改了配置,須要重啓 master
1 [root@salt100 ~]# salt '*' grains.items 2 [root@salt100 ~]# salt '*' cmd.run 'w'