1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | { "name": "test", "description": "", "cookbook_versions": { }, "json_class": "Chef::Environment", "chef_type": "environment", "default_attributes": { "mariadb-galera-cluster": { "cluster": { "members": { "nodeA": "10.0.0.11", "nodeB": "10.0.0.12" }, "master": "nodeA" } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | node['mariadbp4']['cluster']['members'].each_pair do |name, ip| bash "Resolve #{name} to #{ip}." do user "root" group "root" code <<-EOF name=#{name} echo "#{ip} ${name%%.*} $name" >> /etc/hosts EOF not_if "[ #{name} == `hostname -s` ]" end end bash "Open ports on OS firewall" user "root" group "root" code <<-EOF firewall-cmd --zone=public --add-service=mariadb --permanent firewall-cmd --zone=public --add-port=3306/tcp --permanent firewall-cmd --zone=public --add-port=4567/tcp --permanent firewall-cmd --zone=public --add-port=4568/tcp --permanent firewall-cmd --zone=public --add-port=4444/tcp --permanent firewall-cmd --zone=public --add-port=4567/udp --permanent firewall-cmd --reload EOF end |
1 2 3 4 5 6 7 8 | [galera] wsrep_on=ON wsrep_provider=/usr/lib64/galera/libgalera_smm.so wsrep_cluster_address=gcomm://<%= @node.mariadbp4.cluster.members.keys.join(',') %> binlog_format=row default_storage_engine=InnoDB innodb_autoinc_lock_mode=2 bind-address=0.0.0.0 |
1 2 3 4 5 6 7 | template "/etc/my.cnf.d/server.cnf" do source "server.cnf.erb" owner "root" mode 0644 action :create not_if "grep '^wsrep_on=ON' /etc/my.cnf.d/server.cnf" end |
1 2 3 | [Service] ExecStart= ExecStart=/usr/sbin/mysqld --wsrep-new-cluster |
1 2 3 | [Service] ExecStart= ExecStart=/usr/sbin/mysqld --wsrep_cluster_address=gcomm://<%= node.mariadbp4.cluster.master =%> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | master=node['mariadbp4']['cluster']['master'] bash "Add cluster conf for mariadb service in systemd and restart service..." do cwd "/etc/systemd/system" user "root" code <<-EOF if [ ! -d "$service_name.d" ]; then mkdir "mariadb.service.d" fi if [ `hostname -s` == #{master} ]; then mv /tmp/master.conf mariadb.service.d/cluster.conf else mv /tmp/slave.conf mariadb.service.d/cluster.conf fi systemctl daemon-reload systemctl restart $service_name EOF not_if "[[ -f mysql.service.d/cluster.conf || -f mariadb.service.d/cluster.conf ]]" end |
1 2 3 4 | knife cookbook upload -a -o . knife environment from file environments/test.json knife bootstrap 10.0.0.11 -x root -P password -r "recipe[mariadb-galera-cluster]" -E test knife bootstrap 10.0.0.12 -x root -P password -r "recipe[mariadb-galera-cluster]" -E test |
1 2 | mysql --user=root --password=xxx show status like 'wsrep_%' |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |