码迷,mamicode.com
首页 > 数据库 > 详细

SaltStack – Using the Mysql Module

时间:2017-05-25 22:11:36      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:saltstack

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

[root@cm1 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:

  ‘G@env:dev and G@role:dbserver‘:

    - match: compound

    - dev.mysql


  ‘G@env:stage and G@role:dbserver‘:

    - match: compound

    - stage.mysql


  ‘G@env:prod and G@role: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

本文出自 “要有梦想,万一实现了呢” 博客,谢绝转载!

SaltStack – Using the Mysql Module

标签:saltstack

原文地址:http://szgb17.blog.51cto.com/340201/1929487

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!