saltstack之Return data to a mysql server
发表于:2025-01-22 作者:千家信息网编辑
千家信息网最后更新 2025年01月22日,本文章是参照官网和网上一些资料。多数以官网为主。首先是需要安装mysql数据库,我这里已经安装好了一个mysql数据库的分支叫MariaDB数据库,我就使用现成的。听说操作和mysql的操作一样。其实
千家信息网最后更新 2025年01月22日saltstack之Return data to a mysql server
PS:内容有点乱,写作水平也有限,不过这都是我的操作过程,用来记录一番,同时希望能给大家带来参考。
本文章是参照官网和网上一些资料。多数以官网为主。
首先是需要安装mysql数据库,我这里已经安装好了一个mysql数据库的分支叫MariaDB数据库,我就使用现成的。听说操作和mysql的操作一样。其实我就是想试试这个数据库··
依赖条件:所有minion端要安装 。
MySQL-python
maturity: | mature |
---|---|
depends: | python-mysqldb |
platform: | all |
三个主要步骤:
1、创建数据库和表
2、修改minion配置文件指向mysql数据库
3、测试以及查看数据库
1、登录数据库,创建一个salt数据库,三个表:jids、salt_returns、salt_events[root@salt-master ~]# mysql -u root -pEnter password: Welcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 360Server version: 5.5.50-MariaDB MariaDB ServerCopyright (c) 2000, 2016, 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.00 sec)MariaDB [(none)]> USE `salt`;Database changedMariaDB [salt]> DROP TABLE IF EXISTS `jids`;Query OK, 0 rows affected, 1 warning (0.00 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.04 sec)MariaDB [salt]> CREATE INDEX jid ON jids(jid) USING BTREE;ERROR 1061 (42000): Duplicate key name 'jid'MariaDB [salt]> CREATE INDEX jid ON jids(jid) USING BTREE;ERROR 1061 (42000): Duplicate key name 'jid'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.04 sec)MariaDB [salt]> DROP TABLE IF EXISTS `salt_events`;Query OK, 0 rows affected, 1 warning (0.01 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.05 sec)创建数据库完毕!2、开始查看一下数据表,三个没错。MariaDB [salt]> show tables -> ;+----------------+| Tables_in_salt |+----------------+| jids || salt_events || salt_returns |+----------------+3 rows in set (0.00 sec)MariaDB [salt]> select * from salt_returns;Empty set (0.00 sec)3、给数据库授权,官网竟然没有说,差点漏了MariaDB [salt]> grant all on salt.* to salt@'%' identified by 'salt';Query OK, 0 rows affected (0.00 sec)MariaDB [salt]> flush privileges;Query OK, 0 rows affected (0.01 sec)MariaDB [salt]>4、修改minion配置文件[root@salt-minion01 ~]# vim /etc/salt/minion###### Returner settings ################################################### Which returner(s) will be used for minion's result:#return: mysqlmysql.host: '10.0.0.177' #我的master主机ip地址mysql.user: 'salt'mysql.pass: 'salt'mysql.db: 'salt'mysql.port: 3306[root@salt-minion01 ~]# /etc/init.d/salt-minion restartStopping salt-minion daemon: [ OK ]Starting salt-minion daemon: [ OK ]5、差点忘记安装依赖条件了,安装依赖条件。没有安装成功,和python版本有关,请大家自行寻找,我先第六步试试看,[root@salt-master ~]# yum install MySQLdb -y[root@salt-minion01 ~]# yum install mysql-python -y Loaded plugins: fastestmirrorSetting up Install ProcessLoading mirror speeds from cached hostfile * base: mirrors.zju.edu.cn * epel: mirror01.idc.hinet.net * extras: centos.ustc.edu.cn * updates: centos.ustc.edu.cnNo package mysql-python available. * Maybe you meant: MySQL-pythonError: Nothing to do6、运行测试命令,然后进入数据库查看。[root@salt-master ~]# salt '*' test.ping --return mysqlsalt-master: Truesalt-minion01: Truehddcluster1: Truehddcluster4: Truehddcluster2: Truehddcluster3: True#注意:下面id:salt-master 是因为我上面没有安装成功mysql-python,后来我在master端的minion安装mysql-python成功测试。[root@salt-master ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 367Server version: 5.5.50-MariaDB MariaDB ServerCopyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> use salt; Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedMariaDB [salt]> select * from salt_returns;+-----------+----------------------+--------+-------------+---------+-----------------------------------------------------------------------------------------------------------------------------------------+---------------------+| fun | jid | return | id | success | full_ret | alter_time |+-----------+----------------------+--------+-------------+---------+-----------------------------------------------------------------------------------------------------------------------------------------+---------------------+| test.ping | 20161214171944749902 | true | salt-master | 1 | {"fun_args": [], "jid": "20161214171944749902", "return": true, "retcode": 0, "success": true, "fun": "test.ping", "id": "salt-master"} | 2016-12-14 17:19:54 |+-----------+----------------------+--------+-------------+---------+-----------------------------------------------------------------------------------------------------------------------------------------+---------------------+1 row in set (0.00 sec)MariaDB [salt]> 7、终于找到了包的名字是MySQL-python[root@salt-minion01 ~]# yum install MySQL-pythonLoaded plugins: fastestmirrorSetting up Install ProcessLoading mirror speeds from cached hostfile * base: mirrors.zju.edu.cn * epel: mirror01.idc.hinet.net * extras: centos.ustc.edu.cn * updates: centos.ustc.edu.cnResolving DependenciesThere are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.--> Running transaction check---> Package MySQL-python.x86_64 0:1.2.3-0.3.c1.1.el6 will be installed--> Finished Dependency ResolutionDependencies Resolved===================================================================================== Package Arch Version Repository Size=====================================================================================Installing: MySQL-python x86_64 1.2.3-0.3.c1.1.el6 base 86 kTransaction Summary=====================================================================================Install 1 Package(s)Total download size: 86 kInstalled size: 246 kIs this ok [y/N]: yDownloading Packages:MySQL-python-1.2.3-0.3.c1.1.el6.x86_64.rpm | 86 kB 00:00 Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning Transaction Installing : MySQL-python-1.2.3-0.3.c1.1.el6.x86_64 1/1 Verifying : MySQL-python-1.2.3-0.3.c1.1.el6.x86_64 1/1 Installed: MySQL-python.x86_64 0:1.2.3-0.3.c1.1.el6 Complete![root@salt-minion01 ~]# 8、再次测试命令,查看数据库。[root@salt-master ~]# salt 'salt-minion01' test.ping --return mysql salt-minion01: True[root@salt-master ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 370Server version: 5.5.50-MariaDB MariaDB ServerCopyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> use salt; Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedMariaDB [salt]> select * from salt_returns;+-----------+----------------------+--------+---------------+---------+-------------------------------------------------------------------------------------------------------------------------------------------+---------------------+| fun | jid | return | id | success | full_ret | alter_time |+-----------+----------------------+--------+---------------+---------+-------------------------------------------------------------------------------------------------------------------------------------------+---------------------+| test.ping | 20161214171944749902 | true | salt-master | 1 | {"fun_args": [], "jid": "20161214171944749902", "return": true, "retcode": 0, "success": true, "fun": "test.ping", "id": "salt-master"} | 2016-12-14 17:19:54 || test.ping | 20161214172841623449 | true | salt-minion01 | 1 | {"fun_args": [], "jid": "20161214172841623449", "return": true, "retcode": 0, "success": true, "fun": "test.ping", "id": "salt-minion01"} | 2016-12-14 17:28:41 |+-----------+----------------------+--------+---------------+---------+-------------------------------------------------------------------------------------------------------------------------------------------+---------------------+2 rows in set (0.00 sec)MariaDB [salt]>
数据
数据库
测试
成功
三个
条件
命令
文件
配置
主机
内容
再次
分支
同时
名字
地址
就是
指向
数据表
有限
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
安全数据库和通用数据库
二手服务器能打游戏吗
网络安全学习心得感悟
用数据库语言求和1到10
软件开发感兴趣的研究课题
湖南统一软件开发过程检测中心
洪山区营销网络安全维护条件
土地节约评价数据库
数据库型网站
怎么在数据库中快速查找函数
华南理工大学计算机网络安全视频
网络安全培训心得
梦幻西游姑苏城服务器
及网络安全与防范论文致谢
部队网络安全保密教案方案
嵌入式软件开发区美食图片
软件开发培训学校中口大
数据库按天统计
放逐顽徒的手套数据库
更戛乡网络安全事件报告制度
我国网络安全怎么样
微信机器人平台软件开发
阿里巴巴网络安全官
西安锐图软件开发公司
湖北物资管理软件开发平台
用显卡架设游戏服务器
网络技术售后
网络安全产品部
确定数据库的存储结构
erp实施到软件开发