{"id":1694,"date":"2016-03-30T19:47:47","date_gmt":"2016-03-30T23:47:47","guid":{"rendered":"http:\/\/blog-dev.bezko.xyz\/?p=1694"},"modified":"2018-01-12T14:00:00","modified_gmt":"2018-01-12T19:00:00","slug":"how-to-install-galera-on-ubuntu-14-04-lts","status":"publish","type":"post","link":"https:\/\/www.globo.tech\/learning-center\/how-to-install-galera-on-ubuntu-14-04-lts\/","title":{"rendered":"How to install Galera on Ubuntu 14.04"},"content":{"rendered":"<h1>How to install Galera on Ubuntu 14.04<\/h1>\n<p>Galera Cluster is a plugin for MySQL which enables the Galera replication engine and lets you replicate your databases between servers in a synchronous master-master manner. It requires the InnoDB database engine to be set as default for all replicated databases. It&#8217;s strongly recommended to run an odd number of Galera nodes to keep a healthy quorum. While there are MariaDB and Percona XtraDB version, we will cover the default MySQL installation in this tutorial.<\/p>\n<h2>Getting Started<\/h2>\n<p>\u2022 3(<a href=\"https:\/\/www.globo.tech\/cloud-server-pricing\" target=\"_blank\">Cloud Instances<\/a> or <a href=\"http:\/\/www.globo.tech\/dedicated-server-hosting\" target=\"_blank\">Dedicated Servers<\/a>) (which we will call &#8220;Nodes&#8221;)with Ubuntu 14.04 Installed<br \/>\n\u2022 Review your AppArmor policies with MySQL to prevent conflict<br \/>\n\u2022 Galera Packages<br \/>\n\u2022 RSync installed on each node (this should be the case by default on Ubuntu 14.04)<\/p>\n<h2>Install Galera<\/h2>\n<p>First, we\u2019ll want to install the Codership repository, which contains the packages we need. We start that process by installing the python software-properties package, as it is needed to properly manage additional custom repositories.<\/p>\n<p><code>apt-get install software-properties-common<br \/>\napt-key adv --keyserver keyserver.ubuntu.com --recv BC19DDBA<\/code><\/p>\n<p>Then we need to create a repository file and add it in the source list, \/etc\/apt\/sources.list.d\/galera.list, so that apt can query the repository.<\/p>\n<p><code>deb http:\/\/releases.galeracluster.com\/ubuntu trusty main<\/code><\/p>\n<p>Now that we have a new repository setup, we update the apt cache.<\/p>\n<p><code>apt-get update<\/code><\/p>\n<p>Galera needs 3 packages installed to work. Please also note that these packages CAN and WILL conflict with other MySQL packages, so it is better to have a clean server with no MySQL packages installed to avoid dependency hell. So, next we install these 3 packages on all 3 nodes:<\/p>\n<p><code>apt-get install galera-3 galera-arbitrator-3 mysql-wsrep-5.6<\/code><\/p>\n<p>Once this is done, only starting MySQL on each node remains.<\/p>\n<p><code>service mysql start<\/code><\/p>\n<p>You now have a working MySQL instance on each node. Once you have the packages installed, you will want to ensure that connectivity to MySQL is possible between nodes. Start by pinging each node from each other.<\/p>\n<p><code>root@node1:~#ping 192.168.0.2<br \/>\nroot@node1:~#ping 192.168.0.3<br \/>\nroot@node2:~#ping 192.168.0.1<br \/>\nroot@node2:~#ping 192.168.0.3<br \/>\nroot@node3:~#ping 192.168.0.1<br \/>\nroot@node3:~#ping 192.168.0.2<\/code><br \/>\nIf all is well, modify the mysql configuration at \/etc\/mysql\/my.cnf so that MySQL binds on all ip addresses or, modify it to bind to your preferred MySQL communication IP. The 0.0.0.0 represent a wildcard IP and means that mysql listens on all server IPs.<br \/>\n<code>bind-address=0.0.0.0<br \/>\nservice mysql restart<\/code><br \/>\nThen, try to connect to the MySQL server on the other nodes.<br \/>\n<code>mysql -H node2ip \u2013u root -p<\/code><\/p>\n<p>If you get a request to input your password, this means the mysql server on the other side is listening. You can now proceed with configuring MySQL properly.<\/p>\n<h2>Configuration<\/h2>\n<p>Now we will configure the my.cnf that you will use on the Galera Cluster nodes. If the default configuration is not already set like this, you will want to add the following lines in your \/etc\/mysql\/my.cnf file:<\/p>\n<p><code class=\"gris\">binlog_format=ROW<br \/>\ndefault-storage-engine=innodb<br \/>\ninnodb_autoinc_lock_mode=2<br \/>\nwsrep_provider=\/usr\/lib\/libgalera_smm.so<br \/>\nwsrep_provider_options=\"gcache.size=300M; gcache.page_size=1G\"<br \/>\nwsrep_cluster_name=\"galeracluster\"<br \/>\nwsrep_cluster_address=\"gcomm:\/\/192.168.0.1,192.168.0.2,192.168.0.3 \"<br \/>\nwsrep_sst_method=rsync<br \/>\nwsrep_sst_auth=wsrep:password<\/code><\/p>\n<p>There are a few things to change and consider here.<\/p>\n<li>First of all, the default storage engine line is necessary, because Galera can only replicate innodb databases.<\/li>\n<li>The wsrep_cluster_name is the name of your galera setup. It will need to be the same on each server.<\/li>\n<li>Wsrep_cluster_address is where each node is defined. You may want to start your first node with \u201cgcomm:\/\/\u201d instead, or else Galera will try to connect to the other nodes and fail as they are not started yet.<\/li>\n<li>The wsrep_sst_auth line indicates the method Galera will use to send large chunks of data from one node to the other when one of the nodes is too far behind. The three options here are Rsync (the fastest), MySQLdump (the slowest) or Xtrabackup. Rsync locks the database for the donor node, MySQLdump too, but Xtrabackup does not.<\/li>\n<li>The last line is a MySQL user and password used for replication. If using MySQLdump, it needs to be the MySQL root password and the same root password must be used on all nodes. If using Xtrabackup, it can be a user that has access to all tables.<\/li>\n<p><\/br><\/p>\n<p>Next, create the replication user on each node.<\/p>\n<p><code>mysql \u2013u root \u2013p<br \/>\nCREATE USER \u2018wsrep\u2019@\u2019%\u2019 IDENTIFIED BY \u2018password\u2019;<br \/>\nWe will also want the root user to be reachable remotely.<br \/>\nCREATE USER \u2018root\u2019@\u2019%\u2019 IDENTIFIED BY \u2018password\u2019;<br \/>\nGRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;<\/code><\/p>\n<p>(Please note that it may be preferable to specify your network IP with a wildcard at the end like 192.168.0.% instead of just using %, as the mysql server root will become reachable from any IP address with just a %)<\/p>\n<p>Ubuntu has a special user called debian-sys-maint to do maintenance tasks on MySQL. Because of the database replication, the maintenance operations will only continue to work properly on the first node, failing on the others. You will want to copy \/etc\/mysql\/debian.cnf from the original node to the other nodes, so that the maintenance operations can continue to work.<\/p>\n<div class=\"alert alert-info\">scp \/etc\/mysql\/debian.cnf root@node2:\/etc\/mysql\/<\/div>\n<p>Once all of this is done, we are now ready to start the cluster. On the original node, make sure that gcomm:\/\/ is empty in the MySQL configuration. Then shutdown MySQL and restart it like this:<\/p>\n<p><code>service mysql stop<br \/>\nservice mysql start -\u2013wsrep-new-cluster<\/code><\/p>\n<p>You will now have the first node up. On the other nodes, make sure your configuration is set properly and then restart MySQL.<\/p>\n<p><code>service mysql restart<\/code><\/p>\n<p>MySQL should take slightly longer than usual to start as it will sync with the main server. You now have a working master-master Galera cluster. The last step will be to verify that this setup is working.<\/p>\n<h2>Testing it<\/h2>\n<p>You can check that master-master replication is working properly by creating a database on one node and verifying that it exists on the other nodes. We will first login to a MySQL instance on one of the nodes.<\/p>\n<p><code>mysql -u root -p<\/code><\/p>\n<p>Then we create a new database.<\/p>\n<p><code>root@node1:~#create database test<\/code><\/p>\n<p>Next, we go on another node and check if our database is created there.<\/p>\n<p><code>root@node2:~#mysql -u root -p<br \/>\nroot@node2:~#show databases;<\/code><\/p>\n<p>If you see a database named test in the database list, it means the replication has worked flawlessly.<\/p>\n<h2>Conclusion<\/h2>\n<p>You now have a fully functional Galera cluster. You may now want to configure your application to send queries to the cluster or setup a load-balancer to better control where the queries end up. In case you would be interested in using HAProxy for your load-balancing need, we have a knowledge base explaining how to setup HAProxy for use with MySQL. If this guide was helpful to you, kindly share it with others who may also be interested. <\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>How to install Galera on Ubuntu 14.04 Galera Cluster is a plugin for MySQL which enables the Galera replication engine and lets you replicate your databases between servers in a synchronous master-master manner. It requires the InnoDB database engine to be set as default for all replicated databases. It&#8217;s strongly recommended to run an odd<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61,75,50],"tags":[],"class_list":["post-1694","post","type-post","status-publish","format-standard","hentry","category-database","category-ha-clustering","category-tutorials","operating_system-ubuntu-14-04"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to install Galera on Ubuntu 14.04 - Globo.Tech<\/title>\n<meta name=\"description\" content=\"This tutorial will show you how to install Galera on your Ubuntu 14.04 server. Read now &amp; Get a fully functional Galera Cluster !\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.globo.tech\/learning-center\/how-to-install-galera-on-ubuntu-14-04-lts\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to install Galera on Ubuntu 14.04 - Globo.Tech\" \/>\n<meta property=\"og:description\" content=\"This tutorial will show you how to install Galera on your Ubuntu 14.04 server. Read now &amp; Get a fully functional Galera Cluster !\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.globo.tech\/learning-center\/how-to-install-galera-on-ubuntu-14-04-lts\/\" \/>\n<meta property=\"og:site_name\" content=\"Globo.Tech\" \/>\n<meta property=\"article:published_time\" content=\"2016-03-30T23:47:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-12T19:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2016\/09\/GloboTech-Logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"963\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"GloboTech Communications\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"GloboTech Communications\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/how-to-install-galera-on-ubuntu-14-04-lts\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/how-to-install-galera-on-ubuntu-14-04-lts\\\/\"},\"author\":{\"name\":\"GloboTech Communications\",\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/#\\\/schema\\\/person\\\/e17784b37f4a4f49b7bc611847912e87\"},\"headline\":\"How to install Galera on Ubuntu 14.04\",\"datePublished\":\"2016-03-30T23:47:47+00:00\",\"dateModified\":\"2018-01-12T19:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/how-to-install-galera-on-ubuntu-14-04-lts\\\/\"},\"wordCount\":993,\"commentCount\":1,\"articleSection\":[\"Database\",\"HA &amp; Clustering\",\"Tutorials\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/how-to-install-galera-on-ubuntu-14-04-lts\\\/\",\"url\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/how-to-install-galera-on-ubuntu-14-04-lts\\\/\",\"name\":\"How to install Galera on Ubuntu 14.04 - Globo.Tech\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/#website\"},\"datePublished\":\"2016-03-30T23:47:47+00:00\",\"dateModified\":\"2018-01-12T19:00:00+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/#\\\/schema\\\/person\\\/e17784b37f4a4f49b7bc611847912e87\"},\"description\":\"This tutorial will show you how to install Galera on your Ubuntu 14.04 server. Read now & Get a fully functional Galera Cluster !\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/how-to-install-galera-on-ubuntu-14-04-lts\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/how-to-install-galera-on-ubuntu-14-04-lts\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/how-to-install-galera-on-ubuntu-14-04-lts\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to install Galera on Ubuntu 14.04\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/#website\",\"url\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/\",\"name\":\"Globo.Tech\",\"description\":\"Welcome to the Official Globo.Tech Learning Center\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/#\\\/schema\\\/person\\\/e17784b37f4a4f49b7bc611847912e87\",\"name\":\"GloboTech Communications\",\"sameAs\":[\"http:\\\/\\\/www.gtcomm.net\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to install Galera on Ubuntu 14.04 - Globo.Tech","description":"This tutorial will show you how to install Galera on your Ubuntu 14.04 server. Read now & Get a fully functional Galera Cluster !","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.globo.tech\/learning-center\/how-to-install-galera-on-ubuntu-14-04-lts\/","og_locale":"en_US","og_type":"article","og_title":"How to install Galera on Ubuntu 14.04 - Globo.Tech","og_description":"This tutorial will show you how to install Galera on your Ubuntu 14.04 server. Read now & Get a fully functional Galera Cluster !","og_url":"https:\/\/www.globo.tech\/learning-center\/how-to-install-galera-on-ubuntu-14-04-lts\/","og_site_name":"Globo.Tech","article_published_time":"2016-03-30T23:47:47+00:00","article_modified_time":"2018-01-12T19:00:00+00:00","og_image":[{"width":1920,"height":963,"url":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2016\/09\/GloboTech-Logo.png","type":"image\/png"}],"author":"GloboTech Communications","twitter_misc":{"Written by":"GloboTech Communications","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.globo.tech\/learning-center\/how-to-install-galera-on-ubuntu-14-04-lts\/#article","isPartOf":{"@id":"https:\/\/www.globo.tech\/learning-center\/how-to-install-galera-on-ubuntu-14-04-lts\/"},"author":{"name":"GloboTech Communications","@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87"},"headline":"How to install Galera on Ubuntu 14.04","datePublished":"2016-03-30T23:47:47+00:00","dateModified":"2018-01-12T19:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.globo.tech\/learning-center\/how-to-install-galera-on-ubuntu-14-04-lts\/"},"wordCount":993,"commentCount":1,"articleSection":["Database","HA &amp; Clustering","Tutorials"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.globo.tech\/learning-center\/how-to-install-galera-on-ubuntu-14-04-lts\/","url":"https:\/\/www.globo.tech\/learning-center\/how-to-install-galera-on-ubuntu-14-04-lts\/","name":"How to install Galera on Ubuntu 14.04 - Globo.Tech","isPartOf":{"@id":"https:\/\/www.globo.tech\/learning-center\/#website"},"datePublished":"2016-03-30T23:47:47+00:00","dateModified":"2018-01-12T19:00:00+00:00","author":{"@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87"},"description":"This tutorial will show you how to install Galera on your Ubuntu 14.04 server. Read now & Get a fully functional Galera Cluster !","breadcrumb":{"@id":"https:\/\/www.globo.tech\/learning-center\/how-to-install-galera-on-ubuntu-14-04-lts\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.globo.tech\/learning-center\/how-to-install-galera-on-ubuntu-14-04-lts\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.globo.tech\/learning-center\/how-to-install-galera-on-ubuntu-14-04-lts\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.globo.tech\/learning-center\/"},{"@type":"ListItem","position":2,"name":"How to install Galera on Ubuntu 14.04"}]},{"@type":"WebSite","@id":"https:\/\/www.globo.tech\/learning-center\/#website","url":"https:\/\/www.globo.tech\/learning-center\/","name":"Globo.Tech","description":"Welcome to the Official Globo.Tech Learning Center","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87","name":"GloboTech Communications","sameAs":["http:\/\/www.gtcomm.net"]}]}},"_links":{"self":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/1694","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/comments?post=1694"}],"version-history":[{"count":9,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/1694\/revisions"}],"predecessor-version":[{"id":4077,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/1694\/revisions\/4077"}],"wp:attachment":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/media?parent=1694"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/categories?post=1694"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/tags?post=1694"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}