SaltStack之return与job管理
SaltStack组件之return
return组件可以理解为SaltStack系统对执行Minion返回后的数据进行存储或者返回给其他程序,它支持多种存储方式,比如用MySQL、MongoDB、Redis、Memcache等,通过return我们可以对SaltStack的每次操作进行记录,对以后日志审计提供了数据来源。目前官方已经支持30种return数据存储与接口,我们可以很方便的配置与使用它。当然也支持自己定义的return,自定义的return需由python来编写。在选择和配置好要使用的return后,只需在salt命令后面指定return即可。
#查看所哟组件
[root@server1 ~]# salt 'node1' sys.list_returners
node1:
- carbon
- couchdb
- etcd
- highstate
- local
- local_cache
- mattermost
- multi_returner
- pushover
- rawfile_json
- slack
- slack_webhook
- smtp
- splunk
- sqlite3
- syslog
- telegram
return流程
return是在Master端触发任务,然后Minion接受处理任务后直接与return存储服务器建立连接,然后把数据return存到存储服务器。关于这点一定要注意,因为此过程都是Minion端操作存储服务器,所以要确保Minion端的配置跟依赖包是正确的,这意味着我们将必须在每个Minion上安装指定的return方式依赖包,假如使用Mysql作为return存储方式,那么我们将在每台Minion上安装python-mysql模块。
使用mysql作为return存储方式
环境
主机 | IP地址 | 服务 |
---|---|---|
RedHat8:server1 | 192.168.244.131 | master |
RedHat8:node1 | 192.168.244.135 | minion mariadb mariadb-server |
RedHat8:node2 | 192.168.244.137 | minion mariadb |
所有主机关闭防火墙
[root@node1 ~]# systemctl disable --now firewalld
[root@node1 ~]# vim /etc/selinux/config
[root@node1 ~]#
SELINUX=disabled
在所有主机上安装python3-mysql模块
[root@server1 ~]# salt '*' pkg.install python3-PyMySQL
node1
----------
gpg-pubkey.(none):
----------
new:
2f86d6a1-5cf7cefb,8483c65d-5ccc5b19,de57bfbe-53a9be98
old:
8483c65d-5ccc5b19,de57bfbe-53a9be98
mariadb-connector-c:
----------
new:
3.1.11-2.el8_3
old:
mariadb-connector-c-config:
----------
new:
3.1.11-2.el8_3
old:
python3-mysql:
----------
new:
1.4.6-5.el8
old:
......
在node1上部署MySQL作为存储服务器
[root@node1 ~]# yum -y install mariadb*
[root@node1 ~]# systemctl enable --now mysql
Failed to enable unit: Unit file mysql.service does not exist.
[root@node1 ~]# systemctl enable --now mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
[root@node1 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.28-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
MariaDB [(none)]> set password = password('123');
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> exit
Bye
[root@node1 ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.28-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or