Saltstack Official Galera Formula
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

236 行
5.3KB

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