1. 程式人生 > >SaltStack – Using the Mysql Module

SaltStack – Using the Mysql Module

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

[[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

本文出自 “要有夢想,萬一實現了呢” 博客,謝絕轉載!

SaltStack – Using the Mysql Module