6. Creating resources¶
Virtual IP¶
pcs resource create vip ocf:heartbeat:IPaddr2 ip=192.168.13.34 cidr_netmask=24 \
op monitor interval=20s
Gotcha: don't put the subnet in the ip= parameter — ip="192.168.0.200/24" is
wrong and fails with 'not configured' (6) / [findif] failed. Use ip= for the
bare address and cidr_netmask= separately:
pcs resource create etcd_ip ocf:heartbeat:IPaddr2 ip="192.168.0.200" cidr_netmask=24 \
op monitor interval=60s
HAProxy (systemd resource, cloned across all nodes)¶
pcs resource create haproxy systemd:haproxy clone
Apache¶
pcs resource create httpd ocf:heartbeat:apache \
configfile=/etc/httpd/conf/httpd.conf \
statusurl="http://127.0.0.1/server-status" \
op monitor interval=20s
Needs mod_status enabled and a <Location /server-status> block allowing
127.0.0.1 in the Apache config on every node.
MariaDB/MySQL (simple, non-Galera)¶
pcs resource create mariadb ocf:heartbeat:mysql op monitor interval=1min
Galera (multistate master/master cluster)¶
pcs resource create galera ocf:heartbeat:galera \
enable_creation=true \
wsrep_cluster_address="gcomm://node1,node2,node3" \
meta master-max=3 ordered=true \
op monitor interval=20s timeout=30s promote timeout=300s
Colocation / ordering / location constraints¶
pcs constraint colocation add vip httpd mariadb INFINITY
pcs constraint order start vip then start httpd
pcs constraint location vip prefers node1=50
Grouping resources (start/stop together, in order, on the same node)¶
pcs resource create cluster_ip0 ocf:heartbeat:IPaddr2 ip=192.168.122.70 \
cidr_netmask=24 op monitor interval=30s --group public_ips
pcs resource create cluster_ip1 ocf:heartbeat:IPaddr2 ip=192.168.122.71 \
cidr_netmask=24 op monitor interval=30s --group public_ips
Staged config editing pattern (batch several changes atomically)¶
Useful for anything with several interdependent resources (DRBD + filesystem + service, for example) — build the change set offline against a snapshot of the CIB, review it, then push it live in one shot.
pcs cluster cib work.cfg # snapshot current live CIB
pcs -f work.cfg resource create ...
pcs -f work.cfg constraint ...
pcs -f work.cfg resource show # review before committing
pcs cluster cib-push work.cfg # or: pcs cluster push cib work.cfg (older pcs)