Saltstack Official Galera Formula
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

190 Zeilen
4.3KB

  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. galera_log_dir:
  26. file.directory:
  27. - name: /var/log/mysql
  28. - makedirs: true
  29. - mode: 755
  30. - require:
  31. - pkg: galera_packages
  32. {%- if grains.os_family == 'Debian' %}
  33. galera_run_dir:
  34. file.directory:
  35. - name: /var/run/mysqld
  36. - makedirs: true
  37. - mode: 755
  38. - user: mysql
  39. - group: root
  40. - require:
  41. - pkg: galera_packages
  42. {%- if grains.get('init', None) == "upstart" %}
  43. galera_purge_init:
  44. file.absent:
  45. - name: /etc/init.d/mysql
  46. - require:
  47. - pkg: galera_packages
  48. galera_overide:
  49. file.managed:
  50. - name: /etc/init/mysql.override
  51. - contents: |
  52. limit nofile 102400 102400
  53. exec /usr/bin/mysqld_safe
  54. - require:
  55. - pkg: galera_packages
  56. {%- endif %}
  57. galera_conf_debian:
  58. file.managed:
  59. - name: /etc/mysql/debian.cnf
  60. - template: jinja
  61. - source: salt://galera/files/debian.cnf
  62. - mode: 640
  63. - require:
  64. - pkg: galera_packages
  65. {%- endif %}
  66. galera_init_script:
  67. file.managed:
  68. - name: /usr/local/sbin/galera_init.sh
  69. - mode: 755
  70. - source: salt://galera/files/init_bootstrap.sh
  71. - defaults:
  72. service: {{ slave|yaml }}
  73. - template: jinja
  74. galera_bootstrap_script:
  75. file.managed:
  76. - name: /usr/local/sbin/galera_bootstrap.sh
  77. - mode: 755
  78. - defaults:
  79. service: {{ slave|yaml }}
  80. - source: salt://galera/files/bootstrap.sh
  81. - template: jinja
  82. {%- if salt['cmd.run']('test -e /var/lib/mysql/.galera_bootstrap; echo $?') != '0' %}
  83. # Enforce config before package installation
  84. galera_pre_config:
  85. file.managed:
  86. - name: {{ slave.config }}
  87. - source: salt://galera/files/my.cnf.pre
  88. - mode: 644
  89. - template: jinja
  90. - makedirs: true
  91. - require_in:
  92. - pkg: galera_packages
  93. {%- if not grains.get('noservices', False) %}
  94. galera_init_start_service:
  95. cmd.run:
  96. - name: /usr/local/sbin/galera_init.sh
  97. - require:
  98. - file: galera_run_dir
  99. - file: galera_init_script
  100. galera_bootstrap_set_root_password:
  101. cmd.run:
  102. - name: mysqladmin password "{{ slave.admin.password }}"
  103. - require:
  104. - cmd: galera_init_start_service
  105. mysql_bootstrap_update_maint_password:
  106. cmd.run:
  107. - name: mysql -u root -p{{ slave.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ slave.maintenance_password }}';"
  108. - require:
  109. - cmd: galera_bootstrap_set_root_password
  110. galera_bootstrap_stop_service:
  111. service.dead:
  112. - name: {{ slave.service }}
  113. - require:
  114. - cmd: mysql_bootstrap_update_maint_password
  115. {%- endif %}
  116. galera_bootstrap_init_config:
  117. file.managed:
  118. - name: {{ slave.config }}
  119. - source: salt://galera/files/my.cnf
  120. - mode: 644
  121. - template: jinja
  122. {%- if not grains.get('noservices', False) %}
  123. - require:
  124. - service: galera_bootstrap_stop_service
  125. {%- endif %}
  126. {%- if not grains.get('noservices', False) %}
  127. galera_bootstrap_start_service_final:
  128. cmd.run:
  129. - name: /usr/local/sbin/galera_bootstrap.sh
  130. - require:
  131. - file: galera_bootstrap_init_config
  132. - file: galera_bootstrap_script
  133. galera_bootstrap_finish_flag:
  134. file.touch:
  135. - name: /var/lib/mysql/.galera_bootstrap
  136. - require:
  137. - cmd: galera_bootstrap_start_service_final
  138. - watch_in:
  139. - file: galera_config
  140. {%- endif %}
  141. {%- endif %}
  142. galera_config:
  143. file.managed:
  144. - name: {{ slave.config }}
  145. - source: salt://galera/files/my.cnf
  146. - mode: 644
  147. - template: jinja
  148. {%- if not grains.get('noservices', False) %}
  149. - require_in:
  150. - service: galera_service
  151. {%- endif %}
  152. {%- if not grains.get('noservices', False) %}
  153. galera_service:
  154. service.running:
  155. - name: {{ slave.service }}
  156. - enable: true
  157. - reload: true
  158. {%- endif %}
  159. {%- endif %}