Saltstack Official Galera Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

slave.sls 5.2KB

9 년 전
8 년 전
9 년 전
9 년 전
9 년 전
9 년 전
9 년 전
9 년 전
9 년 전
9 년 전
9 년 전
9 년 전
9 년 전
9 년 전
9 년 전
9 년 전
9 년 전
9 년 전
9 년 전
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. {%- from "galera/map.jinja" import slave with context %}
  2. {%- if slave.enabled %}
  3. {%- if grains.os_family == 'RedHat' %}
  4. xtrabackup_repo:
  5. pkg.installed:
  6. - sources:
  7. - percona-release: {{ slave.xtrabackup_repo }}
  8. - require_in:
  9. - pkg: galera_packages
  10. # Workaround https://bugs.launchpad.net/percona-server/+bug/1490144
  11. xtrabackup_repo_fix:
  12. cmd.run:
  13. - name: |
  14. sed -i 's,enabled\ =\ 1,enabled\ =\ 1\nexclude\ =\ Percona-XtraDB-\*\ Percona-Server-\*,g' /etc/yum.repos.d/percona-release.repo
  15. - unless: 'grep "exclude = Percona-XtraDB-\*" /etc/yum.repos.d/percona-release.repo'
  16. - watch:
  17. - pkg: xtrabackup_repo
  18. - require_in:
  19. - pkg: galera_packages
  20. {%- endif %}
  21. galera_packages:
  22. pkg.installed:
  23. - names: {{ slave.pkgs }}
  24. - refresh: true
  25. - force_yes: True
  26. galera_log_dir:
  27. file.directory:
  28. - name: /var/log/mysql
  29. - makedirs: true
  30. - mode: 755
  31. - require:
  32. - pkg: galera_packages
  33. {%- if grains.os_family == 'Debian' %}
  34. galera_run_dir:
  35. file.directory:
  36. - name: /var/run/mysqld
  37. - makedirs: true
  38. - mode: 755
  39. - user: mysql
  40. - group: root
  41. - require:
  42. - pkg: galera_packages
  43. {%- if grains.get('init', None) == "upstart" %}
  44. galera_purge_init:
  45. file.absent:
  46. - name: /etc/init.d/mysql
  47. - require:
  48. - pkg: galera_packages
  49. galera_overide:
  50. file.managed:
  51. - name: /etc/init/mysql.override
  52. - contents: |
  53. limit nofile 102400 102400
  54. exec /usr/bin/mysqld_safe
  55. - require:
  56. - pkg: galera_packages
  57. {%- elif grains.get('init', None) == "systemd" %}
  58. galera_systemd_directory_present:
  59. file.directory:
  60. - name: /etc/systemd/system/mysql.service.d
  61. - user: root
  62. - group: root
  63. - mode: 755
  64. - require:
  65. - pkg: galera_packages
  66. galera_override_limit_no_file:
  67. file.managed:
  68. - name: /etc/systemd/system/mysql.service.d/override.conf
  69. - contents: |
  70. [Service]
  71. LimitNOFILE=1024000
  72. - require:
  73. - pkg: galera_packages
  74. - file: galera_systemd_directory_present
  75. - watch_in:
  76. - service: galera_service
  77. mysql_restart_systemd:
  78. module.wait:
  79. - name: service.systemctl_reload
  80. - watch:
  81. - file: /etc/systemd/system/mysql.service.d/override.conf
  82. - require_in:
  83. - service: galera_service
  84. {%- endif %}
  85. galera_conf_debian:
  86. file.managed:
  87. - name: /etc/mysql/debian.cnf
  88. - template: jinja
  89. - source: salt://galera/files/debian.cnf
  90. - mode: 640
  91. - require:
  92. - pkg: galera_packages
  93. {%- endif %}
  94. galera_init_script:
  95. file.managed:
  96. - name: /usr/local/sbin/galera_init.sh
  97. - mode: 755
  98. - source: salt://galera/files/init_bootstrap.sh
  99. - defaults:
  100. service: {{ slave|yaml }}
  101. - template: jinja
  102. galera_bootstrap_script:
  103. file.managed:
  104. - name: /usr/local/sbin/galera_bootstrap.sh
  105. - mode: 755
  106. - defaults:
  107. service: {{ slave|yaml }}
  108. - source: salt://galera/files/bootstrap.sh
  109. - template: jinja
  110. {%- if salt['cmd.run']('test -e /var/lib/mysql/.galera_bootstrap; echo $?') != '0' %}
  111. # Enforce config before package installation
  112. galera_pre_config:
  113. file.managed:
  114. - name: {{ slave.config }}
  115. - source: salt://galera/files/my.cnf.pre
  116. - mode: 644
  117. - template: jinja
  118. - makedirs: true
  119. - require_in:
  120. - pkg: galera_packages
  121. galera_init_start_service:
  122. cmd.run:
  123. - name: /usr/local/sbin/galera_init.sh
  124. {%- if grains.get('noservices') %}
  125. - onlyif: /bin/false
  126. {%- endif %}
  127. - require:
  128. - file: galera_run_dir
  129. - file: galera_init_script
  130. - timeout: 1800
  131. galera_bootstrap_set_root_password:
  132. cmd.run:
  133. - name: mysqladmin password "{{ slave.admin.password }}"
  134. {%- if grains.get('noservices') %}
  135. - onlyif: /bin/false
  136. {%- endif %}
  137. - require:
  138. - cmd: galera_init_start_service
  139. mysql_bootstrap_update_maint_password:
  140. cmd.run:
  141. - name: mysql -u root -p{{ slave.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ slave.maintenance_password }}';"
  142. {%- if grains.get('noservices') %}
  143. - onlyif: /bin/false
  144. {%- endif %}
  145. - require:
  146. - cmd: galera_bootstrap_set_root_password
  147. galera_bootstrap_stop_service:
  148. service.dead:
  149. - name: {{ slave.service }}
  150. {%- if grains.get('noservices') %}
  151. - onlyif: /bin/false
  152. {%- endif %}
  153. - require:
  154. - cmd: mysql_bootstrap_update_maint_password
  155. galera_bootstrap_init_config:
  156. file.managed:
  157. - name: {{ slave.config }}
  158. - source: salt://galera/files/my.cnf
  159. - mode: 644
  160. - template: jinja
  161. - require:
  162. - service: galera_bootstrap_stop_service
  163. galera_bootstrap_start_service_final:
  164. cmd.run:
  165. - name: /usr/local/sbin/galera_bootstrap.sh
  166. {%- if grains.get('noservices') %}
  167. - onlyif: /bin/false
  168. {%- endif %}
  169. - require:
  170. - file: galera_bootstrap_init_config
  171. - file: galera_bootstrap_script
  172. - timeout: 1800
  173. galera_bootstrap_finish_flag:
  174. file.touch:
  175. - name: /var/lib/mysql/.galera_bootstrap
  176. - require:
  177. - cmd: galera_bootstrap_start_service_final
  178. - watch_in:
  179. - file: galera_config
  180. {%- endif %}
  181. galera_config:
  182. file.managed:
  183. - name: {{ slave.config }}
  184. - source: salt://galera/files/my.cnf
  185. - mode: 644
  186. - template: jinja
  187. - require_in:
  188. - service: galera_service
  189. galera_service:
  190. service.running:
  191. - name: {{ slave.service }}
  192. - enable: true
  193. - reload: true
  194. {%- if grains.get('noservices') %}
  195. - onlyif: /bin/false
  196. {%- endif %}
  197. {%- endif %}