### Conditional Configuration Example Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/keepalived-conf.md Demonstrates how to use '@' for conditional configuration based on the config-id. Lines starting with '@' followed by an ID are included only if the config-id matches. '@^' is used for negative matching. ```keepalived global_defs { @main router_id main_router @backup router_id backup_router } ... 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 } ... } ``` -------------------------------- ### Enable and Start Keepalived Service with systemd Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/user-guide/installing.md Enable the keepalived service to start automatically at boot and start it immediately using systemctl. ```bash systemctl enable --now keepalived ``` -------------------------------- ### Enable and Start Keepalived Service Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/user-guide/quick-start.md Enable Keepalived to start on boot and start the service immediately on both nodes. ```bash # systemctl enable --now keepalived ``` -------------------------------- ### Install Prerequisites on Debian/Ubuntu Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/user-guide/installing.md Install essential build tools and development libraries required for compiling Keepalived from source on Debian/Ubuntu systems. ```bash apt-get install build-essential pkg-config curl gcc autoconf automake libssl-dev \ libnl-3-dev libnl-genl-3-dev libsnmp-dev libnl-route-3-dev libnfnetlink-dev \ iptables-dev* libipset-dev libsnmp-dev libmagic-dev libglib2.0-dev libpcre2-dev \ libnftnl-dev libmnl-dev libsystemd-dev libkmod-dev ``` -------------------------------- ### Install Prerequisites on Archlinux Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/user-guide/installing.md Install required libraries for compiling Keepalived from source on Archlinux. ```bash pacman -S ipset libnfnetlink libnl1 pcre-2 ``` -------------------------------- ### Download, Build, and Install Keepalived from Source Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/user-guide/installing.md Download the Keepalived source tarball using curl, extract it, configure the build, compile the package, and install it using make. ```bash curl --location --progress https://www.keepalived.org/software/keepalived-2.3.4.tar.gz | tar xz cd keepalived-2.3.4 ./configure make sudo make install ``` -------------------------------- ### Start and Enable Keepalived Service Source: https://github.com/acassen/keepalived/blob/master/README.md Enables Keepalived to start on boot and starts the service immediately. This command should be run on both master and backup nodes. ```sh sudo systemctl enable --now keepalived ``` -------------------------------- ### Install Prerequisites on Alpine Linux Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/user-guide/installing.md Install essential build tools and development libraries required for compiling Keepalived from source on Alpine Linux. ```bash autoconf automake iptables-dev ipset-dev libnfnetlink-dev libnl3-dev musl-dev libnftnl-dev file-dev pcre2-dev and openssl-dev or libressl-dev ``` -------------------------------- ### Build Keepalived from Source Source: https://github.com/acassen/keepalived/blob/master/README.md Clones the Keepalived repository, navigates into the directory, configures the build, and installs the software. Requires build tools and libraries listed in the INSTALL file. ```sh git clone https://github.com/acassen/keepalived.git cd keepalived ./configure make && sudo make install ``` -------------------------------- ### Conditional Parameter Substitution Example Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/keepalived-conf.md Shows how parameter substitution can be used with conditional configuration directives like @main and @backup. ```keepalived @main $PRIORITY=240 @backup $PRIORITY=200 ... vrrp_instance VI_0 { priority $PRIORITY } will produce: ... vrrp_instance VI_0 { priority 240 } if the config_id is main. ``` -------------------------------- ### Install Prerequisites on RHEL/CentOS/Fedora Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/user-guide/installing.md Install essential build tools and development libraries required for compiling Keepalived from source on RHEL-based systems. Replace dnf with yum on older systems. ```bash dnf install gcc make autoconf automake openssl-devel libnl3-devel \ iptables-devel ipset-devel net-snmp-devel libnfnetlink-devel file-devel \ glib2-devel pcre2-devel libnftnl-devel libmnl-devel systemd-devel kmod-devel ``` -------------------------------- ### Serve MkDocs Website Locally for Debugging Source: https://github.com/acassen/keepalived/blob/master/www/README.md Starts a local development server to preview the MkDocs website. Changes can be debugged by browsing to http://localhost:8000/. ```bash $ mkdocs serve ``` -------------------------------- ### Keepalived Syslog Output Example Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/user-guide/programs-synopsis.md This is an example of the log messages generated by Keepalived when it starts and loads its configuration. It shows global definitions, SSL settings, LVS topology, and health checker status. ```log Jun 7 18:17:03 lvs1 Keepalived: Starting Keepalived v0.6.1 (06/13, 2002) Jun 7 18:17:03 lvs1 Keepalived: Configuration is using : 92013 Bytes Jun 7 18:17:03 lvs1 Keepalived: ------< Global definitions >------ Jun 7 18:17:03 lvs1 Keepalived: LVS ID = LVS_PROD Jun 7 18:17:03 lvs1 Keepalived: Smtp server = 192.168.200.1 Jun 7 18:17:03 lvs1 Keepalived: Smtp server connection timeout = 30 Jun 7 18:17:03 lvs1 Keepalived: Email notification from = keepalived@domain.com Jun 7 18:17:03 lvs1 Keepalived: Email notification = alert@domain.com Jun 7 18:17:03 lvs1 Keepalived: Email notification = 0633556699@domain.com Jun 7 18:17:03 lvs1 Keepalived: ------< SSL definitions >------ Jun 7 18:17:03 lvs1 Keepalived: Using autogen SSL context Jun 7 18:17:03 lvs1 Keepalived: ------< LVS Topology >------ Jun 7 18:17:03 lvs1 Keepalived: System is compiled with LVS v0.9.8 Jun 7 18:17:03 lvs1 Keepalived: VIP = 10.10.10.2, VPORT = 80 Jun 7 18:17:03 lvs1 Keepalived: VirtualHost = www.domain1.com Jun 7 18:17:03 lvs1 Keepalived: delay_loop = 6, lb_algo = rr Jun 7 18:17:03 lvs1 Keepalived: persistence timeout = 50 Jun 7 18:17:04 lvs1 Keepalived: persistence granularity = 255.255.240.0 Jun 7 18:17:04 lvs1 Keepalived: protocol = TCP Jun 7 18:17:04 lvs1 Keepalived: lb_kind = NAT Jun 7 18:17:04 lvs1 Keepalived: sorry server = 192.168.200.200:80 Jun 7 18:17:04 lvs1 Keepalived: RIP = 192.168.200.2, RPORT = 80, WEIGHT = 1 Jun 7 18:17:04 lvs1 Keepalived: RIP = 192.168.200.3, RPORT = 80, WEIGHT = 2 Jun 7 18:17:04 lvs1 Keepalived: VIP = 10.10.10.3, VPORT = 443 Jun 7 18:17:04 lvs1 Keepalived: VirtualHost = www.domain2.com Jun 7 18:17:04 lvs1 Keepalived: delay_loop = 3, lb_algo = rr Jun 7 18:17:04 lvs1 Keepalived: persistence timeout = 50 Jun 7 18:17:04 lvs1 Keepalived: protocol = TCP Jun 7 18:17:04 lvs1 Keepalived: lb_kind = NAT Jun 7 18:17:04 lvs1 Keepalived: RIP = 192.168.200.4, RPORT = 443, WEIGHT = 1 Jun 7 18:17:04 lvs1 Keepalived: RIP = 192.168.200.5, RPORT = 1358, WEIGHT = 1 Jun 7 18:17:05 lvs1 Keepalived: ------< Health checkers >------ Jun 7 18:17:05 lvs1 Keepalived: 192.168.200.2:80 Jun 7 18:17:05 lvs1 Keepalived: Keepalive method = HTTP_GET Jun 7 18:17:05 lvs1 Keepalived: Connection timeout = 3 Jun 7 18:17:05 lvs1 Keepalived: Nb get retry = 3 Jun 7 18:17:05 lvs1 Keepalived: Delay before retry = 3 Jun 7 18:17:05 lvs1 Keepalived: Checked url = /testurl/test.jsp, Jun 7 18:17:05 lvs1 Keepalived: digest = 640205b7b0fc66c1ea91c463fac6334d Jun 7 18:17:05 lvs1 Keepalived: 192.168.200.3:80 Jun 7 18:17:05 lvs1 Keepalived: Keepalive method = HTTP_GET Jun 7 18:17:05 lvs1 Keepalived: Connection timeout = 3 Jun 7 18:17:05 lvs1 Keepalived: Nb get retry = 3 Jun 7 18:17:05 lvs1 Keepalived: Delay before retry = 3 Jun 7 18:17:05 lvs1 Keepalived: Checked url = /testurl/test.jsp, Jun 7 18:17:05 lvs1 Keepalived: digest = 640205b7b0fc66c1ea91c463fac6334c Jun 7 18:17:05 lvs1 Keepalived: Checked url = /testurl2/test.jsp, Jun 7 18:17:05 lvs1 Keepalived: digest = 640205b7b0fc66c1ea91c463fac6334c Jun 7 18:17:06 lvs1 Keepalived: 192.168.200.4:443 Jun 7 18:17:06 lvs1 Keepalived: Keepalive method = SSL_GET Jun 7 18:17:06 lvs1 Keepalived: Connection timeout = 3 Jun 7 18:17:06 lvs1 Keepalived: Nb get retry = 3 Jun 7 18:17:06 lvs1 Keepalived: Delay before retry = 3 Jun 7 18:17:06 lvs1 Keepalived: Checked url = /testurl/test.jsp, Jun 7 18:17:05 lvs1 Keepalived: digest = 640205b7b0fc66c1ea91c463fac6334d Jun 7 18:17:06 lvs1 Keepalived: Checked url = /testurl2/test.jsp, Jun 7 18:17:05 lvs1 Keepalived: digest = 640205b7b0fc66c1ea91c463fac6334d Jun 7 18:17:06 lvs1 Keepalived: 192.168.200.5:1358 Jun 7 18:17:06 lvs1 Keepalived: Keepalive method = TCP_CHECK Jun 7 18:17:06 lvs1 Keepalived: Connection timeout = 3 Jun 7 18:17:06 lvs1 Keepalived: Registering Kernel netlink reflector ``` -------------------------------- ### Start Keepalived Daemon Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/user-guide/programs-synopsis.md Use this command to start the Keepalived service on systems using systemd. ```bash # systemctl start keepalived ``` -------------------------------- ### Setting up Test Environment with mk_if Script Source: https://github.com/acassen/keepalived/blob/master/www/docs/release-notes/Release-2.1.4.md This snippet is part of the 'mk_if' script, which has been extended to provide a more flexible test environment setup. ```bash #!/bin/sh # # mk_if # # This script is used to set up a test environment for keepalived. # It is not intended for use in production. # # Usage: mk_if # # Example: mk_if eth0 192.168.1.100 # if [ $# -ne 2 ]; then echo "Usage: $0 " exit 1 fi INTERFACE=$1 IPADDR=$2 # Add IP address to interface /sbin/ip addr add $IPADDR/24 dev $INTERFACE # Bring interface up /sbin/ip link set $INTERFACE up # Add default route /sbin/ip route add default via 192.168.1.1 # Enable IP forwarding echo 1 > /proc/sys/net/ipv4/ip_forward exit 0 ``` -------------------------------- ### Example iptables logging rule Source: https://github.com/acassen/keepalived/blob/master/www/docs/Keepalived-LVS-NAT-Director-ProxyArp-Firewall-HOWTO.html This example shows how to log firewall hits to the system logs with a default log level. You can add a custom log prefix by appending '--log-prefix "YourPrefix"' to the rule. ```bash /sbin/iptables -A INPUT -i $EXTIF -p tcp -s 1.2.3.4 $LOG ``` -------------------------------- ### Install DBUS Support Prerequisites on RHEL/CentOS/Fedora Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/user-guide/installing.md Install the glib2 development library for DBUS support when compiling Keepalived from source on RHEL-based systems. ```bash dnf install glib2-devel ``` -------------------------------- ### Install Keepalived on Debian Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/user-guide/installing.md Use apt-get to install the keepalived package and its dependencies from the distribution's repositories. ```bash apt-get install keepalived ``` -------------------------------- ### Install Keepalived on Debian/Ubuntu and RHEL/Fedora Source: https://github.com/acassen/keepalived/blob/master/README.md Installs Keepalived using the system's package manager. Use the appropriate command for your distribution. ```sh sudo apt install keepalived # Debian / Ubuntu sudo dnf install keepalived # RHEL / Fedora / Rocky ``` -------------------------------- ### Install JSON Support Prerequisites on RHEL/CentOS/Fedora Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/user-guide/installing.md Install the json-c development library for JSON support when compiling Keepalived from source on RHEL-based systems. ```bash dnf install json-c-devel ``` -------------------------------- ### Build and Install Keepalived Source: https://github.com/acassen/keepalived/blob/master/www/docs/LVS-NAT-Keepalived-HOWTO.html Compiles and installs Keepalived from source. Ensure all necessary development libraries and header files are present before running. ```bash tar xzvf keepalived-0.7.1.tar.gz; cd keepalived-0.7.1; ./configure; make; make install ``` -------------------------------- ### Nested Multiline Parameter Substitution Example Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/keepalived-conf.md Demonstrates nested multiline parameter definitions, creating complex configurations like virtual servers with multiple real servers. ```keepalived $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" \ quorum_down "${_PWD}/scripts/notify.sh VS_notify.${INST} DOWN 10.0.${VS_NUM}.4:80" \ $RS_NUM=1 \ $RS \ $RS_NUM=2 \ $RS \ $RS_NUM=3 \ $RS \ } $VS_NUM=0 $ALPHA=alpha $VS $VS_NUM=1 $ALPHA= $VS ``` -------------------------------- ### Install Keepalived on Debian/Ubuntu Source: https://github.com/acassen/keepalived/blob/master/www/docs/download.md Use this command to install Keepalived on Debian-based systems like Ubuntu. ```shell sudo apt install keepalived ``` -------------------------------- ### Install Keepalived on RHEL/Fedora/Rocky Source: https://github.com/acassen/keepalived/blob/master/www/docs/download.md Use this command to install Keepalived on RHEL, Fedora, or Rocky Linux. ```shell sudo dnf install keepalived ``` -------------------------------- ### Example SuSE 8.0 Keepalived Startup Script Source: https://github.com/acassen/keepalived/blob/master/www/docs/LVS-NAT-Keepalived-HOWTO.html This is a template for an LSB-compliant service control script for Keepalived on SuSE 8.0. It includes standard init info directives. ```shell #! /bin/sh # Copyright (c) 1995-2002 SuSE Linux AG, Nuernberg, Germany. # All rights reserved. # # Author of template: Kurt Garloff # Modified for keepalived by Adam Fletcher # # /etc/init.d/keepalived # # # LSB compliant service control script; see [http://www.linuxbase.org/spec/] # # System startup script for some example service or daemon keepalived (template) # ### BEGIN INIT INFO # Provides: keepalived # Required-Start: $remote_fs $syslog # Required-Stop:� $remote_fs $syslog # Default-Start:� 3 5 # Default-Stop:�� 0 1 2 6 # Description:��� Start keepalived to allow XY and provide YZ #������ continued on second line by '#' ### END INIT INFO ``` -------------------------------- ### Example iptables logging rule with custom prefix Source: https://github.com/acassen/keepalived/blob/master/www/docs/Keepalived-LVS-NAT-Director-ProxyArp-Firewall-HOWTO.html This example demonstrates how to log firewall hits with a custom log prefix. The '$LOG' variable is defined to include the '-j LOG --log-level 6' options. ```bash /sbin/iptables -A INPUT -i $EXTIF -p tcp -s 3.4.5.6 $LOG --log-prefix "Some Hacker! :" ``` -------------------------------- ### Nested Sequence Blocks Example Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/keepalived-conf.md Demonstrates nesting multiple sequence blocks to generate complex configurations, such as nested IPv6 addresses. ```keepalived Another example: virtual_ipaddress { ~SEQx(AD2, 0x90, 0x10, 0xc0) ~SEQx(AD1, 0x12, -1, 0x0c) fe81::10:${AD2}:${AD1} } ``` -------------------------------- ### Install SNMP Support Prerequisites on Archlinux Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/user-guide/installing.md Install net-snmp package for SNMP support on Archlinux when compiling Keepalived from source. ```bash pacman -S net-snmp ``` -------------------------------- ### Recursive Parameter Substitution Example Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/keepalived-conf.md Demonstrates how parameter substitution can be recursive. Note the use of braces when parameters are not followed by whitespace. ```keepalived $ADDRESS_BASE=10.2.${ADDRESS_BASE_SUB} $ADDRESS_BASE_SUB=0 ${ADDRESS_BASE}.100/32 $ADDRESS_BASE_SUB=10 ${ADDRESS_BASE}.100/32 will produce: 10.2.0.100/32 10.2.10.100/32 ``` -------------------------------- ### Create and Activate Virtual Environment Source: https://github.com/acassen/keepalived/blob/master/www/README.md Generates a local Python virtual environment and installs all MkDocs Material dependencies within it. This isolates project dependencies. ```bash $ python3 -m venv .venv $ . .venv/bin/activate $ pip install "mkdocs-material[all]" ``` -------------------------------- ### Example Keepalived Configuration Summary with SNMP Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/user-guide/snmp-support.md This output shows a typical configuration summary during Keepalived compilation, indicating that SNMP support is enabled and listing relevant libraries. ```text ./configure --prefix=/usr/local/keepalived-2.3.4 --enable-snmp Keepalived configuration ------------------------ Keepalived version : 2.3.4 Compiler : gcc Compiler flags : -g -O2 -I/usr/include/libnl3 Extra Lib : -Wl,-z,relro -Wl,-z,now -L/usr/lib64 -lnetsnmpagent -lnetsnmphelpers -lnetsnmpmibs -lnetsnmp -Wl,-E -Wl,-rpath,/usr/lib64/perl5/CORE -lssl -lcrypto -lcrypt -lnl-genl-3 -lnl-3 Use IPVS Framework : Yes IPVS sync daemon support : Yes IPVS use libnl : Yes fwmark socket support : Yes Use VRRP Framework : Yes Use VRRP VMAC : Yes SNMP support : Yes SHA1 support : No Use Debug flags : No ``` -------------------------------- ### List Block Example (Multiple Variables) Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/keepalived-conf.md Allows substituting multiple variables simultaneously from corresponding lists of values. Useful for generating configurations with multiple dynamic parameters. ```keepalived ~LST({IP, IP1}, {10,1},{20,4},{5,6},{12,8}) 192.168.${IP}.${IP1} would produce: 192.168.10.1 192.168.20.4 192.168.5.6 192.168.12.8 ``` -------------------------------- ### Quoted String Example 2 Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/keepalived-conf.md Shows how nested quotes are handled, resulting in multiple strings when inner quotes are present. ```text 'abcd "efg h jkl" mnop' ``` -------------------------------- ### Install SNMP Support Prerequisites on Alpine Linux Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/user-guide/installing.md Install net-snmp development package for SNMP support on Alpine Linux when compiling Keepalived from source. Note the dependency on libressl-dev. ```bash net-snmp-dev (requires libressl-dev and not openssl-dev) ``` -------------------------------- ### Interpreted Script Parameters Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/keepalived-conf.md Shows the interpreted values of the parameters passed to the notify_master script in the previous example. ```text ' spaces\x20file ', '"s p a c e "', 'SG1.low' and 'master' ``` -------------------------------- ### Sample iptables Stateful Firewall Script Source: https://github.com/acassen/keepalived/blob/master/www/docs/Keepalived-LVS-NAT-Director-ProxyArp-Firewall-HOWTO.html This is a sample bash script for configuring a stateful firewall using iptables. It is intended for use with an LVS-NAT director setup. ```bash #!/bin/bash ``` -------------------------------- ### Multiline Parameter Definition Example Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/keepalived-conf.md Illustrates defining a multiline parameter using the backslash character to continue definitions across lines. ```keepalived $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 ``` -------------------------------- ### Sequence Block Example (Decimal) Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/keepalived-conf.md Generates multiple lines by iterating a variable through a defined range. Useful for generating IP addresses or other sequential parameters. ```keepalived ~SEQ(SUBNET, 0, 3) ip_address 10.0.${SUBNET}.1 would produce: ip_address 10.0.0.1 ip_address 10.0.1.1 ip_address 10.0.2.1 ip_address 10.0.3.1 ``` -------------------------------- ### Using ${_HASH} and ${_BANG} for Conditional Configuration Source: https://github.com/acassen/keepalived/blob/master/www/docs/release-notes/Release-2.1.4.md Demonstrates how to use ${_HASH} and ${_BANG} to conditionally enable or disable configuration lines. These are replaced by '#' and '!' respectively, allowing for commented-out sections without starting a comment. ```conf $TEST=${_HASH} $TEST test config ``` ```conf $TEST= or even $TEST=#${_HASH} ``` -------------------------------- ### Sequence Block Example (Hexadecimal) Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/keepalived-conf.md Generates multiple lines using hexadecimal representation for a variable. Particularly useful for IPv6 addresses. ```keepalived ~SEQx(SUBNET, 144, 16, 192) ip_address fe80::20:${SUBNET}:1 or better ~SEQx(SUBNET, 0x90, 0x10, 0xc0) ip_address fe80::20:${SUBNET}:1 would produce: ip_address fe80::20:90:1 ip_address fe80::20:a0:1 ip_address fe80::20:b0:1 ip_address fe80::20:c0:1 ``` -------------------------------- ### ipvsadm Output Source: https://github.com/acassen/keepalived/blob/master/www/docs/LVS-NAT-Keepalived-HOWTO.html Shows the output of the 'ipvsadm' command after Keepalived has started, detailing the configured virtual server and its associated real server. ```bash example-01:~ # ipvsadm IP Virtual Server version 1.0.4 (size=65536) Prot LocalAddress:Port Scheduler Flags � -> RemoteAddress:Port���������� Forward Weight ActiveConn InActConn TCP� 192.168.1.11:ssh rr � -> 10.20.40.10:ssh����������� Masq��� 1����� 0��������� 0 example-01:~ # ``` -------------------------------- ### List Block Example (Single Variables) Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/keepalived-conf.md Generates lines by substituting values from a list into a variable. Useful for defining a set of specific parameters. ```keepalived ~LST(var, val1, val2, val3) ... ~LST(IP, 1, 2, 3, 4) ~LST(IP1, 5,6,7) 192.169.${IP}.${IP1} produces: 192.169.1.5 192.169.1.6 192.169.1.7 192.169.2.5 192.169.2.6 192.169.2.7 192.169.3.5 192.169.3.6 192.169.3.7 192.169.4.5 192.169.4.6 192.169.4.7 ``` -------------------------------- ### Global Definitions Configuration Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/user-guide/configuration-synopsis.md Example of the global_defs block, including email notifications, SMTP server settings, router ID, multicast group for VRRP, and LVS sync daemon binding. ```keepalived global_defs { notification_email { admin@example.com } notification_email_from keepalived@example.com smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_MAIN # send an email on every state transition smtp_alert # multicast group used for VRRP adverts (default is RFC assigned) vrrp_mcast_group4 224.0.0.18 # bind the IPVS synchronisation daemon to an interface and an instance lvs_sync_daemon eth0 VI_1 } ``` -------------------------------- ### Configure Keepalived Build with Custom Prefix Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/user-guide/installing.md Configure the Keepalived build process to install into a specific directory using the --prefix option. This facilitates easier uninstallation and management of multiple versions. ```bash ./configure --prefix=/usr/local/keepalived-2.3.4 ``` -------------------------------- ### Keepalived SSL Server Health Check Configuration Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/user-guide/case-study-healthcheck.md Configure SSL_GET checkers for SSL server health checks. This example shows how to set up real servers with specific weights and failure detection parameters for SSL services. ```nginx virtual_server 192.168.200.15 443 { delay_loop 20 lb_algo rr lb_kind NAT persistence_timeout 360 protocol TCP real_server 192.168.100.2 443 { weight 1 SSL_GET { url { path /testurl/test.jsp digest ec90a42b99ea9a2f5ecbe213ac9eba03 } url { path /testurl2/test.jsp digest 640205b7b0fc66c1ea91c463fac6334c } connect_timeout 3 retry 3 delay_before_retry 2 } } real_server 192.168.100.3 443 { weight 1 SSL_GET { url { path /testurl/test.jsp digest 640205b7b0fc66c1ea91c463fac6334c } connect_timeout 3 retry 3 delay_before_retry 2 } } } ``` -------------------------------- ### Keepalived Debug Log Output Source: https://github.com/acassen/keepalived/blob/master/www/docs/LVS-NAT-Keepalived-HOWTO.html Example log messages when Keepalived is started with the -d flag, showing global definitions, SSL context, VRRP topology, and LVS topology. ```log Sep 12 14:13:11 example-01 Keepalived: ------< Global definitions >------ Sep 12 14:13:11 example-01 Keepalived:� LVS ID = LVS_EXAMPLE_01 Sep 12 14:13:11 example-01 Keepalived:� Smtp server = 127.0.0.1 Sep 12 14:13:11 example-01 Keepalived:� Smtp server connection timeout = 100 Sep 12 14:13:11 example-01 Keepalived:� Email notification from = admins@example.com, fakepager@example.com Sep 12 14:13:11 example-01 Keepalived:� Email notification = admins@example.com Sep 12 14:13:11 example-01 Keepalived: ------< SSL definitions >------ Sep 12 14:13:11 example-01 Keepalived:� Using autogen SSL context Sep 12 14:13:11 example-01 Keepalived: ------< VRRP Topology >------ Sep 12 14:13:11 example-01 Keepalived:� VRRP Instance = VI_1 Sep 12 14:13:11 example-01 Keepalived:��� Want State = MASTER Sep 12 14:13:11 example-01 Keepalived:��� Runing on device = eth0 Sep 12 14:13:11 example-01 Keepalived:��� Virtual Router ID = 51 Sep 12 14:13:11 example-01 Keepalived:��� Priority = 150 Sep 12 14:13:11 example-01 Keepalived:��� Advert interval = 1sec Sep 12 14:13:11 example-01 Keepalived:��� Preempt Active Sep 12 14:13:11 example-01 Keepalived:��� Authentication type = SIMPLE_PASSWORD Sep 12 14:13:11 example-01 Keepalived:��� Password = example Sep 12 14:13:11 example-01 Keepalived:��� VIP count = 1 Sep 12 14:13:11 example-01 Keepalived:����� VIP1 = 192.168.1.11/32 Sep 12 14:13:11 example-01 Keepalived:� VRRP Instance = VI_GATEWAY Sep 12 14:13:11 example-01 Keepalived:��� Want State = MASTER Sep 12 14:13:11 example-01 Keepalived:��� Runing on device = eth1 Sep 12 14:13:11 example-01 Keepalived:��� Virtual Router ID = 52 Sep 12 14:13:11 example-01 Keepalived:��� Priority = 150 Sep 12 14:13:11 example-01 Keepalived:��� Advert interval = 1sec Sep 12 14:13:11 example-01 Keepalived:��� Preempt Active Sep 12 14:13:11 example-01 Keepalived:��� Authentication type = SIMPLE_PASSWORD Sep 12 14:13:11 example-01 Keepalived:��� Password = example Sep 12 14:13:11 example-01 Keepalived:��� VIP count = 1 Sep 12 14:13:11 example-01 Keepalived:����� VIP1 = 10.20.40.1/32 Sep 12 14:13:11 example-01 Keepalived: ------< VRRP Sync groups >------ Sep 12 14:13:11 example-01 Keepalived:� VRRP Sync Group = VG1, MASTER Sep 12 14:13:11 example-01 Keepalived:��� monitor = VI_1 Sep 12 14:13:11 example-01 Keepalived:��� monitor = VI_GATEWAY Sep 12 14:13:11 example-01 Keepalived: ------< LVS Topology >------ Sep 12 14:13:11 example-01 Keepalived:� System is compiled with LVS v1.0.4 Sep 12 14:13:11 example-01 Keepalived:� VIP = 192.168.1.11, VPORT = 22 Sep 12 14:13:11 example-01 Keepalived:��� delay_loop = 10, lb_algo = rr Sep 12 14:13:11 example-01 Keepalived:��� protocol = TCP Sep 12 14:13:11 example-01 Keepalived:��� lb_kind = NAT Sep 12 14:13:11 example-01 Keepalived:��� RIP = 10.20.40.11, RPORT = 22, WEIGHT = 1 Sep 12 14:13:11 example-01 Keepalived: ------< Health checkers >------ Sep 12 14:13:11 example-01 Keepalived:� 10.20.40.11:22 Sep 12 14:13:11 example-01 Keepalived:��� Keepalive method = TCP_CHECK Sep 12 14:13:11 example-01 Keepalived:��� Connection timeout = 10 Sep 12 14:13:11 example-01 Keepalived:��� Connection port = 22 ``` -------------------------------- ### Install Keepalived on Alpine Source: https://github.com/acassen/keepalived/blob/master/www/docs/download.md Use this command to install Keepalived on Alpine Linux. ```shell sudo apk add keepalived ``` -------------------------------- ### Install Keepalived on Arch Linux Source: https://github.com/acassen/keepalived/blob/master/www/docs/download.md Use this command to install Keepalived on Arch Linux. ```shell sudo pacman -S keepalived ``` -------------------------------- ### Script Execution with Parameters Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/keepalived-conf.md Illustrates how to pass parameters to scripts, including handling spaces within parameters using single quotes and using shell variables. ```bash $SG_NAME=SG1 $INST=low $USER=user notify_master "/etc/keepalived/notify_event.sh ' spaces\x20f\x69le ' '\"s p a c e \"' ${SG_NAME}.${INST} master" $USER group ``` -------------------------------- ### Build MkDocs Website Content Source: https://github.com/acassen/keepalived/blob/master/www/README.md Compiles the MkDocs website content into static files for deployment. ```bash $ mkdocs build ``` -------------------------------- ### Install Keepalived on Red Hat Enterprise Linux Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/user-guide/installing.md Use dnf (or yum) to install the keepalived package and its dependencies from the distribution's repositories. ```bash dnf install keepalived ``` -------------------------------- ### SSL GET Healthchecker Configuration Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/keepalived-conf.md Configure SSL GET health checks. This includes options for enabling Server Name Indicator (SNI) and complying with TLS protocol by sending a close_notify alert. ```keepalived SSL_GET { enable_sni tls_compliant } ``` -------------------------------- ### HTTP GET Healthchecker Configuration Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/keepalived-conf.md Configure HTTP GET health checks for virtual servers. Supports specifying protocol version, recovery behavior, and detailed URL checks including path, digest, status codes, virtual host, regex matching, and SSL/TLS options. ```keepalived HTTP_GET { http_protocol fast_recovery [] url { path digest status_code [] ... virtualhost regex regex_no_match regex_options regex_stack regex_min_offset regex_max_offset } } ``` -------------------------------- ### Quoted String Example 1 Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/keepalived-conf.md Demonstrates how whitespace is retained and quotes are removed when a string is enclosed in single quotes. ```text 'abcd" efg h jkl "mnop' ``` -------------------------------- ### Combined List and Sequence Blocks Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/keepalived-conf.md Demonstrates combining list and sequence blocks to generate configurations with both predefined sets of values and sequential ranges. ```keepalived ~LST({IP, IP1}, {10,1},{20,4},{5,6},{12,8}) ~SEQ(IP2,168,2,172) 192.${IP2}.${IP}.${IP1} produces: 192.168.10.1 192.170.10.1 192.172.10.1 192.168.20.4 192.170.20.4 192.172.20.4 192.168.5.6 192.170.5.6 192.172.5.6 192.168.12.8 192.170.12.8 192.172.12.8 ``` -------------------------------- ### Populate User-Defined Chains Message Source: https://github.com/acassen/keepalived/blob/master/www/docs/Keepalived-LVS-NAT-Director-ProxyArp-Firewall-HOWTO.html A simple echo command to indicate the start of populating user-defined chains during script execution. ```bash echo " Populating User-Defined Chains..." ``` -------------------------------- ### Multiple Sequence Blocks on One Line Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/keepalived-conf.md Shows how to use multiple sequence blocks on a single line to generate a large number of configurations, like multiple VRRP 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 will produce 65024 vrrp instances with names from vrrp4.0.0.1 through to vrrp4.7.31.254. ``` -------------------------------- ### Verify IPVS Configuration Source: https://github.com/acassen/keepalived/blob/master/www/docs/documentation/user-guide/quick-start.md Check that the virtual server and real servers have been programmed into the kernel's IPVS table. ```bash # ipvsadm -Ln ``` -------------------------------- ### Source SuSE Configuration Source: https://github.com/acassen/keepalived/blob/master/www/docs/LVS-NAT-Keepalived-HOWTO.html Loads configuration variables from the SuSE rc.config file if it exists. This is typically used in init scripts. ```bash test -r /etc/rc.config && . /etc/rc.config ```