设为首页 收藏本站
查看: 1841|回复: 0

[经验分享] saltstack之Return data to a mysql server

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-12-15 09:00:50 | 显示全部楼层 |阅读模式
本文章是参照官网和网上一些资料。多数以官网为主。
首先是需要安装mysql数据库,我这里已经安装好了一个mysql数据库的分支叫MariaDB数据库,我就使用现成的。听说操作和mysql的操作一样。其实我就是想试试这个数据库··
依赖条件:所有minion端要安装 。
1
MySQL-python






maturity:
mature
depends:
python-mysqldb
platform:
all
PS:内容有点乱,写作水平也有限,不过这都是我的操作过程,用来记录一番,同时希望能给大家带来参考。
三个主要步骤:
1、创建数据库和表
2、修改minion配置文件指向mysql数据库
3、测试以及查看数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
1、登录数据库,创建一个salt数据库,三个表:jids、salt_returns、salt_events
[iyunv@salt-master ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 360
Server version: 5.5.50-MariaDB MariaDB Server

Copyright (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 changed
MariaDB [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配置文件
[iyunv@salt-minion01 ~]# vim /etc/salt/minion
######      Returner  settings        ######
############################################
# Which returner(s) will be used for minion's result:
#return: mysql
mysql.host: '10.0.0.177'                  #我的master主机ip地址
mysql.user: 'salt'
mysql.pass: 'salt'
mysql.db: 'salt'
mysql.port: 3306

[iyunv@salt-minion01 ~]# /etc/init.d/salt-minion restart
Stopping salt-minion daemon:                               [  OK  ]
Starting salt-minion daemon:                               [  OK  ]


5、差点忘记安装依赖条件了,安装依赖条件。没有安装成功,和python版本有关,请大家自行寻找,我先第六步试试看,
[iyunv@salt-master ~]# yum install MySQLdb -y
[iyunv@salt-minion01 ~]#  yum install mysql-python -y     
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirrors.zju.edu.cn
* epel: mirror01.idc.hinet.net
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
No package mysql-python available.
  * Maybe you meant: MySQL-python
Error: Nothing to do
6、运行测试命令,然后进入数据库查看。
[iyunv@salt-master ~]# salt '*' test.ping --return mysql
salt-master:
    True
salt-minion01:
    True
hddcluster1:
    True
hddcluster4:
    True
hddcluster2:
    True
hddcluster3:
    True


#注意:下面id:salt-master  是因为我上面没有安装成功mysql-python,后来我在master端的minion安装mysql-python成功测试。
[iyunv@salt-master ~]# mysql -u root -p                 
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 367
Server version: 5.5.50-MariaDB MariaDB Server

Copyright (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 names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [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
[iyunv@salt-minion01 ~]# yum install MySQL-python
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirrors.zju.edu.cn
* epel: mirror01.idc.hinet.net
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
Resolving Dependencies
There 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 Resolution

Dependencies Resolved

=====================================================================================
Package              Arch           Version                      Repository    Size
=====================================================================================
Installing:
MySQL-python         x86_64         1.2.3-0.3.c1.1.el6           base          86 k

Transaction Summary
=====================================================================================
Install       1 Package(s)

Total download size: 86 k
Installed size: 246 k
Is this ok [y/N]: y
Downloading Packages:
MySQL-python-1.2.3-0.3.c1.1.el6.x86_64.rpm                    |  86 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running 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!
[iyunv@salt-minion01 ~]#


8、再次测试命令,查看数据库。
[iyunv@salt-master ~]# salt 'salt-minion01' test.ping --return mysql
salt-minion01:
    True
[iyunv@salt-master ~]# mysql -u root -p                             
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 370
Server version: 5.5.50-MariaDB MariaDB Server

Copyright (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 names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [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]>



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-314488-1-1.html 上篇帖子: 配置管理工具Saltstack 之 自定义grains 下篇帖子: (一)slatstack简介与安装 server mysql
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表