diff options
Diffstat (limited to 'deploy/adapters/ansible/roles/database')
12 files changed, 197 insertions, 142 deletions
diff --git a/deploy/adapters/ansible/roles/database/files/my.cnf b/deploy/adapters/ansible/roles/database/files/my.cnf deleted file mode 100644 index e4a23d96..00000000 --- a/deploy/adapters/ansible/roles/database/files/my.cnf +++ /dev/null @@ -1,131 +0,0 @@ -# -# The MySQL database server configuration file. -# -# You can copy this to one of: -# - "/etc/mysql/my.cnf" to set global options, -# - "~/.my.cnf" to set user-specific options. -# -# One can use all long options that the program supports. -# Run program with --help to get a list of available options and with -# --print-defaults to see which it would actually understand and use. -# -# For explanations see -# http://dev.mysql.com/doc/mysql/en/server-system-variables.html - -# This will be passed to all mysql clients -# It has been reported that passwords should be enclosed with ticks/quotes -# escpecially if they contain "#" chars... -# Remember to edit /etc/mysql/debian.cnf when changing the socket location. -[client] -port = 3306 -socket = /var/run/mysqld/mysqld.sock - -# Here is entries for some specific programs -# The following values assume you have at least 32M ram - -# This was formally known as [safe_mysqld]. Both versions are currently parsed. -[mysqld_safe] -socket = /var/run/mysqld/mysqld.sock -nice = 0 - -[mysqld] -# -# * Basic Settings -# -user = mysql -pid-file = /var/run/mysqld/mysqld.pid -socket = /var/run/mysqld/mysqld.sock -port = 3306 -basedir = /usr -datadir = /var/lib/mysql -tmpdir = /tmp -lc-messages-dir = /usr/share/mysql -skip-external-locking -# -# Instead of skip-networking the default is now to listen only on -# localhost which is more compatible and is not less secure. -bind-address = 0.0.0.0 -# -# * Fine Tuning -# -key_buffer = 16M -max_allowed_packet = 16M -thread_stack = 192K -thread_cache_size = 8 -# This replaces the startup script and checks MyISAM tables if needed -# the first time they are touched -myisam-recover = BACKUP -#max_connections = 100 -#table_cache = 64 -#thread_concurrency = 10 -# -# * Query Cache Configuration -# -query_cache_limit = 1M -query_cache_size = 16M -# -# * Logging and Replication -# -# Both location gets rotated by the cronjob. -# Be aware that this log type is a performance killer. -# As of 5.1 you can enable the log at runtime! -#general_log_file = /var/log/mysql/mysql.log -#general_log = 1 -# -# Error log - should be very few entries. -# -log_error = /var/log/mysql/error.log -# -# Here you can see queries with especially long duration -#log_slow_queries = /var/log/mysql/mysql-slow.log -#long_query_time = 2 -#log-queries-not-using-indexes -# -# The following can be used as easy to replay backup logs or for replication. -# note: if you are setting up a replication slave, see README.Debian about -# other settings you may need to change. -#server-id = 1 -#log_bin = /var/log/mysql/mysql-bin.log -expire_logs_days = 10 -max_binlog_size = 100M -#binlog_do_db = include_database_name -#binlog_ignore_db = include_database_name -# -# * InnoDB -# -# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. -# Read the manual for more InnoDB related options. There are many! -# -# * Security Features -# -# Read the manual, too, if you want chroot! -# chroot = /var/lib/mysql/ -# -# For generating SSL certificates I recommend the OpenSSL GUI "tinyca". -# -# ssl-ca=/etc/mysql/cacert.pem -# ssl-cert=/etc/mysql/server-cert.pem -# ssl-key=/etc/mysql/server-key.pem -default-storage-engine = innodb -innodb_file_per_table -collation-server = utf8_general_ci -init-connect = 'SET NAMES utf8' -character-set-server = utf8 - -[mysqldump] -quick -quote-names -max_allowed_packet = 16M - -[mysql] -#no-auto-rehash # faster start of mysql but no tab completition - -[isamchk] -key_buffer = 16M - -# -# * IMPORTANT: Additional settings that can override those from this file! -# The files must end with '.cnf', otherwise they'll be ignored. -# -!includedir /etc/mysql/conf.d/ - diff --git a/deploy/adapters/ansible/roles/database/tasks/main.yml b/deploy/adapters/ansible/roles/database/tasks/main.yml index 1918f06a..124b2639 100644 --- a/deploy/adapters/ansible/roles/database/tasks/main.yml +++ b/deploy/adapters/ansible/roles/database/tasks/main.yml @@ -8,6 +8,8 @@ ############################################################################## --- - include_vars: "{{ ansible_os_family }}.yml" + tags: + - test_mongo - include: mariadb_install.yml - include: mariadb_cluster.yml @@ -17,8 +19,13 @@ - inventory_hostname == haproxy_hosts.keys()[0] - include: mongodb_install.yml + tags: + - test_mongo + - include: mongodb_config.yml when: - inventory_hostname == haproxy_hosts.keys()[0] + tags: + - test_mongo - meta: flush_handlers diff --git a/deploy/adapters/ansible/roles/database/tasks/mariadb_cluster.yml b/deploy/adapters/ansible/roles/database/tasks/mariadb_cluster.yml index 16bbabce..84704fa4 100644 --- a/deploy/adapters/ansible/roles/database/tasks/mariadb_cluster.yml +++ b/deploy/adapters/ansible/roles/database/tasks/mariadb_cluster.yml @@ -9,3 +9,6 @@ --- - include: mariadb_cluster_debian.yml when: ansible_os_family == "Debian" + +- include: mariadb_cluster_redhat.yml + when: ansible_os_family == "RedHat" diff --git a/deploy/adapters/ansible/roles/database/tasks/mariadb_cluster_redhat.yml b/deploy/adapters/ansible/roles/database/tasks/mariadb_cluster_redhat.yml new file mode 100755 index 00000000..2fbde33b --- /dev/null +++ b/deploy/adapters/ansible/roles/database/tasks/mariadb_cluster_redhat.yml @@ -0,0 +1,37 @@ +############################################################################## +# Copyright (c) 2016 HUAWEI TECHNOLOGIES CO.,LTD and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +--- +- name: start first node to create new cluster + shell: service mysql start --wsrep-new-cluster + when: + - inventory_hostname == haproxy_hosts.keys()[0] + +- name: wait for cluster ready + command: mysql -e"show status like 'wsrep%'" + register: cluster_status + until: cluster_status|success + failed_when: not cluster_status.stdout | search("ON") + retries: 10 + delay: 3 + when: + - inventory_hostname == haproxy_hosts.keys()[0] + +- name: restart other nodes and join cluster + service: + name: mysql + state: restarted + enabled: yes + when: + - inventory_hostname != haproxy_hosts.keys()[0] + +- name: restart first nodes + service: + name: mysql + state: restarted + when: inventory_hostname == haproxy_hosts.keys()[0] and haproxy_hosts|length > 1 diff --git a/deploy/adapters/ansible/roles/database/tasks/mariadb_config.yml b/deploy/adapters/ansible/roles/database/tasks/mariadb_config.yml index d4ef6dd1..f9811dfa 100644 --- a/deploy/adapters/ansible/roles/database/tasks/mariadb_config.yml +++ b/deploy/adapters/ansible/roles/database/tasks/mariadb_config.yml @@ -8,11 +8,14 @@ ############################################################################## --- - name: create all needed db - mysql_db: name={{ item.db }} state=present + mysql_db: login_unix_socket=/var/run/mysqld/mysqld.sock name={{ item.db }} state=present with_items: "{{ credentials }}" + tags: + - test_db - name: create service db user mysql_user: + login_unix_socket=/var/run/mysqld/mysqld.sock name={{ item[0].user }} password={{ item[0].password }} priv=*.*:ALL,GRANT @@ -20,13 +23,16 @@ state=present with_nested: - "{{ credentials }}" - - ['%', 'localhost', inventory_hostname] + - ['%', 'localhost', '{{ inventory_hostname }}'] + tags: + - test_user - name: create wsrep db user mysql_user: + login_unix_socket=/var/run/mysqld/mysqld.sock name={{ WSREP_SST_USER }} password={{ WSREP_SST_PASS }} priv=*.*:ALL,GRANT host={{ item }} state=present - with_items: ['%', 'localhost', inventory_hostname] + with_items: ['%', 'localhost', '{{ inventory_hostname }}'] diff --git a/deploy/adapters/ansible/roles/database/tasks/mariadb_install.yml b/deploy/adapters/ansible/roles/database/tasks/mariadb_install.yml index 62257810..14fe1634 100644 --- a/deploy/adapters/ansible/roles/database/tasks/mariadb_install.yml +++ b/deploy/adapters/ansible/roles/database/tasks/mariadb_install.yml @@ -24,6 +24,10 @@ dest: "/etc/security/limits.conf" mode: 0755 +- name: create conf dir for wsrep + file: path=/etc/my.cnf.d state=directory mode=0755 + when: ansible_os_family == "RedHat" + - name: update mariadb config file template: src: '{{ item.src }}' diff --git a/deploy/adapters/ansible/roles/database/tasks/mongodb_install.yml b/deploy/adapters/ansible/roles/database/tasks/mongodb_install.yml index 4eb91560..dea15a83 100755 --- a/deploy/adapters/ansible/roles/database/tasks/mongodb_install.yml +++ b/deploy/adapters/ansible/roles/database/tasks/mongodb_install.yml @@ -19,17 +19,18 @@ template: src=mongodb.conf dest=/opt/os_templates backup=yes - name: update mongodb config file - shell: crudini --merge /etc/mongodb.conf < /opt/os_templates/mongodb.conf + shell: crudini --merge {{ mongodb_config.dest }} < /opt/os_templates/mongodb.conf - name: rm prealloc files file: dest: "{{ item }}" state: absent with_fileglob: - - /var/lib/mongodb/journal/* + - "{{ mongodb_config.journal }}" - name: manually restart mongodb server service: name={{ mongodb_service }} state=restarted enabled=yes + ignore_errors: true - name: write mongodb to monitor list lineinfile: dest=/opt/service create=yes line={{ mongodb_service}} diff --git a/deploy/adapters/ansible/roles/database/templates/my.cnf b/deploy/adapters/ansible/roles/database/templates/my.cnf index b8016849..68e0fca2 100644 --- a/deploy/adapters/ansible/roles/database/templates/my.cnf +++ b/deploy/adapters/ansible/roles/database/templates/my.cnf @@ -56,4 +56,4 @@ quote-names max_allowed_packet = 16M -!includedir /etc/mysql/conf.d/ +!includedir /etc/my.cnf.d/ diff --git a/deploy/adapters/ansible/roles/database/templates/my_debian.cnf b/deploy/adapters/ansible/roles/database/templates/my_debian.cnf new file mode 100644 index 00000000..b8016849 --- /dev/null +++ b/deploy/adapters/ansible/roles/database/templates/my_debian.cnf @@ -0,0 +1,59 @@ +[client] +port = 3306 +socket = /var/run/mysqld/mysqld.sock + + +[mysqld_safe] +socket = /var/run/mysqld/mysqld.sock +nice = 0 + + +[mysql] +default-character-set = utf8 + +[mysqld] +user = mysql +collation-server = utf8_unicode_ci +init-connect = 'SET NAMES utf8' +character-set-server = utf8 +datadir = /var/lib/mysql +bind-address = {{ internal_ip }} + +max-allowed-packet = 16M +max-connect-errors = 1000000 + +max_connections = {{ ansible_processor_vcpus * 100 }} + +wait_timeout = 28800 +tmp-table-size = 32M +max-heap-table-size = 32M +query-cache-type = 0 +query-cache-size = 0M +thread-cache-size = 50 +open-files-limit = 65535 +table-definition-cache = 4096 +table-open-cache = 10240 + +innodb-flush-method = O_DIRECT +innodb-additional-mem-pool-size = 24M +innodb-log-file-size = 1024M +innodb-file-per-table = 1 +innodb-buffer-pool-size = 4096M + +innodb-read-io-threads = 4 +innodb-write-io-threads = 4 +innodb-doublewrite = 1 +innodb-log-buffer-size = 1024M +innodb-buffer-pool-instances = 8 +innodb-log-files-in-group = 2 +innodb-thread-concurrency = {{ ansible_processor_vcpus * 2 }} + +innodb_stats_on_metadata = 0 + +[mysqldump] +quick +quote-names +max_allowed_packet = 16M + + +!includedir /etc/mysql/conf.d/ diff --git a/deploy/adapters/ansible/roles/database/templates/my_redhat.cnf b/deploy/adapters/ansible/roles/database/templates/my_redhat.cnf new file mode 100644 index 00000000..68e0fca2 --- /dev/null +++ b/deploy/adapters/ansible/roles/database/templates/my_redhat.cnf @@ -0,0 +1,59 @@ +[client] +port = 3306 +socket = /var/run/mysqld/mysqld.sock + + +[mysqld_safe] +socket = /var/run/mysqld/mysqld.sock +nice = 0 + + +[mysql] +default-character-set = utf8 + +[mysqld] +user = mysql +collation-server = utf8_unicode_ci +init-connect = 'SET NAMES utf8' +character-set-server = utf8 +datadir = /var/lib/mysql +bind-address = {{ internal_ip }} + +max-allowed-packet = 16M +max-connect-errors = 1000000 + +max_connections = {{ ansible_processor_vcpus * 100 }} + +wait_timeout = 28800 +tmp-table-size = 32M +max-heap-table-size = 32M +query-cache-type = 0 +query-cache-size = 0M +thread-cache-size = 50 +open-files-limit = 65535 +table-definition-cache = 4096 +table-open-cache = 10240 + +innodb-flush-method = O_DIRECT +innodb-additional-mem-pool-size = 24M +innodb-log-file-size = 1024M +innodb-file-per-table = 1 +innodb-buffer-pool-size = 4096M + +innodb-read-io-threads = 4 +innodb-write-io-threads = 4 +innodb-doublewrite = 1 +innodb-log-buffer-size = 1024M +innodb-buffer-pool-instances = 8 +innodb-log-files-in-group = 2 +innodb-thread-concurrency = {{ ansible_processor_vcpus * 2 }} + +innodb_stats_on_metadata = 0 + +[mysqldump] +quick +quote-names +max_allowed_packet = 16M + + +!includedir /etc/my.cnf.d/ diff --git a/deploy/adapters/ansible/roles/database/vars/Debian.yml b/deploy/adapters/ansible/roles/database/vars/Debian.yml index d1704385..2eefc703 100644 --- a/deploy/adapters/ansible/roles/database/vars/Debian.yml +++ b/deploy/adapters/ansible/roles/database/vars/Debian.yml @@ -30,8 +30,13 @@ services: [] mongodb_service: mongodb mysql_config: - dest: /etc/mysql/my.cnf - src: my.cnf + src: my_debian.cnf - dest: /etc/mysql/conf.d/wsrep.cnf src: wsrep.cnf +mongodb_config: + dest: /etc/mongodb.conf + src: mongodb.conf + journal: /var/lib/mongodb/journal/* + wsrep_provider_file: "/usr/lib/galera/libgalera_smm.so" diff --git a/deploy/adapters/ansible/roles/database/vars/RedHat.yml b/deploy/adapters/ansible/roles/database/vars/RedHat.yml index 0782de91..fe2d3f0a 100644 --- a/deploy/adapters/ansible/roles/database/vars/RedHat.yml +++ b/deploy/adapters/ansible/roles/database/vars/RedHat.yml @@ -27,12 +27,17 @@ pip_packages: services: [] -mongodb_service: mongodb +mongodb_service: mongod mysql_config: - - dest: /etc/mysql/my.cnf - src: my.cnf - - dest: /etc/mysql/conf.d/wsrep.cnf + - dest: /etc/my.cnf + src: my_redhat.cnf + - dest: /etc/my.cnf.d/wsrep.cnf src: wsrep.cnf +mongodb_config: + dest: /etc/mongod.conf + src: mongodb.conf + journal: /var/lib/mongo/journal/* + wsrep_provider_file: "/usr/lib64/galera/libgalera_smm.so" |