您好,登錄后才能下訂單哦!
本文章是參照官網和網上一些資料。多數以官網為主。
首先是需要安裝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 -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配置文件 [root@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 [root@salt-minion01 ~]# /etc/init.d/salt-minion restart Stopping 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: 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、運行測試命令,然后進入數據庫查看。 [root@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成功測試。 [root@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 [root@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! [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 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]>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。