Ubuntu 16.04版Amazon EC2实例部署Corosync+Pacemaker集群咨询
Hey there! Let's break down your questions one by one and get you past that stuck step with Corosync/Pacemaker on Ubuntu 16.04 EC2 instances.
Absolutely. Ubuntu 16.04 (Xenial Xerus) includes both packages in its default repositories, so you can install them directly with:
sudo apt-get install corosync pacemaker pcs
Note that pcs is the recommended CLI tool for managing the cluster—it ties together Corosync and Pacemaker into a single, easy-to-use management interface.
A quick heads-up though: Ubuntu 16.04 reached end-of-life in April 2021, so you won't receive any security updates going forward. If possible, migrating to a newer LTS release like 20.04 or 22.04 would be better for long-term stability, but if you have to stick with 16.04, the cluster setup will still work as intended.
Yes, they do—but EC2 has a few virtualized networking quirks you need to account for:
- Corosync relies on reliable cluster communication. EC2 doesn't support cross-instance multicast by default, so you must configure unicast instead of multicast in your Corosync setup.
- Always use your EC2 instances' private IP addresses for cluster communication (not public IPs). Public IPs can change if instances are stopped/started, and internal private network traffic is faster and more secure.
- Make sure your EC2 security group allows inbound/outbound traffic on these ports: TCP 2224 (for pcsd), UDP 5404/5405 (Corosync cluster traffic), and TCP 3121 (Pacemaker).
Since you're using S3 as primary storage and RDS as your database, most of your shared state is already handled externally—which simplifies the cluster setup a lot! Let's walk through the steps, including fixing that private_binding_IP_address issue you hit.
Pre-Cluster Setup
- Ensure all EC2 instances are in the same VPC (and same subnet, or connected via VPC peering if needed) with static private IPs (the default for EC2 instances unless you specify otherwise).
- Set up a password for the
haclusteruser (created automatically during package installation) on every node:sudo passwd hacluster - Enable and start the
pcsdservice on all nodes to manage cluster authentication:sudo systemctl enable --now pcsd
Install & Configure Corosync/Pacemaker (Fixing the IP Binding Issue)
The private_binding_IP_address hangup usually comes from manual Corosync config edits. Using the pcs CLI avoids this by auto-configuring the correct private IP bindings and unicast settings for EC2. Here's how:
- On one node, authenticate all cluster nodes with each other (replace
node1-private-ip,node2-private-ipwith your instances' actual private IPs):sudo pcs cluster auth node1-private-ip node2-private-ip node3-private-ip -u hacluster -p your-hacluster-password - Create the cluster (replace
my-nextcloud-clusterwith your preferred cluster name):
This command auto-generates the Corosync config with unicast enabled and binds each node to its private IP—no manual editing needed!sudo pcs cluster setup --name my-nextcloud-cluster node1-private-ip node2-private-ip node3-private-ip - Start the cluster on all nodes:
sudo pcs cluster start --all - Temporarily disable STONITH (fencing) for initial testing (we'll set up EC2-specific fencing later for production):
For production, you should configure thesudo pcs property set stonith-enabled=falsefence_ec2agent to safely terminate failed EC2 instances and prevent split-brain scenarios.
NextCloud-Specific Cluster Configuration
Since your NextCloud data lives in S3 and your database is in RDS, each EC2 node just needs a consistent NextCloud setup and a way to route traffic to the active node:
- Install NextCloud on every EC2 node, configuring each instance to point to the same RDS database and S3 bucket. Ensure the
config/config.phpfile is identical across all nodes (you can sync it viarsyncor store it in EFS for shared access). - Set up a floating Elastic IP (EIP) with Pacemaker so users connect to a single, stable IP that fails over to a healthy node:
Replacesudo pcs resource create nextcloud-fip ocf:heartbeat:aws-vpc-elastic-ip allocation_id=your-eip-allocation-id ip=node1-private-ip op monitor interval=30syour-eip-allocation-idwith the allocation ID of your EC2 Elastic IP. - Create a resource to manage your NextCloud web service (adjust for Nginx if you're not using Apache):
sudo pcs resource create nextcloud-service systemd:apache2 op monitor interval=10s - Colocate the floating IP with the NextCloud service so they always run on the same node:
sudo pcs constraint colocation add nextcloud-fip with nextcloud-service INFINITY - Set an order constraint to start the web service before the floating IP:
sudo pcs constraint order nextcloud-service then nextcloud-fip
Now your cluster will automatically fail over the NextCloud service and floating IP to a healthy node if any instance goes down.
内容的提问来源于stack exchange,提问作者ibr




