User Tools

Site Tools


Setting up CARP

You need carp set up to tell the nodes which is primary and which is secondary.

I'm using vlan50 for my data, so we need to be able to switch between machines. The two machines will have in common, configured as follows:

  • iscsi-0:
  • iscsi-1:
  • CARP:

Enable carp and set shared IP

Add the directives to load the carp module and make the alias for vlan50. the carp.preempt sets it so so when the parent interface goes down or comes up, the carp interface will do the same

echo 'carp_load="YES"' >> /boot/loader.conf
echo 'net.inet.carp.preempt=1' >> /etc/sysctl.conf
echo 'ifconfig_vlan50_alias0="inet vhid 1 pass iscsilan alias"' >> /etc/rc.conf

if you want to test this, you can run the following:

kldload carp  
sysctl net.inet.carp.preempt=1
ifconfig vlan50 alias vhid 1 pass iscsilan

Set devd

Add the following to the bottom of /etc/devd.conf. This tells the server what to do when the carp interface comes up or goes down.

notify 30 {
        match "system" "IFNET";
        match "subsystem" "vlan50";
        match "type" "LINK_UP";
        action "/usr/local/opt/hast/failover master";
notify 30 {
        match "system" "IFNET";
        match "subsystem" "vlan50";
        match "type" "LINK_DOWN";
        action "/usr/local/opt/hast/failover slave";

Create the failover script

This is taken mainly from the hast article at [].

The following script is designed to bring up/shutdown the hast volumes and will eventually be used to handle the iSCSI service and NFS. It already handles the zpool itself.

Change resource list and pool name before implementing.

# Original script by Freddie Cash <>
# Modified by Michael W. Lucas <>
# and Viktor Petersson <>
# Modified by George Kontostanos <>
# The names of the HAST resources, as listed in /etc/hast.conf
resources="disk0 disk1 disk2 disk3 disk4 disk5 disk6 disk7 disk8 disk9"
# delay in mounting HAST resource after becoming master
# make your best guess
# logging
# end of user configurable stuff
case "$1" in
  logger -p $log -t $name "Switching to primary provider for ${resources}."
  sleep ${delay}
  # Wait for any "hastd secondary" processes to stop
  for disk in ${resources}; do
   while $( pgrep -lf "hastd: ${disk} \(secondary\)" > /dev/null 2>&1 ); do
    sleep 1
   # Switch role for each disk
   hastctl role primary ${disk}
   if [ $? -ne 0 ]; then
    logger -p $log -t $name "Unable to change role to primary for resource ${disk}."
    exit 1
  # Wait for the /dev/hast/* devices to appear
  for disk in ${resources}; do
   for I in $( jot 60 ); do
    [ -c "/dev/hast/${disk}" ] && break
    sleep 0.5
   if [ ! -c "/dev/hast/${disk}" ]; then
    logger -p $log -t $name "GEOM provider /dev/hast/${disk} did not appear."
    exit 1
  logger -p $log -t $name "Role for HAST resources ${resources} switched to primary."
  logger -p $log -t $name "Importing Pool"
  # Import ZFS pool. Do it forcibly as it remembers hostid of
                # the other cluster node.
                out=`zpool import -f "${pool}" 2>&1`
                if [ $? -ne 0 ]; then
                    logger -p local0.error -t hast "ZFS pool import for resource ${resource} failed: ${out}."
                    exit 1
                logger -p local0.debug -t hast "ZFS pool for resource ${resource} imported."
  logger -p $log -t $name "Switching to secondary provider for ${resources}."
  # Switch roles for the HAST resources
  zpool list | egrep -q "^${pool} "
         if [ $? -eq 0 ]; then
                 # Forcibly export file pool.
                 out=`zpool export -f "${pool}" 2>&1`
                  if [ $? -ne 0 ]; then
                         logger -p local0.error -t hast "Unable to export pool for resource ${resource}: ${out}."
                         exit 1
                 logger -p local0.debug -t hast "ZFS pool for resource ${resource} exported."
  for disk in ${resources}; do
   sleep $delay
   hastctl role secondary ${disk} 2>&1
   if [ $? -ne 0 ]; then
    logger -p $log -t $name "Unable to switch role to secondary for resource ${disk}."
    exit 1
   logger -p $log -t $name "Role switched to secondary for resource ${disk}."


unix/freebsd/system_builds/carp.txt · Last modified: 2019/07/10 20:46 by