{"id":2357,"date":"2010-05-18T09:27:06","date_gmt":"2010-05-18T07:27:06","guid":{"rendered":"http:\/\/code.openark.org\/blog\/?p=2357"},"modified":"2010-05-18T19:14:44","modified_gmt":"2010-05-18T17:14:44","slug":"replication-configuration-checklist","status":"publish","type":"post","link":"https:\/\/code.openark.org\/blog\/mysql\/replication-configuration-checklist","title":{"rendered":"Replication configuration checklist"},"content":{"rendered":"<p>This post lists the essential and optional settings for a replication environment.<\/p>\n<p>It does not explain how to create replicating slaves. See <a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/replication-howto.html\">How To Setup Replication<\/a> for that. However, not all configuration options are well understood, and their roles in varying architectures can change.<\/p>\n<p>Here are the settings for a basic Master\/Slave(s) replication architecturee.<\/p>\n<h4>Essential<\/h4>\n<ul>\n<li><strong>log-bin<\/strong>: enable binary logs on the master. Replication is based on the master logging all modifying queries (<strong>INSERT<\/strong>\/<strong>CREATE<\/strong>\/<strong>ALTER<\/strong>\/<strong>GRANT<\/strong> etc.), and the slaves being able to replicate them.<\/li>\n<li><strong>server-id<\/strong>: each machine must have a <em>unique<\/em> <strong>server-id<\/strong>. A slave will not replay queries originating from a server with the same <strong>server-id<\/strong> as its own.<\/li>\n<li><strong>GRANT<\/strong>: grant a user with <strong>REPLICATION SLAVE<\/strong>. The host list must include all replication slave hosts.<\/li>\n<li><strong>expire-logs-days<\/strong>: automatically clean up master&#8217;s binary logs older than given value. By default, binary logs are never removed.<\/li>\n<\/ul>\n<p>When working with Master\/Slaves replication, one should be prepared to master failure and slave promotion to master. It may be desirable to identify a particular slave as primary candidate for promotion.<\/p>\n<p><!--more-->Just setting up the <strong>log-bin<\/strong> will yield with warnings in the MySQL&#8217;s error log. The binary logs are named, by default, after the host&#8217;s name. If that should change &#8211; MySQL will not be able to find the binary logs anymore (expecting a name which does previous logs did not use). It is therefore recommended to use:<\/p>\n<blockquote>\n<pre>log-bin=mychachine-bin<\/pre>\n<\/blockquote>\n<p>or<\/p>\n<blockquote>\n<pre>log-bin=mysql-bin<\/pre>\n<\/blockquote>\n<h4>Essential\/Optional<\/h4>\n<ul>\n<li><strong>log-bin<\/strong>: enable on a slave, so that in case it is promoted to master, the rest of the slaves can replicate using its binary logs. Enabling binary logging cannot be done on a live server: this parameter requires MySQL restart.<\/li>\n<li><strong>GRANT<\/strong>: include the master&#8217;s host, so that when a slave promotes to master, the master can become a slave and continue replicating.<\/li>\n<li><strong>log-slave-updates<\/strong>: together with <strong>log-bin<\/strong>, enable on slave so that master&#8217;s binary logs are propagated and logged by the slave. This is required if the slave takes the role of a master in a chained replication setup.<\/li>\n<li><strong>expire-logs-days<\/strong>: set this flag on slave as well [tnx Sheeri].<\/li>\n<li><strong>read-only<\/strong>: set on slave(s). Refuses any modifying query (INSERT, DELETE, ALTER, DROP etc.) for non-<strong>SUPER<\/strong> privileged users [tnx Ryan].<\/li>\n<li><strong>sync-binlog<\/strong>: flush binary log to disk per transaction commit. Use this on master for safer replication; however note that increased I\/O is expected [tnx Harrison].<\/li>\n<\/ul>\n<h4>Extra<\/h4>\n<ul>\n<li><strong>report-host<\/strong>, <strong>report-port<\/strong>: the host and port identifying the slave when looking at SHOW SLAVE HOSTS on master. Set this up on all hosts. See <a href=\"http:\/\/code.openark.org\/blog\/mysql\/the-importance-of-report_host-report_port\">further discussion here<\/a>.<\/li>\n<li><strong>max-binlog-size<\/strong>: the maximum size for a binary log \/ relay log file, after which it is rotated.<\/li>\n<\/ul>\n<h4>Expert<\/h4>\n<ul>\n<li><strong>binlog-do-db<\/strong>, <strong>binlog-do-table<\/strong>, <strong>replicate-do-db<\/strong>, <strong>&#8230;<\/strong>: filter queries by either not writing them to binary log, or not reading them from the logs.<\/li>\n<\/ul>\n<p>The reason I list the above as &#8220;Expert&#8221; is not because one must have a super-brain to set them up. That part is easy enough. But they lead to some dangerous situations, sometimes seemingly harmless. It takes great care to control the application and developers from creating those situations. See <a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/replication-rules.html\">documentation here<\/a>. See also discussion <a href=\"http:\/\/code.openark.org\/blog\/mysql\/quick-reminder-avoid-using-binlog-do-db\">here<\/a> and <a href=\"http:\/\/www.mysqlperformanceblog.com\/2009\/05\/14\/why-mysqls-binlog-do-db-option-is-dangerous\/\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post lists the essential and optional settings for a replication environment. It does not explain how to create replicating slaves. See How To Setup Replication for that. However, not all configuration options are well understood, and their roles in varying architectures can change. Here are the settings for a basic Master\/Slave(s) replication architecturee. Essential [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[5],"tags":[11,8],"class_list":["post-2357","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-configuration","tag-replication"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2bZZp-C1","_links":{"self":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/2357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/comments?post=2357"}],"version-history":[{"count":20,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/2357\/revisions"}],"predecessor-version":[{"id":2438,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/2357\/revisions\/2438"}],"wp:attachment":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/media?parent=2357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/categories?post=2357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/tags?post=2357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}