Skip to content
logo
Percona XtraDB Cluster
How to set up a three-node cluster on a single box
Initializing search
    percona/pxc-docs
    percona/pxc-docs
    • Home
      • About Percona XtraDB Cluster
      • Percona XtraDB Cluster limitations
      • Understand version numbers
      • Quick start guide for Percona XtraDB Cluster
      • Install Percona XtraDB Cluster
      • Configure nodes for write-set replication
      • Bootstrap the first node
      • Add nodes to cluster
      • Verify replication
      • High availability
      • PXC strict mode
      • Online schema upgrade
      • Non-Blocking Operations (NBO) method for Online Scheme Upgrades (OSU)
      • Security basics
      • Secure the network
      • Encrypt PXC traffic
      • Enable AppArmor
      • Enable SELinux
      • State snapshot transfer
      • Percona XtraBackup SST configuration
      • Restart the cluster nodes
      • Cluster failover
      • Monitor the cluster
      • Certification in Percona XtraDB Cluster
      • Percona XtraDB Cluster threading model
      • Understand GCache and Record-Set cache
      • GCache encryption and Write-Set cache encryption
      • Perfomance Schema instrumentation
      • Data at Rest Encryption
      • Upgrade Percona XtraDB Cluster
      • Crash recovery
      • Configure Percona XtraDB Cluster on CentOS
      • Configure Percona XtraDB Cluster on Ubuntu
      • Set up Galera arbitrator
      • How to set up a three-node cluster on a single box
      • How to set up a three-node cluster in EC2 environment
      • Load balancing with HAProxy
      • Load balancing with ProxySQL
      • ProxySQL admin utilities
      • Setting up a testing environment with ProxySQL
      • Release notes index
      • Percona XtraDB Cluster 8.0.31-23 (2023-03-14)
      • Percona XtraDB Cluster 8.0.30-22.md (2022-12-28)
      • Percona XtraDB Cluster 8.0.29-21 (2022-09-12)
      • Percona XtraDB Cluster 8.0.28-19.1 (2022-07-19)
      • Percona XtraDB Cluster 8.0.27-18.1
      • Percona XtraDB Cluster 8.0.26-16.1
      • Percona XtraDB Cluster 8.0.25-15.1
      • Percona XtraDB Cluster 8.0.23-14.1
      • Percona XtraDB Cluster 8.0.22-13.1
      • Percona XtraDB Cluster 8.0.21-12.1
      • Percona XtraDB Cluster 8.0.20-11
      • Percona XtraDB Cluster 8.0.20-11.3
      • Percona XtraDB Cluster 8.0.20-11.2
      • Percona XtraDB Cluster 8.0.19-10
      • Percona XtraDB Cluster 8.0.18-9.3
      • Index of wsrep status variables
      • Index of wsrep system variables
      • Index of wsrep_provider options
      • Index of files created by PXC
      • Frequently asked questions
      • Glossary
      • Copyright and licensing information
      • Trademark policy

    How to set up a three-node cluster on a single box¶

    This tutorial describes how to set up a 3-node cluster on a single physical box.

    For the purposes of this tutorial, assume the following:

    • The local IP address is 192.168.2.21.

    • Percona XtraDB Cluster is extracted from binary tarball into /usr/local/Percona-XtraDB-Cluster-8.0.x86_64

    To set up the cluster:

    1. Create three MySQL configuration files for the corresponding nodes:

      • /etc/my.4000.cnf
      [mysqld]
      port = 4000
      socket=/tmp/mysql.4000.sock
      datadir=/data/bench/d1
      basedir=/usr/local/Percona-XtraDB-Cluster-8.0.x86_64
      user=mysql
      log_error=error.log
      binlog_format=ROW
      wsrep_cluster_address='gcomm://192.168.2.21:5030,192.168.2.21:6030'
      wsrep_provider=/usr/local/Percona-XtraDB-Cluster-8.0.x86_64/lib/libgalera_smm.so
      wsrep_sst_receive_address=192.168.2.21:4020
      wsrep_node_incoming_address=192.168.2.21
      wsrep_cluster_name=trimethylxanthine
      wsrep_provider_options = "gmcast.listen_addr=tcp://192.168.2.21:4030;"
      wsrep_sst_method=xtrabackup-v2
      wsrep_node_name=node4000
      innodb_autoinc_lock_mode=2
      
      • /etc/my.5000.cnf
      [mysqld]
      port = 5000
      socket=/tmp/mysql.5000.sock
      datadir=/data/bench/d2
      basedir=/usr/local/Percona-XtraDB-Cluster-8.0.x86_64
      user=mysql
      log_error=error.log
      binlog_format=ROW
      wsrep_cluster_address='gcomm://192.168.2.21:4030,192.168.2.21:6030'
      wsrep_provider=/usr/local/Percona-XtraDB-Cluster-8.0.x86_64/lib/libgalera_smm.so
      wsrep_sst_receive_address=192.168.2.21:5020
      wsrep_node_incoming_address=192.168.2.21
      
      wsrep_cluster_name=trimethylxanthine
      wsrep_provider_options = "gmcast.listen_addr=tcp://192.168.2.21:5030;"
      wsrep_sst_method=xtrabackup-v2
      wsrep_node_name=node5000
      innodb_autoinc_lock_mode=2
      
      • /etc/my.6000.cnf
      [mysqld]
      port = 6000
      socket=/tmp/mysql.6000.sock
      datadir=/data/bench/d3
      basedir=/usr/local/Percona-XtraDB-Cluster-8.0.x86_64
      user=mysql
      log_error=error.log
      binlog_format=ROW
      wsrep_cluster_address='gcomm://192.168.2.21:4030,192.168.2.21:5030'
      wsrep_provider=/usr/local/Percona-XtraDB-Cluster-8.0.x86_64/lib/libgalera_smm.so
      wsrep_sst_receive_address=192.168.2.21:6020
      wsrep_node_incoming_address=192.168.2.21
      wsrep_cluster_name=trimethylxanthine
      wsrep_provider_options = "gmcast.listen_addr=tcp://192.168.2.21:6030;"
      wsrep_sst_method=xtrabackup-v2
      wsrep_node_name=node6000
      innodb_autoinc_lock_mode=2
      
    2. Create three data directories for the nodes:

      • /data/bench/d1

      • /data/bench/d2

      • /data/bench/d3

    3. Start the first node using the following command (from the Percona XtraDB Cluster install directory):

      $ bin/mysqld_safe --defaults-file=/etc/my.4000.cnf --wsrep-new-cluster
      

      If the node starts correctly, you should see the following output:

      Expected output
      111215 19:01:49 [Note] WSREP: Shifting JOINED -> SYNCED (TO: 0)
      111215 19:01:49 [Note] WSREP: New cluster view: global state: 4c286ccc-2792-11e1-0800-94bd91e32efa:0, view# 1: Primary, number of nodes: 1, my index: 0, protocol version 1
      

      To check the ports, run the following command:

      $ netstat -anp | grep mysqld
      tcp        0      0 192.168.2.21:4030           0.0.0.0:*                   LISTEN      21895/mysqld
      tcp        0      0 0.0.0.0:4000                0.0.0.0:*                   LISTEN      21895/mysqld
      
    4. Start the second and third nodes:

      bin/mysqld_safe --defaults-file=/etc/my.5000.cnf
      bin/mysqld_safe --defaults-file=/etc/my.6000.cnf
      

      If the nodes start and join the cluster successful, you should see the following output:

      111215 19:22:26 [Note] WSREP: Shifting JOINER -> JOINED (TO: 2)
      111215 19:22:26 [Note] WSREP: Shifting JOINED -> SYNCED (TO: 2)
      111215 19:22:26 [Note] WSREP: Synchronized with group, ready for connections
      

      To check the cluster size, run the following command:

      $ mysql -h127.0.0.1 -P6000 -e "show global status like 'wsrep_cluster_size';"
      
      Expected output
      +--------------------+-------+
      | Variable_name      | Value |
      +--------------------+-------+
      | wsrep_cluster_size | 3     |
      +--------------------+-------+
      

      After that you can connect to any node and perform queries, which will be automatically synchronized with other nodes. For example, to create a database on the second node, you can run the following command:

      $ mysql -h127.0.0.1 -P5000 -e "CREATE DATABASE hello_peter"
      

    Contact us

    For free technical help, visit the Percona Community Forum.

    To report bugs or submit feature requests, open a JIRA ticket.

    For paid support and managed or consulting services , contact Percona Sales.


    Last update: 2023-01-20
    Percona LLC and/or its affiliates, © 2023
    Made with Material for MkDocs

    Cookie consent

    We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better.