return组件可以理解为SaltStack系统对执行Minion返回后的数据进行存储或者返回给其他程序,它支持多种存储方式,比如用MySQL、MongoDB、Redis、Memcache等,通过return我们可以对SaltStack的每次操作进行记录,对以后日志审计提供了数据来源。目前官方已经支持30种return数据存储与接口,我们可以很方便的配置与使用它。当然也支持自己定义的return,自定义的return需由python来编写。在选择和配置好要使用的return后,只需在salt命令后面指定return即可。
[root@master ~]# salt 'minion' sys.list_returners
minion:
- carbon
- couchdb
- etcd
- highstate
- local
- local_cache
- mattermost
- multi_returner
- pushover
- rawfile_json
- slack
- slack_webhook
- smtp
- splunk
- sqlite3
- syslog
- telegram
return是在Master端触发任务,然后Minion接受处理任务后直接与return存储服务器建立连接,然后把数据return存到存储服务器。关于这点一定要注意,因为此过程都是Minion端操作存储服务器,所以要确保Minion端的配置跟依赖包是正确的,这意味着我们将必须在每个Minion上安装指定的return方式依赖包,假如使用Mysql作为return存储方式,那么我们将在每台Minion上安装python-mysql模块。
示意图片:
环境说明:
主机 | IP | 服务 |
---|---|---|
master | 192.168.101.110 | salt-master |
minion | 192.168.101.120 | salt-minion mariadb |
mariadb | 192.168.101.210 | mariadb-server mariadb |
三台关闭防火墙
[root@master ~]# systemctl disable --now firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@master ~]# setenforce 0
[root@minion ~]# systemctl disable --now firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@minion ~]# setenforce 0
[root@mariadb ~]# systemctl disable --now firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@mariadb ~]# setenforce 0
master上安装服务
# 下载仓库
[root@master ~]# rpm --import https://repo.saltproject.io/py3/redhat/8/x86_64/latest/SALTSTACK-GPG-KEY.pub
[root@master ~]# curl -fsSL https://repo.saltproject.io/py3/redhat/8/x86_64/latest.repo | sudo tee /etc/yum.repos.d/salt.repo
[salt-latest-repo]
name=Salt repo for RHEL/CentOS 8 PY3
baseurl=https://repo.saltproject.io/py3/redhat/8/x86_64/latest
skip_if_unavailable=True
failovermethod=priority
enabled=1
enabled_metadata=1
gpgcheck=1
gpgkey=https://repo.saltproject.io/py3/redhat/8/x86_64/latest/SALTSTACK-GPG-KEY.pub
[root@master ~]# ls /etc/yum.repos.d/
CentOS-Stream-AppStream.repo CentOS-Stream-Media.repo
CentOS-Stream-BaseOS.repo CentOS-Stream-PowerTools.repo
CentOS-Stream-Debuginfo.repo CentOS-Stream-RealTime.repo
CentOS-Stream-Extras.repo salt.repo
CentOS-Stream-HighAvailability.repo
# 安装服务salt-master
[root@master ~]# yum -y install salt-master
......
# 启动
[root@master ~]# systemctl start salt-master
minion上安装服务
[root@minion ~]# rpm --import https://repo.saltproject.io/py3/redhat/8/x86_64/latest/SALTSTACK-GPG-KEY.pub
[root@minion ~]# curl -fsSL https://repo.saltproject.io/py3/redhat/8/x86_64/latest.repo | sudo tee /etc/yum.repos.d/salt.repo
[salt-latest-repo]
name=Salt repo for RHEL/CentOS 8 PY3
baseurl=https://repo.saltproject.io/py3/redhat/8/x86_64/latest
skip_if_unavailable=True
failovermethod=priority
enabled=1
enabled_metadata=1
gpgcheck=1
gpgkey=https://repo.saltproject.io/py3/redhat/8/x86_64/latest/SALTSTACK-GPG-KEY.pub
[root@minion ~]# ls /etc/yum.repos.d/
CentOS-Stream-AppStream.repo CentOS-Stream-Media.repo
CentOS-Stream-BaseOS.repo CentOS-Stream-PowerTools.repo
CentOS-Stream-Debuginfo.repo CentOS-Stream-RealTime.repo
CentOS-Stream-Extras.repo salt.repo
CentOS-Stream-HighAvailability.repo
# 安装服务salt-minion, python3-PyMySQL mariadb
[root@minion ~]# yum -y install salt-minion
....
[root@minion ~]# yum -y install python3-PyMySQL
......
# 修改配置文件
[root@minion ~]# vim /etc/salt/minion
......
15 # resolved, then the minion will fail to start.
16 #master: salt
17 master: 192.168.101.110 # IP是master的,前面有一个空格
.......
# 启动salt-minion
[root@minion ~]# systemctl start salt-minion
mariadb安装服务并配置
[root@mariadb ~]# yum -y install mariadb-server mariadb
.......
# 启动
[root@mariadb ~]# systemctl start mariadb
[root@mariadb ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
[root@mariadb ~]# 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)]> set password = password('123456');
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> exit
Bye
[root@mariadb ~]# mysql -uroot -p123456
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 '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE DATABASE `salt`
-> DEFAULT CHARACTER SET utf8
-> DEFAULT COLLATE utf8_general_ci;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| salt |
+--------------------+
4 rows in set (0.000 sec)
MariaDB [(none)]> USE `salt`;
Database changed
MariaDB [salt]> DROP TABLE IF EXISTS `jids`;
Query OK, 0 rows affected, 1 warning (0.001 sec)
MariaDB [salt]> 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.003 sec)
MariaDB [salt]> DROP TABLE IF EXISTS `salt_returns`;
Query OK, 0 rows affected, 1 warning (0.000 sec)
MariaDB [salt]> 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.003 sec)
MariaDB [salt]> DROP TABLE IF EXISTS `salt_events`;
Query OK, 0 rows affected, 1 warning (0.000 sec)
MariaDB [salt]> 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.002 sec)
# 授权访问
MariaDB [salt]> grant all on salt.* to salt@'%' identified by 'salt';
Query OK, 0 rows affected (0.000 sec)
MariaDB [salt]> flush privileges;
Query OK, 0 rows affected (0.000 sec)
minion上安装mariadb
[root@minion ~]# yum -y install mariadb
[root@minion ~]# mysql -usalt -psalt -h192.168.101.210
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
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)]>
# 修改配置文件
[root@minion ~]# vim /etc/salt/minion
#return: mysql
#
#return: mysql,slack,redis
#
#return:
# - mysql
# - hipchat
# - slack
mysql.host: '192.168.101.210'
mysql.user: 'salt'
mysql.pass: 'salt'
mysql.db: 'salt'
mysql.port: 3306
[root@minion ~]# systemctl restart salt-minion
master上ping 测试连通性
[root@master ~]# salt 'minion' test.ping
minion:
True
mariadb上查看是否有数据
[root@mariadb ~]# mysql -uroot -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
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)]> select * from salt.salt_returns;
Empty set (0.000 sec)
master上测试存储到mariadb中
[root@master ~]# salt 'minion' test.ping --return mysql
minion:
True
mariadb查看
MariaDB [(none)]> select * from salt.salt_returns\G
*************************** 1. row ***************************
fun: test.ping
jid: 20211107111209404569
return: true
id: minion
success: 1
full_ret: {"success": true, "return": true, "retcode": 0, "jid": "20211107111209404569", "fun": "test.ping", "fun_args": [], "id": "minion"}
alter_time: 2021-11-07 19:12:09
1 row in set (0.000 sec)
return时是由Minion直接与存储服务器进行交互,因此需要在每台Minion上安装指定的存储方式的模块,比如python-mysql,那么我们能否直接在Master上就把返回的结果给存储到存储服务器呢?
答案是肯定的,这种方式被称作 job cache 。意思是当Minion将结果返回给Master后,由Master将结果给缓存在本地,然后将缓存的结果给存储到指定的存储服务器,比如存储到mysql中。
master默认的存储位置
[root@master ~]# cd /var/cache/salt/master/jobs/
[root@master jobs]# ls
07 10 20 2e 37 41 47 4e 59 67 70 79 8f 9a a4 b6 c1 c9 dd e7 ef f7
08 11 23 30 38 42 48 50 5d 68 71 7d 93 9b ad b8 c3 ca df e8 f1 f9
0a 16 24 32 39 43 49 51 5e 69 72 7f 94 9e ae bb c4 d0 e0 ea f2 fa
0c 17 27 33 3a 44 4a 55 60 6b 74 82 95 a0 af bc c6 d3 e1 eb f3 fb
0e 1d 29 34 3f 45 4b 56 61 6c 75 88 96 a1 b1 be c7 d4 e2 ec f4 ff
0f 1e 2a 36 40 46 4d 58 63 6f 78 8a 98 a2 b4 c0 c8 d5 e3 ee f6
之前改的minion上的配置文件还原
[root@minion ~]# vim /etc/salt/minion
......
931 mysql.host: '192.168.101.210' # 删除添加的五行
932 mysql.user: 'salt'
933 mysql.pass: 'salt'
934 mysql.db: 'salt'
935 mysql.port: 3306
......
# 重启salt-minion服务
[root@minion ~]# systemctl restart salt-minion
master操作
开启master端的master_job_cache
[root@master ~]# yum -y install python3-PyMySQL
# 安装 python3-PyMySQL
[root@master jobs]# cd
[root@master ~]# yum -y install python3-PyMySQL
......
# 修改master的配置文件
[root@master ~]# vim /etc/salt/master
......
137 #job_cache: True
138 master_job_cache: mysql
139 mysql.host: '192.168.101.210' # mariadb主机的IP
140 mysql.user: 'salt'
141 mysql.pass: 'salt'
142 mysql.db: 'salt'
143 mysql.port: 3306
......
# 重启salt-master
[root@master ~]# systemctl restart salt-master
测试连通性
[root@master ~]# salt 'minion' test.ping
minion:
True
master安装mariadb服务
[root@master ~]# yum -y install mariadb
[root@master ~]# mysql -usalt -psalt -h192.168.101.210
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 25
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上之前的数据
MariaDB [(none)]> delete from salt.salt_returns;
Query OK, 4 rows affected (0.001 sec)
MariaDB [(none)]> select * from salt.salt_returns;
Empty set (0.000 sec)
在master上再次测试能否存储至数据库
[root@master ~]# salt 'minion' cmd.run 'df -h'
minion:
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.8G 80K 3.8G 1% /dev/shm
tmpfs 3.8G 9.7M 3.8G 1% /run
tmpfs 3.8G 0 3.8G 0% /sys/fs/cgroup
/dev/mapper/cs-root 62G 5.9G 56G 10% /
/dev/mapper/cs-home 30G 251M 30G 1% /home
/dev/sda1 1014M 243M 772M 24% /boot
tmpfs 775M 1.2M 773M 1% /run/user/42
tmpfs 775M 0 775M 0% /run/user/0
在mariadb数据库中查询
MariaDB [(none)]> select * from salt.salt_returns\G
*************************** 1. row ***************************
fun: cmd.run
jid: 20211107130618362431
return: "Filesystem Size Used Avail Use% Mounted on\ndevtmpfs 3.8G 0 3.8G 0% /dev\ntmpfs 3.8G 80K 3.8G 1% /dev/shm\ntmpfs 3.8G 9.7M 3.8G 1% /run\ntmpfs 3.8G 0 3.8G 0% /sys/fs/cgroup\n/dev/mapper/cs-root 62G 5.9G 56G 10% /\n/dev/mapper/cs-home 30G 251M 30G 1% /home\n/dev/sda1 1014M 243M 772M 24% /boot\ntmpfs 775M 1.2M 773M 1% /run/user/42\ntmpfs 775M 0 775M 0% /run/user/0"
id: minion
success: 1
full_ret: {"cmd": "_return", "id": "minion", "success": true, "return": "Filesystem Size Used Avail Use% Mounted on\ndevtmpfs 3.8G 0 3.8G 0% /dev\ntmpfs 3.8G 80K 3.8G 1% /dev/shm\ntmpfs 3.8G 9.7M 3.8G 1% /run\ntmpfs 3.8G 0 3.8G 0% /sys/fs/cgroup\n/dev/mapper/cs-root 62G 5.9G 56G 10% /\n/dev/mapper/cs-home 30G 251M 30G 1% /home\n/dev/sda1 1014M 243M 772M 24% /boot\ntmpfs 775M 1.2M 773M 1% /run/user/42\ntmpfs 775M 0 775M 0% /run/user/0", "retcode": 0, "jid": "20211107130618362431", "fun": "cmd.run", "fun_args": ["df -h"], "_stamp": "2021-11-07T13:06:18.558653"}
alter_time: 2021-11-07 21:06:18
1 row in set (0.000 sec)
Salt 0.9.7 为管理作业的saltutil引入了一些新功能。这些功能是:
running返回在proc目录中找到的所有运行作业的数据。
find_job根据工作 ID 返回有关某项工作的具体数据。
signal_job允许向给定夹具发送信号。
term_job向控制指定作业的流程发送终止信号(SIGTERM,15)。
kill_job向控制指定作业的流程发送杀伤信号(SIGKILL,9)。
获取任务的jid
[root@master ~]# salt 'minion' cmd.run 'date' -v
Executing job with jid 20211107130853049269
-------------------------------------------
minion:
Sun Nov 7 21:08:53 CST 2021
通过jid获取任务的返回结果
[root@master ~]# salt-run jobs.lookup_jid 20211107130853049269
minion:
Sun Nov 7 21:08:53 CST 2021
列出正在执行的任务,可以通过上面的 kill_job jid 杀死一个正在执行的任务
salt-run jobs.active
列出执行过的任务
salt-run jobs.list_jobs
文章浏览阅读642次。PPT内容这是htmlppt课件,关于第2章Web编程技术,包括了HTML的发展历史,HTML的基本框架,HTML的各种常用标记:文字标记、图片标记、超级链接标记,CSS的基本使用方法,如何让CSS与HTML协同工作,JavaScript中的变量、数组、表达式、运算符、流程控制语句,JavaScript的函数、内置对象、浏览器对象的层次和DOM模型的建立和使用等内容,欢迎点击下载。第2章 Web编..._html if elseppt课件
文章浏览阅读259次。您可以使用查询界面将搜索查询提交给 Solr 集合并分析结果。在下面截图中的例子中,查询已经被提交,并且界面显示了作为 JSON 形式发送到浏览器的查询结果。在这个例子中,genre:Fantasy 的查询被发送到 “films” 集合。表单中的所有其他选项都使用了默认值,下表中对此进行了简要介绍,本指南的后面部分将对此进行详细介绍。该响应显示在窗体的右侧。对 Solr 的请求只是简单的 HTTP..._solr查询界面
文章浏览阅读1.5k次,点赞65次,收藏51次。Spring请求如何传递参数详解,传递单个参数,传递多个参数,传递对象,后端参数重命名(后端参数映射),传递数组,传递集合,传递JSON数据,获取URL中参数@PathVariable,上传文件@RequestPart,获取Cooki/Session,获取Header
Android 串口开发,发送串口命令,读卡,反扫码,USB通讯,实现demo。——持续更新_androidschedulers.from(mwritethread.getlooper());-CSDN博客
Rust是一种内存安全的语言,它提供了与C语言类似的底层访问能力,但具有更强大的内存安全和并发特性。:一旦你编译了Rust代码并生成了共享库,你就可以在Python中像导入任何其他模块一样导入它,并调用你在Rust中定义的函数。通过这种方式,你可以利用Rust的强大功能和性能优势来扩展Python,同时享受到Python的易用性和丰富的生态系统。:你可以使用Cargo来构建你的Rust代码,并生成一个Python可以导入的共享库(例如。:首先,你需要在你的系统上安装Rust。,它会自动处理大部分构建配置。
音频编解码技术的目标是,通过减少音频文件的大小来节省存储空间或减轻网络传输的负担。理想的情况下,即使音频被压缩,我们听到的声音与原版也应该没有任何区别。过去,已经有不少编解码技术被开发出来,满足了这些需求,比如Opus和EVS这两种编解码器就很出名。Opus是一个多才多艺的音频编解码器,它适用于各种应用,从视频会议(比如 Google Meet)到在线视频流(比如 YouTube)。Opus支持的压缩比率非常灵活,从每秒6千比特到每秒510千比特都可以。而EVS,是由针对移动>)开发的最新编解码器。
文章浏览阅读226次。文章来源:微信公众号”沥青路面“引 言众所周知,以水泥稳定碎石为代表的半刚性材料是中国目前使用最为广泛的基层材料,因为其力学性能优良、使用成本较低、原材料来源广泛和施工工艺简单等优点,水泥稳定碎石在未来十几年内仍将是中国使用最为广泛的基层材料。目前水泥稳定碎石在设计和施工方面存在一些问题,例如室内成型方式与实际道路受力状态存在一定差异;设计指标和施工检测指标相关性不足;对矿质石料级配的要求没有体现..._无侧限抗压强度与劈裂强度的的关系
文章浏览阅读1.5k次。编者按:本文来自稀土掘金江昪编译自 Github:0x5e/wechat-deleted-friends “ 清理下[微笑],不用回。你的朋友圈没事也该清清了,打开设置,通用,功能,群助手,全选,把我的信息粘贴一下,就可以了,发送就知道谁把你删了,方便你清人,不清不知道 ,一清吓一跳。” 相信大家在微信上一定被上面的这段话刷过屏,群发消息应该算是微信上流传最广的找到删除好友的方法..._微信出现brandsessionholder
文章浏览阅读1.5k次。MySQL存储过程 游标循环的使用_存储过程 重复定义同名游标 会覆盖吗?
文章浏览阅读372次。浙江大学2003-2004学年第一学期期末考试<>课程试卷A姓名: 专业: 学号:单选题(每小题1分,共20分)1.若计算机内存中有若干个内存单元,它们的地址编号从00H到FFH,则这些内存单元总共可存放的数据数量为:( B )A.256 bitB.256 ByteC.255 KBD.255 Kb2. 计算机网络的最基本功能就是在网络中的计算机之..._浙江大学计算机科学导论连线题
汽车信息安全从2015年开始被引起重视发展至今已近10年时间,虽然有很多高屋建瓴的白皮书、指导标准可以指导我们从宏观了解汽车信息安全这个新兴行业,但真正实际需求落实到我们一线开发人员身上,总归感觉缺少点最底层的逻辑闭环。与汽车传统的主被动功能安全相比,汽车信息安全问题一旦出现可能会带来巨大影响,不仅对驾驶员、乘客的人身安全、隐私安全和财产安全造成影响,还会给车企或者供应商带来巨大经济损失,更有甚者影响国家安全(参考Tesla)。任何事物的出现都背景和根源,汽车信息安全也不例外。今天就来聊聊个人粗浅的看法。
8 空间复杂度:使用了长度为n + 1的数组dp,空间复杂度为O(n)。每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?需要 n 阶你才能到达楼顶。:有两种方法可以爬到楼顶。