SaltStack – Using the Mysql Module

salt ‘*‘ saltutil.refresh_pillar

官网的例子真的没看懂,英文菜。其实就简单一步。

参考文档

https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.mysql.html

https://z900collector.wordpress.com/linux/using-the-saltstack-mysql-module/

salt-master主要是找/usr/lib/python2.6/site-packages/salt/modules/test.py

[[email protected] salt]# cat /etc/salt/minion

master: 172.1.1.1

id: cm1

mysql.host: ‘localhost‘

mysql.port: 3306

mysql.user: ‘root‘

mysql.socket: ‘x.sock‘

mysql.pass: ‘xx‘

mysql.charset: ‘utf8‘

/etc/init.d/salt-minion restart

‘‘‘

执行顺序,测试命令

state.show_sls执行函数来查看salt state的执行顺序

sudo salt stage-db1 state.show_sls mysql

sudo salt stage-db1 state.apply mysql test=True

sudo salt stage-db1 state.apply mysql

mysql

sudo salt stage-db1 mysql.db_list

‘‘‘

salt ‘*‘ mysql.db_list

最完整的例子

https://www.digitalocean.com/community/tutorials/saltstack-infrastructure-creating-salt-states-for-mysql-database-servers

1.salt-minion端

mysql连接信息 /etc/salt/minion.d/mysql.conf

mysql.default_file: ‘/etc/mysql/salt.cnf‘

vim /etc/mysql/salt.cnf

mysql.host: ‘localhost‘

mysql.port: 3306

mysql.user: ‘root‘

mysql.socket: ‘x.sock‘

mysql.pass: ‘xx‘

mysql.charset: ‘utf8‘

2.vim /srv/pillar/top.sls

base:

‘[email protected]:dev and [email protected]:dbserver‘:

- match: compound

- dev.mysql

‘[email protected]:stage and [email protected]:dbserver‘:

- match: compound

- stage.mysql

‘[email protected]:prod and [email protected]:dbserver‘:

- match: compound

- prod.mysql

3.vim /srv/salt/mysql/init.sls

debconf-utils:

pkg.installed

mysql_setup:

debconf.set:

- name: mysql-server

- data:

‘mysql-server/root_password‘: {‘type‘: ‘password‘, ‘value‘: ‘{{ salt[‘pillar.get‘](‘mysql:root_pw‘, ‘‘) }}‘ }

‘mysql-server/root_password_again‘: {‘type‘: ‘password‘, ‘value‘: ‘{{ salt[‘pillar.get‘](‘mysql:root_pw‘, ‘‘) }}‘ }

- require:

- pkg: debconf-utils

python-mysqldb:

pkg.installed

mysql-server:

pkg.installed:

- require:

- debconf: mysql-server

- pkg: python-mysqldb

mysql:

service.running:

- watch:

- pkg: mysql-server

- file: /etc/mysql/my.cnf

mysql:

service.running:

- watch:

- pkg: mysql-server

- file: /etc/mysql/my.cnf

/etc/mysql/my.cnf:

file.managed:

- source: salt://mysql/files/etc/mysql/my.cnf.jinja

- template: jinja

- user: root

- group: root

- mode: 640

- require:

- pkg: mysql-server

/etc/salt/minion.d/mysql.conf:

file.managed:

- source: salt://mysql/files/etc/salt/minion.d/mysql.conf

- user: root

- group: root

- mode: 640

- require:

- service: mysql

/etc/mysql/salt.cnf:

file.managed:

- source: salt://mysql/files/etc/mysql/salt.cnf.jinja

- template: jinja

- user: root

- group: root

- mode: 640

- require:

- service: mysql

restart_minion_for_mysql:

service.running:

- name: salt-minion

- watch:

- file: /etc/salt/minion.d/mysql.conf

上面是digitoean云上的例子。最重要的是/etc/salt/minion.d

时间: 2024-12-08 21:38:02

SaltStack – Using the Mysql Module的相关文章

percona innobackupex 遇到 connect to MySQL server as DBD::mysql module is not installed 问题

percona innobackupex connect to MySQL server as DBD::mysql module is not installed [[email protected] software]# innobackupex --user=root --password=123456 /data/backup/ InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy and Pe

SaltStack工具中MySQL的模块返回值问题解决

由于管理系统中对mysql管理的开发中用到了saltstack集成的mysql模块其中一个主要的功能是 mysql.query 官方文档中的两个示例: salt.modules.mysql.query(database, query, **connection_args) Run an arbitrary SQL query and return the results or the number of affected rows. CLI Example: salt '*' mysql.que

saltstack (4) 用mysql存储 salt 返回值

Salt返回接收器(returner)允许把minion的响应保存在各种数据存储或不同的位置,甚至把响应内容显示在命令行.Returner可以用来扩展Salt,和新的.定制的接口和支持新的数据库进行通信.本例用mysql存储salt返回值 操作如下: [[email protected] ~]# yum -y install mysql-connector-python [[email protected] ~]# yum -y install MySQL-python27 [[email pr

SaltStack 与 Python 程序的结合

SaltStack 库中的 Modules: 在 SaltStack 中,每个子系统插件(plug-in)都是一个 Python Module.因此,SaltStack 库中的 Module 可以看作是一组 functions(例如:aka 命令):可以看作是一个应用(例如:mysql.docker):可以看作是一个系统组件(例如:disk.file):还可以看作是一个外部系统(gitfs). 使用 SaltStack 库中的 Modules 需要注意以下几点: (1).所有的模块都在 salt

How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu

About LAMP LAMP stack is a group of open source software used to get web servers up and running. The acronym stands for Linux, Apache, MySQL, and PHP. Since the virtual private server is already running Ubuntu, the linux part is taken care of. Here i

saltstack学习笔记9-JOB

saltstack里面执行任何一个操作都会在master上产生一个jid号,就像上一节存储到redis上的数据显示的一样 ./redis-cli monitor OK 1461054358.412376 [0 127.0.0.1:58564] "SELECT" "0" 1461054358.412717 [0 127.0.0.1:58564] "SET" "minion1:20160419162558137768" "

mysql之 percona-xtrabackup 2.4.7安装(热备工具)

准备:os是centos6.7,提前下载并上传 percona-xtrabackup 安装包,下载网址为: https://www.percona.com/downloads/XtraBackup/LATEST/1.安装依赖包[[email protected] xtrabackup]# yum -y install perl perl-devel libaio libaio-devel perl-Time-HiRes perl-DBD-MySQL Dependency Installed: 

jbpm6.2 installer 使用mysql

所需环境 JDK1.6+,Ant1.7+ 本文实验环境 JDK1.8.0_51,Ant1.9.6 1. 解压instller-full:jbpm-6.2.0.Final-installer-full\jbpm-installer 2. 将eclipse-java-kepler-SR2-win32.zip拷贝到跟目录lib下:jbpm-6.2.0.Final-installer-full\jbpm-installer\lib--默认不存在此文件不拷贝的话后续运行时会自动下载,可以不拷贝. 3. 将

Xtrabackup之innobackupex在线热备mysql数据库

XtraBackup简介 Xtrabackup是一个对InnoDB做数据备份的工具,支持在线热备份(备份时不影响数据读写),是商业备份工具InnoDB Hotbackup的一个很好的替代品. Xtrabackup有两个主要的工具:xtrabackup.innobackupex (1)xtrabackup只能备份InnoDB和XtraDB两种数据表,而不能备份MyISAM数据表 (2)innobackupex-1.5.1则封装了xtrabackup,是一个脚本封装,所以能同时备份处理innodb和