### Example of Virtual Server Configuration Source: https://www.keepalived.org/manpage.html This example demonstrates the creation of two virtual servers, each with three real servers, using Keepalived configuration syntax. ```keepalived $VS_NUM=0 $ALPHA=alpha $VS $VS_NUM=1 $ALPHA= $VS ``` -------------------------------- ### Nested Multiline Parameter Definition Example Source: https://www.keepalived.org/manpage.html Demonstrates nested multiline definitions, where a parameter definition itself contains other multiline parameter definitions. This example shows defining real servers and virtual servers. ```plaintext $RS= \ **real_server **192.168.${VS_NUM}.${RS_NUM} 80 { \ **weight **1 \ **inhibit_on_failure** \ **smtp_alert** \ **MISC_CHECK **{ \ **misc_path **"${_PWD}/scripts/vs.sh RS_misc.${INST}.${VS_NUM}.${RS_NUM}.0 10.0.${VS_NUM}.4:80->192.168.${VS_NUM}.${RS_NUM}:80" \ } \ **MISC_CHECK **{ \ **misc_path **"${_PWD}/scripts/vs.sh RS_misc.${INST}.${VS_NUM}.${RS_NUM}.1 10.0.${VS_NUM}.4:80->192.168.${VS_NUM}.${RS_NUM}:80" \ } \ **notify_up **"${_PWD}/scripts/notify.sh RS_notify.${INST}.${VS_NUM}.${RS_NUM} UP 10.0.${VS_NUM}.4:80->192.168.${VS_NUM}.${RS_NUM}:80" \ **notify_down **"${_PWD}/scripts/notify.sh RS_notify.${INST}.${VS_NUM}.${RS_NUM} DOWN 10.0.${VS_NUM}.4:80->192.168.${VS_NUM}.${RS_NUM}:80" \ } $VS= \ **virtual_server **10.0.${VS_NUM}.4 80 { \ **quorum **2 \ **quorum_up **"${_PWD}/scripts/notify.sh VS_notify.${INST} UP 10.0.${VS_NUM}.4:80" ``` -------------------------------- ### Keepalived Routing Configuration Examples Source: https://www.keepalived.org/manpage.html Examples of Keepalived routing rules, specifying source, destination, table, interface, and other parameters. ```config from 192.168.2.0/24 table 1 track_group GROUP1 ``` ```config to 192.168.2.0/24 table 1 ``` ```config from 192.168.28.0/24 to 192.168.29.0/26 table small iif p33p1 oif wlan0 tos 22 fwmark 24/12 preference 39 realms 30/20 goto 40 ``` ```config to 1:2:3:4:5:6:7:0/112 from 7:6:5:4:3:2::/96 table 6908 uidrange 10000-19999 ``` ```config to 1:2:3:4:6:6:7:0/112 from 8:6:5:4:3:2::/96 l3mdev protocol 12 ip_proto UDP sport 10-20 dport 20-30 ``` -------------------------------- ### Recursive Parameter Substitution Example Source: https://www.keepalived.org/manpage.html Demonstrates recursive parameter substitution where a parameter's value can contain other parameters that are resolved at replacement time. Note the use of braces {} when a parameter is not followed by whitespace. ```plaintext $ADDRESS_BASE=10.2.${ADDRESS_BASE_SUB} $ADDRESS_BASE_SUB=0 ${ADDRESS_BASE}.100/32 $ADDRESS_BASE_SUB=10 ${ADDRESS_BASE}.100/32 ``` -------------------------------- ### Multiline Parameter Definition Example Source: https://www.keepalived.org/manpage.html Illustrates how to define a parameter that spans multiple lines using a backslash '\' at the end of each line except the last. This is useful for defining complex configurations like VRRP instances. ```plaintext $INSTANCE= \ **vrrp_instance **VI_${NUM} { \ **interface **eth0.${NUM} \ **use_vmac **vrrp${NUM}.1 \ **virtual_router_id **1 \ @high **priority **130 \ @low **priority **120 \ **advert_int **1 \ **virtual_ipaddress **{ \ 10.0.${NUM}.254/24 \ } \ **track_script **{ \ offset_instance_${NUM} \ } \ } $NUM=0 $INSTANCE $NUM=1 $INSTANCE ``` -------------------------------- ### Generating Multiple VRRP Instances with Sequence Blocks Source: https://www.keepalived.org/manpage.html This example demonstrates generating a large number of VRRP instances by using three nested sequence blocks for interface (IF), number (NUM), and ID. This will produce 65024 instances. ```keepalived $VI4= \ **track_file **offset_instance_4.${IF}.${NUM}.${ID} { \ **file **"${_PWD}/679/track_files/4.${IF}.${NUM}.${ID}" \ **weight **-100 \ } \ **vrrp_instance **vrrp4.${IF}.${NUM}.${ID} { \ **interface **bond${IF}.${NUM} \ **use_vmac **vrrp4.${IF}.${NUM}.${ID} \ **virtual_router_id **${ID} \ **priority **130 \ **virtual_ipaddress **{ \ 10.${IF}.${NUM}.${ID}/24 \ } \ **track_file **{ \ offset_instance_4.${IF}.${NUM}.${ID} \ } \ } **~SEQ**(IF,0,7) **~SEQ**(NUM,0,31) **~SEQ**(ID,1,254) $VI4 ``` -------------------------------- ### Conditional Configuration with Parameter Substitution Source: https://www.keepalived.org/manpage.html Shows how parameter substitution can be used with conditional configuration blocks (e.g., @main, @backup) to dynamically set values based on configuration context. ```plaintext $PRIORITY=240 @backup $PRIORITY=200 ... **vrrp_instance **VI_0 { **priority **$PRIORITY } ``` ```plaintext $IF_MAIN=@main $IF_MAIN **priority **240 ``` -------------------------------- ### Configure SSL Settings in Keepalived Source: https://www.keepalived.org/manpage.html Configure SSL parameters for secure connections. If no parameters are provided, the SSL context is auto-generated. ```keepalived SSL { password ca certificate key } ``` -------------------------------- ### Keepalived Track File Configuration Source: https://www.keepalived.org/manpage.html Defines how to track a file for state changes. The weight and initialization of the file can be configured. ```config track_file { file weight <-2147483647..2147483647> [reverse] init_file [VALUE] [overwrite] } ``` -------------------------------- ### Configure Notification Scripts in Keepalived Source: https://www.keepalived.org/manpage.html Define scripts to be executed when a VRRP instance changes state (MASTER, BACKUP, FAULT, STOP). Optional username and groupname can be specified. ```keepalived notify_master | [username [groupname]] ``` ```keepalived notify_backup | [username [groupname]] ``` ```keepalived notify_fault | [username [groupname]] ``` ```keepalived notify_stop | [username [groupname]] ``` ```keepalived notify | [username [groupname]] ``` -------------------------------- ### Enable Preemption in Keepalived Source: https://www.keepalived.org/manpage.html Allows a higher priority VRRP instance to take over the MASTER role when it becomes available. This is the default behavior. ```keepalived preempt ``` -------------------------------- ### Keepalived VRRP Track Process Configuration Source: https://www.keepalived.org/manpage.html Configures monitoring of a process for VRRP instances. Includes options for process matching, weight, and quorum. ```config vrrp_track_process { process | [| ...] param_match {initial|partial} weight <-254..254> [reverse] quorum NUM } ``` -------------------------------- ### Nested Sequence Blocks for IP Address Generation Source: https://www.keepalived.org/manpage.html Generates IPv6 addresses using nested hexadecimal sequence blocks. AD2 iterates from 0x90 to 0xc0, and AD1 iterates from 0x12 down to 0x0c. ```keepalived virtual_ipaddress { ~SEQx(AD2, 0x90, 0x10, 0xc0) ~SEQx(AD1, 0x12, -1, 0x0c) fe81::10:${AD2}:${AD1} } ``` -------------------------------- ### Configure Static Routes Source: https://www.keepalived.org/manpage.html Define static routes. These routes are managed by Keepalived and are not moved by VRRPd. Supports specifying next hops, table assignments, interface, and various route attributes like TOS, protocol, scope, and MTU. IPv6 routes can be specified using 'inet6'. ```keepalived static_routes { 192.168.2.0/24 via 192.168.1.100 dev eth0 track_group GROUP1 192.168.100.0/24 table 6909 nexthop via 192.168.101.1 dev wlan0 onlink weight 1 nexthop via 192.168.101.2 dev wlan0 onlink weight 2 192.168.200.0/24 dev p33p1.2 table 6909 tos 0x04 protocol bird scope link priority 12 mtu 1000 hoplimit 100 advmss 101 rtt 102 rttvar 103 reordering 104 window 105 cwnd 106 ssthresh lock 107 realms PQA/0x14 rto_min 108 initcwnd 109 initrwnd 110 vrf blue features ecn add 2001:470:69e9:1:2::4 dev p33p1.2 table 6909 tos 0x04 protocol bird scope link priority 12 mtu 1000 hoplimit 100 advmss 101 rtt 102 rttvar 103 reordering 104 window 105 cwnd 106 ssthresh lock 107 rto_min 108 initcwnd 109 append initrwnd 110 features ecn fastopen_no_cookie 1 ... } ``` -------------------------------- ### Sequence Block for IP Address Generation Source: https://www.keepalived.org/manpage.html Generates IP addresses by iterating through a subnet range. The SUBNET variable is incremented from 0 to 3, creating multiple IP addresses. ```keepalived ~SEQ(SUBNET, 0, 3) ip_address 10.0.${SUBNET}.1 ``` -------------------------------- ### Configure Linkbeat Interfaces Source: https://www.keepalived.org/manpage.html Specify the preferred method for polling network interface link status. Supported types include ETHTOOL and IOCTL. If the preferred type is not supported, Keepalived will attempt to use a supported alternative. ```keepalived linkbeat_interfaces { eth2 enp2s0 ETHTOOL } ``` -------------------------------- ### Configure Static Rules Source: https://www.keepalived.org/manpage.html Placeholder for configuring static rules. Keepalived can manage static rules, similar to 'ip rule add'. Rules require a preference to ensure consistent ordering. ```keepalived static_rules { ``` -------------------------------- ### Configure Preemption Delay in Keepalived Source: https://www.keepalived.org/manpage.html Sets a delay in seconds before a higher priority VRRP instance will preempt a lower priority instance. This can be used to stabilize the MASTER role. ```keepalived preempt_delay 300 # waits 5 minutes ``` -------------------------------- ### Enable Accept Mode in Keepalived VRRPv3 Source: https://www.keepalived.org/manpage.html Allows a VRRP instance, even when not the address owner, to receive packets addressed to a Virtual IP (VIP). This is the default behavior unless strict mode is enabled. ```keepalived accept ``` -------------------------------- ### Configure Master Receive Lower Priority Advert Notification Source: https://www.keepalived.org/manpage.html Specifies a script to execute when the MASTER instance receives a VRRP advertisement with a priority lower than its own. This can help in detecting potential issues. ```keepalived notify_master_rx_lower_pri | [username [groupname]] ``` -------------------------------- ### Keepalived Variable Substitution with Lists Source: https://www.keepalived.org/manpage.html Use ~LST blocks to substitute multiple variables simultaneously. Variables and their values must be enclosed in {...} for multiple substitutions per block. ```keepalived.conf ~LST({IP, IP1}, {10,1},{20,4},{5,6},{12,8}) 192.168.${IP}.${IP1} ``` -------------------------------- ### Configure UDP Check in Keepalived Source: https://www.keepalived.org/manpage.html Use UDP_CHECK for network health monitoring. Specify payload for custom data, require_reply to ensure a response, and define reply length constraints. ```keepalived UDP_CHECK { payload require_reply [] min_reply_length max_reply_length } ``` -------------------------------- ### Conditional Configuration in Keepalived Source: https://www.keepalived.org/manpage.html Use '@' for conditional configuration lines based on the config-id. '@^' inverts the condition. This allows a single file for multiple systems. ```keepalived global_defs { @main router_id main_router @backup router_id backup_router } ``` ```keepalived vrrp_instance VRRP { ... @main unicast_src_ip 1.2.3.4 @backup unicast_src_ip 1.2.3.5 @backup2 unicast_src_ip 1.2.3.6 unicast_peer { @^main 1.2.3.4 @^backup 1.2.3.5 @^backup2 1.2.3.6 } ... } ``` -------------------------------- ### Configure File Check in Keepalived Source: https://www.keepalived.org/manpage.html Use FILE_CHECK to monitor file content for health checks. The 'dynamic' option allows the file's value to adjust the weight. ```keepalived FILE_CHECK { track_file dynamic weight <-2147483647..2147483647> [reverse] } ``` -------------------------------- ### Configure Socket Receive Buffer Size Source: https://www.keepalived.org/manpage.html Sets the socket receive buffer size for VRRP. The policy for this setting is explained in the global_defs section under 'vrrp_rx_bufs_policy'. ```keepalived # Set socket receive buffer size (see global_defs # vrrp_rx_bufs_policy for explanation) ``` -------------------------------- ### Configure Virtual Routes in Keepalived Source: https://www.keepalived.org/manpage.html Define static routes that are added or deleted when a VRRP instance changes state to MASTER or BACKUP. This is useful for managing network reachability. ```keepalived virtual_routes { src 192.168.100.1 to 192.168.109.0/24 via 192.168.200.254 dev eth1 192.168.110.0/24 via 192.168.200.254 dev eth1 192.168.111.0/24 dev eth2 no_track 192.168.112.0/24 via 192.168.100.254 192.168.113.0/24 via 192.168.200.254 or 192.168.100.254 dev eth1 blackhole 192.168.114.0/24 0.0.0.0/0 gw 192.168.0.1 table 100 # To set a default gateway into table 100. } ``` -------------------------------- ### Configure Static IP Address Source: https://www.keepalived.org/manpage.html Define static IP addresses for an interface. These addresses are managed by Keepalived and are not moved by VRRPd. Options include specifying the IP address with a mask, broadcast address, device, scope, label, peer, and tracking group. ```keepalived static_ipaddress { 192.168.1.1/24 dev eth0 scope global ... } ``` -------------------------------- ### Enable SMTP Alerts in Keepalived Source: https://www.keepalived.org/manpage.html Configures Keepalived to send alerts via SMTP. This requires proper SMTP server configuration. ```keepalived smtp_alert ``` -------------------------------- ### Configure Advertisement Address Check Skip Source: https://www.keepalived.org/manpage.html Controls whether to skip checking the advertisement address. The default value is inherited from the global 'vrrp_skip_check_adv_addr' setting. ```keepalived skip_check_adv_addr [on|off|true|false|yes|no] ``` -------------------------------- ### Configure Virtual Rules in Keepalived Source: https://www.keepalived.org/manpage.html Define static rules that are added or deleted when a VRRP instance changes state. These rules can control packet routing based on source or destination. ```keepalived virtual_rules { from 192.168.2.0/24 table 1 to 192.168.2.0/24 table 1 no_track } ``` -------------------------------- ### Keepalived Combined List and Sequence Variable Substitution Source: https://www.keepalived.org/manpage.html Combine list blocks (~LST) and sequence blocks (~SEQ) for advanced variable substitution. This enables intricate IP address generation based on multiple variable sets. ```keepalived.conf ~LST({IP, IP1}, {10,1},{20,4},{5,6},{12,8}) ~SEQ(IP2,168,2,172) 192.${IP2}.${IP}.${IP1} ``` -------------------------------- ### Hexadecimal Sequence Block for IPv6 Addresses Source: https://www.keepalived.org/manpage.html Generates IPv6 addresses using hexadecimal values for the subnet. The SUBNET variable is incremented from 0x90 to 0xc0 in steps of 0x10. ```keepalived ~SEQx(SUBNET, 144, 16, 192) ip_address fe80::20:${SUBNET}:1 ``` ```keepalived ~SEQx(SUBNET, 0x90, 0x10, 0xc0) ip_address fe80::20:${SUBNET}:1 ``` -------------------------------- ### Configure Strict Mode in Keepalived Source: https://www.keepalived.org/manpage.html Enables or disables strict mode for VRRP. If not specified, it inherits the value from 'vrrp_strict'. If specified without a parameter, it defaults to 'on'. ```keepalived strict_mode [on|off|true|false|yes|no] ``` -------------------------------- ### Enable VRRP Priority Change Notifications Source: https://www.keepalived.org/manpage.html Enables sending notifications when VRRP instance priorities change. This can be useful for monitoring and alerting. ```keepalived notify_priority_changes ``` -------------------------------- ### Configure Debug Level in Keepalived Source: https://www.keepalived.org/manpage.html Sets the debug level for VRRP. The level is a number in the range of 0 to 4. This feature is not yet fully implemented. ```keepalived debug ``` -------------------------------- ### Keepalived Nested List Variable Substitution Source: https://www.keepalived.org/manpage.html List blocks can be nested to create more complex variable substitutions. This allows for combinations of variables across different list definitions. ```keepalived.conf ~LST(IP, 1, 2, 3, 4) ~LST(IP1, 5,6,7) 192.169.${IP}.${IP1} ``` -------------------------------- ### Disable Accept Mode in Keepalived VRRPv3 Source: https://www.keepalived.org/manpage.html Configures the VRRP instance to drop packets addressed to a Virtual IP (VIP) if the instance is not the current address owner. This enforces stricter packet handling. ```keepalived no_accept ```