Saltstack Official Galera Formula
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

master.sls 5.3KB

9 år sedan
9 år sedan
8 år sedan
8 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. {%- from "galera/map.jinja" import master with context %}
  2. {%- if master.get('enabled', False) %}
  3. {%- if master.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: {{ master.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: {{ master.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: {{ master|yaml }}
  105. - template: jinja
  106. - timeout: 1800
  107. galera_bootstrap_script:
  108. file.managed:
  109. - name: /usr/local/sbin/galera_bootstrap.sh
  110. - mode: 755
  111. - source: salt://galera/files/bootstrap.sh
  112. - defaults:
  113. service: {{ master|yaml }}
  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: {{ master.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 "{{ master.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{{ master.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ master.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: {{ master.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: {{ master.config }}
  164. - source: salt://galera/files/my.cnf.init
  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. galera_bootstrap_finish_flag:
  179. file.touch:
  180. - name: /var/lib/mysql/.galera_bootstrap
  181. - require:
  182. - cmd: galera_bootstrap_start_service_final
  183. - watch_in:
  184. - file: galera_config
  185. {%- endif %}
  186. galera_config:
  187. file.managed:
  188. - name: {{ master.config }}
  189. - source: salt://galera/files/my.cnf
  190. - mode: 644
  191. - template: jinja
  192. - require_in:
  193. - service: galera_service
  194. galera_service:
  195. service.running:
  196. - name: {{ master.service }}
  197. - enable: true
  198. - reload: true
  199. {%- if grains.get('noservices') %}
  200. - onlyif: /bin/false
  201. {%- endif %}
  202. {%- endif %}