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.

133 lines
3.5KB

  1. {%- from "galera/map.jinja" import master with context %}
  2. {%- if master.enabled %}
  3. {%- if grains.os_family == 'RedHat' %}
  4. xtrabackup_repo:
  5. pkg.installed:
  6. - sources:
  7. - percona-release: {{ master.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. {%- if grains.os_family == 'Debian' %}
  22. mariadb_repo:
  23. file.managed:
  24. - name: /etc/apt/sources.list.d/mariadb_10-1.list
  25. - source: salt://galera/files/mariadb.list
  26. mariadb_key:
  27. file.managed:
  28. - name: /root/mariadb.key
  29. - source: salt://galera/files/mariadb.key
  30. - mode: 660
  31. - unless: 'apt-key list | grep mariadb'
  32. install_mariadb_key:
  33. cmd.run:
  34. - name: 'cat /root/mariadb.key | apt-key add -'
  35. - require:
  36. - file: mariadb_key
  37. - file: mariadb_repo
  38. {%- endif %}
  39. mariadb_etc_dir:
  40. file.directory:
  41. - name: /etc/mysql
  42. - makedirs: true
  43. - mode: 755
  44. mariadb-common-pkgs:
  45. pkg.installed:
  46. - names:
  47. - mariadb-common
  48. galera_bootstrap_config:
  49. file.managed:
  50. - name: {{ master.config }}
  51. - source: salt://galera/files/my.cnf.bootstrap
  52. - mode: 644
  53. - template: jinja
  54. - require:
  55. - pkg: mariadb-common-pkgs
  56. - file: mariadb_etc_dir
  57. - unless: 'mysql --user="root" --password="{{ salt['pillar.get']('galera:master:admin:password') }}" --database="mysql" --execute="show status" | grep wsrep_cluster_size | grep -E "2|3"'
  58. galera_debian_config:
  59. file.managed:
  60. - name: /etc/mysql/debian.cnf
  61. - source: salt://galera/files/debian.cnf
  62. - mode: 644
  63. - template: jinja
  64. - require:
  65. - pkg: mariadb-common-pkgs
  66. galera_packages:
  67. pkg.installed:
  68. - names: {{ master.pkgs }}
  69. - refresh: true
  70. - require:
  71. - cmd: install_mariadb_key
  72. - file: galera_bootstrap_config
  73. - file: galera_debian_config
  74. galera_log_dir:
  75. file.directory:
  76. - name: /var/log/mysql
  77. - makedirs: true
  78. - mode: 755
  79. - require:
  80. - pkg: galera_packages
  81. galera_bootstrap_start_service:
  82. service.running:
  83. - name: mysql
  84. - enable: True
  85. - require:
  86. - file: galera_bootstrap_config
  87. galera_bootstrap_set_root_password:
  88. cmd.run:
  89. - name: mysqladmin password "{{ master.admin.password }}"
  90. - require:
  91. - service: galera_bootstrap_start_service
  92. - unless: 'mysql --user="root" --password="{{ salt['pillar.get']('galera:master:admin:password') }}" --database="mysql" --execute="show tables"'
  93. mysql_bootstrap_update_maint_password:
  94. cmd.run:
  95. - name: mysql -u root -p{{ master.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ master.maintenance_password }}';"
  96. - require:
  97. - cmd: galera_bootstrap_set_root_password
  98. galera_restart_bootstrap:
  99. service.running:
  100. - name: mysql
  101. - enable: True
  102. - watch:
  103. - file: galera_normal_config
  104. galera_normal_config:
  105. file.managed:
  106. - name: /etc/mysql/my.cnf
  107. - source: salt://galera/files/my.cnf
  108. - mode: 644
  109. - template: jinja
  110. - require:
  111. - pkg: galera_packages
  112. - onlyif: 'mysql --user="root" --password="{{ salt['pillar.get']('galera:master:admin:password') }}" --database="mysql" --execute="show status" | grep wsrep_cluster_size | grep -E "2|3"'
  113. {%- endif %}