Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Using Corosync

1. Introduction to Corosync

Corosync is an open-source cluster engine used to implement high availability (HA) solutions. It handles messaging, membership, and quorum information for nodes in a cluster. This tutorial guides you through the process of setting up Corosync from start to finish.

2. Installing Corosync

First, you'll need to install Corosync on all nodes in your cluster. Use the following command:

sudo apt-get install corosync

Once the installation is complete, verify the installation:

corosync -v
Corosync Cluster Engine, version 3.x.x

3. Configuring Corosync

Next, configure Corosync by editing the /etc/corosync/corosync.conf file. Here is a basic example configuration:

totem {
    version: 2
    secauth: off
    cluster_name: mycluster
    transport: udpu
    interface {
        ringnumber: 0
        bindnetaddr: 192.168.1.0
        mcastport: 5405
    }
}
logging {
    fileline: off
    to_stderr: yes
    to_logfile: yes
    logfile: /var/log/corosync/corosync.log
    to_syslog: yes
    debug: off
    timestamp: on
    logger_subsys {
        subsys: AMF
        debug: off
        tags: enter|leave|trace1|trace2|trace3|trace4|trace6
    }
}
quorum {
    provider: corosync_votequorum
    two_node: 1
}
                

Replace bindnetaddr with your network's subnet address. This configuration sets up Corosync for a two-node cluster using UDP unicast.

4. Starting Corosync

After configuring Corosync, start the service on all nodes:

sudo systemctl start corosync

Enable Corosync to start on boot:

sudo systemctl enable corosync

Check the status of the Corosync service:

sudo systemctl status corosync
● corosync.service - Corosync Cluster Engine Loaded: loaded (/lib/systemd/system/corosync.service; enabled; vendor preset: enabled) Active: active (running) since ...

5. Verifying Corosync Cluster

To verify that Corosync is running and that the nodes are communicating, use the following commands:

corosync-cmapctl | grep members
runtime.totem.pg.mrp.srp.members.123456789.nodeid (u32) = 1 runtime.totem.pg.mrp.srp.members.123456789.name (str) = node1

Ensure that all nodes are listed in the output.

6. Configuring Quorum

Quorum is important in a cluster to avoid split-brain scenarios. Ensure that your configuration includes quorum settings. In the example configuration, we used the corosync_votequorum provider:

quorum {
    provider: corosync_votequorum
    two_node: 1
}
                

For more complex setups, refer to the official Corosync documentation.

7. Troubleshooting

If you encounter issues, check the logs located in /var/log/corosync/corosync.log. Common issues include misconfigured network settings or firewall rules blocking communication between nodes.

Use the following command to view the logs:

sudo tail -f /var/log/corosync/corosync.log

8. Conclusion

By following this tutorial, you have set up Corosync for high availability on a Linux cluster. Corosync provides a reliable foundation for building HA solutions. For further customization and advanced features, refer to the Corosync documentation and community resources.