本文章是参照官网和网上一些资料。多数以官网为主。

首先是需要安装mysql数据库,我这里已经安装好了一个mysql数据库的分支叫MariaDB数据库,我就使用现成的。听说操作和mysql的操作一样。其实我就是想试试这个数据库··

依赖条件:所有minion端要安装 。

MySQL-python


maturity:maturedepends:python-mysqldbplatform:allPS:内容有点乱,写作水平也有限,不过这都是我的操作过程,用来记录一番,同时希望能给大家带来参考。

三个主要步骤:

1、创建数据库和表

2、修改minion配置文件指向mysql数据库

3、测试以及查看数据库


1、登录数据库,创建一个salt数据库,三个表:jids、salt_returns、salt_events[root@salt-master~]#mysql-uroot-pEnterpassword:WelcometotheMariaDBmonitor.Commandsendwith;or\g.YourMariaDBconnectionidis360Serverversion:5.5.50-MariaDBMariaDBServerCopyright(c)2000,2016,Oracle,MariaDBCorporationAbandothers.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.MariaDB[(none)]>CREATEDATABASE`salt`->DEFAULTCHARACTERSETutf8->DEFAULTCOLLATEutf8_general_ci;QueryOK,1rowaffected(0.00sec)MariaDB[(none)]>USE`salt`;DatabasechangedMariaDB[salt]>DROPTABLEIFEXISTS`jids`;QueryOK,0rowsaffected,1warning(0.00sec)MariaDB[salt]>CREATETABLE`jids`(->`jid`varchar(255)NOTNULL,->`load`mediumtextNOTNULL,->UNIQUEKEY`jid`(`jid`)->)ENGINE=InnoDBDEFAULTCHARSET=utf8;QueryOK,0rowsaffected(0.04sec)MariaDB[salt]>CREATEINDEXjidONjids(jid)USINGBTREE;ERROR1061(42000):Duplicatekeyname'jid'MariaDB[salt]>CREATEINDEXjidONjids(jid)USINGBTREE;ERROR1061(42000):Duplicatekeyname'jid'MariaDB[salt]>CREATETABLE`salt_returns`(->`fun`varchar(50)NOTNULL,->`jid`varchar(255)NOTNULL,->`return`mediumtextNOTNULL,->`id`varchar(255)NOTNULL,->`success`varchar(10)NOTNULL,->`full_ret`mediumtextNOTNULL,->`alter_time`TIMESTAMPDEFAULTCURRENT_TIMESTAMP,->KEY`id`(`id`),->KEY`jid`(`jid`),->KEY`fun`(`fun`)->)ENGINE=InnoDBDEFAULTCHARSET=utf8;QueryOK,0rowsaffected(0.04sec)MariaDB[salt]>DROPTABLEIFEXISTS`salt_events`;QueryOK,0rowsaffected,1warning(0.01sec)MariaDB[salt]>CREATETABLE`salt_events`(->`id`BIGINTNOTNULLAUTO_INCREMENT,->`tag`varchar(255)NOTNULL,->`data`mediumtextNOTNULL,->`alter_time`TIMESTAMPDEFAULTCURRENT_TIMESTAMP,->`master_id`varchar(255)NOTNULL,->PRIMARYKEY(`id`),->KEY`tag`(`tag`)->)ENGINE=InnoDBDEFAULTCHARSET=utf8;QueryOK,0rowsaffected(0.05sec)创建数据库完毕!2、开始查看一下数据表,三个没错。MariaDB[salt]>showtables->;+----------------+|Tables_in_salt|+----------------+|jids||salt_events||salt_returns|+----------------+3rowsinset(0.00sec)MariaDB[salt]>select*fromsalt_returns;Emptyset(0.00sec)3、给数据库授权,官网竟然没有说,差点漏了MariaDB[salt]>grantallonsalt.*tosalt@'%'identifiedby'salt';QueryOK,0rowsaffected(0.00sec)MariaDB[salt]>flushprivileges;QueryOK,0rowsaffected(0.01sec)MariaDB[salt]>4、修改minion配置文件[root@salt-minion01~]#vim/etc/salt/minion######Returnersettings###################################################Whichreturner(s)willbeusedforminion'sresult:#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-minionrestartStoppingsalt-miniondaemon:[OK]Startingsalt-miniondaemon:[OK]5、差点忘记安装依赖条件了,安装依赖条件。没有安装成功,和python版本有关,请大家自行寻找,我先第六步试试看,[root@salt-master~]#yuminstallMySQLdb-y[root@salt-minion01~]#yuminstallmysql-python-yLoadedplugins:fastestmirrorSettingupInstallProcessLoadingmirrorspeedsfromcachedhostfile*base:mirrors.zju.edu.cn*epel:mirror01.idc.hinet.net*extras:centos.ustc.edu.cn*updates:centos.ustc.edu.cnNopackagemysql-pythonavailable.*Maybeyoumeant:MySQL-pythonError:Nothingtodo6、运行测试命令,然后进入数据库查看。[root@salt-master~]#salt'*'test.ping--returnmysqlsalt-master:Truesalt-minion01:Truehddcluster1:Truehddcluster4:Truehddcluster2:Truehddcluster3:True#注意:下面id:salt-master是因为我上面没有安装成功mysql-python,后来我在master端的minion安装mysql-python成功测试。[root@salt-master~]#mysql-uroot-pEnterpassword:WelcometotheMariaDBmonitor.Commandsendwith;or\g.YourMariaDBconnectionidis367Serverversion:5.5.50-MariaDBMariaDBServerCopyright(c)2000,2016,Oracle,MariaDBCorporationAbandothers.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.MariaDB[(none)]>usesalt;ReadingtableinformationforcompletionoftableandcolumnnamesYoucanturnoffthisfeaturetogetaquickerstartupwith-ADatabasechangedMariaDB[salt]>select*fromsalt_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-1417:19:54|+-----------+----------------------+--------+-------------+---------+-----------------------------------------------------------------------------------------------------------------------------------------+---------------------+1rowinset(0.00sec)MariaDB[salt]>7、终于找到了包的名字是MySQL-python[root@salt-minion01~]#yuminstallMySQL-pythonLoadedplugins:fastestmirrorSettingupInstallProcessLoadingmirrorspeedsfromcachedhostfile*base:mirrors.zju.edu.cn*epel:mirror01.idc.hinet.net*extras:centos.ustc.edu.cn*updates:centos.ustc.edu.cnResolvingDependenciesThereareunfinishedtransactionsremaining.Youmightconsiderrunningyum-complete-transactionfirsttofinishthem.-->Runningtransactioncheck--->PackageMySQL-python.x86_640:1.2.3-0.3.c1.1.el6willbeinstalled-->FinishedDependencyResolutionDependenciesResolved=====================================================================================PackageArchVersionRepositorySize=====================================================================================Installing:MySQL-pythonx86_641.2.3-0.3.c1.1.el6base86kTransactionSummary=====================================================================================Install1Package(s)Totaldownloadsize:86kInstalledsize:246kIsthisok[y/N]:yDownloadingPackages:MySQL-python-1.2.3-0.3.c1.1.el6.x86_64.rpm|86kB00:00Runningrpm_check_debugRunningTransactionTestTransactionTestSucceededRunningTransactionInstalling:MySQL-python-1.2.3-0.3.c1.1.el6.x86_641/1Verifying:MySQL-python-1.2.3-0.3.c1.1.el6.x86_641/1Installed:MySQL-python.x86_640:1.2.3-0.3.c1.1.el6Complete![root@salt-minion01~]#8、再次测试命令,查看数据库。[root@salt-master~]#salt'salt-minion01'test.ping--returnmysqlsalt-minion01:True[root@salt-master~]#mysql-uroot-pEnterpassword:WelcometotheMariaDBmonitor.Commandsendwith;or\g.YourMariaDBconnectionidis370Serverversion:5.5.50-MariaDBMariaDBServerCopyright(c)2000,2016,Oracle,MariaDBCorporationAbandothers.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.MariaDB[(none)]>usesalt;ReadingtableinformationforcompletionoftableandcolumnnamesYoucanturnoffthisfeaturetogetaquickerstartupwith-ADatabasechangedMariaDB[salt]>select*fromsalt_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-1417: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-1417:28:41|+-----------+----------------------+--------+---------------+---------+-------------------------------------------------------------------------------------------------------------------------------------------+---------------------+2rowsinset(0.00sec)MariaDB[salt]>