blob: 009305c9d3bdbab1ffd9d78d82e06097e4d1331f [file] [log] [blame]
OlgaGusarenko29c21fd2018-07-30 18:52:30 +03001=====
2Usage
3=====
Filip Pytloun4ab64a02015-10-06 16:28:32 +02004
OlgaGusarenko29c21fd2018-07-30 18:52:30 +03005Keepalived is a routing software written in C. The main goal of this project
6is to provide simple and robust facilities for loadbalancing and
7high-availability to Linux system and Linux based infrastructures.
8Loadbalancing framework relies on well-known and widely used Linux Virtual
9Server (IPVS) kernel module providing Layer4 loadbalancing. Keepalived
10implements a set of checkers to dynamically and adaptively maintain and
11manage loadbalanced server pool according their health. On the other hand
12high-availability is achieved by VRRP protocol. VRRP is a fundamental brick
13for router failover. In addition, Keepalived implements a set of hooks to the
14VRRP finite state machine providing low-level and high-speed protocol
15interactions. Keepalived frameworks can be used independently or all together
16to provide resilient infrastructures.
Filip Pytloun4ab64a02015-10-06 16:28:32 +020017
18Sample pillar
19=============
20
OlgaGusarenko29c21fd2018-07-30 18:52:30 +030021Simple virtual IP on an interface:
Ales Komarek733b0922016-01-05 16:27:21 +010022
Filip Pytloun4ab64a02015-10-06 16:28:32 +020023.. code-block:: yaml
24
25 keepalived:
26 cluster:
27 enabled: True
28 instance:
Ales Komarek733b0922016-01-05 16:27:21 +010029 VIP1:
Jakub Pavlik2680d652016-08-26 17:35:40 +020030 nopreempt: True
Filip Pytloun4ab64a02015-10-06 16:28:32 +020031 priority: 100 (highest priority must be on primary server, different for cluster members)
32 virtual_router_id: 51
Vasyl Saienkoa4165fd2017-11-16 16:47:19 +020033 auth_type: AH
Filip Pytloun4ab64a02015-10-06 16:28:32 +020034 password: pass
35 address: 192.168.10.1
36 interface: eth0
Ales Komarek733b0922016-01-05 16:27:21 +010037 VIP2:
Jakub Pavlik2680d652016-08-26 17:35:40 +020038 nopreempt: True
Filip Pytloun4ab64a02015-10-06 16:28:32 +020039 priority: 150 (highest priority must be on primary server, different for cluster members)
40 virtual_router_id: 52
Vasyl Saienkoa4165fd2017-11-16 16:47:19 +020041 auth_type: PASS
Filip Pytloun4ab64a02015-10-06 16:28:32 +020042 password: pass
43 address: 10.0.0.5
44 interface: eth1
Ales Komarek733b0922016-01-05 16:27:21 +010045
OlgaGusarenko29c21fd2018-07-30 18:52:30 +030046Multiple virtual IPs on single interface:
Ales Komarek733b0922016-01-05 16:27:21 +010047
48.. code-block:: yaml
49
50 keepalived:
51 cluster:
52 enabled: True
53 instance:
54 VIP1:
Jakub Pavlik2680d652016-08-26 17:35:40 +020055 nopreempt: True
56 priority: 100 (highest priority must be on primary server, different for cluster members)
57 virtual_router_id: 51
58 password: pass
59 addresses:
60 - 192.168.10.1
61 - 192.168.10.2
62 interface: eth0
63
OlgaGusarenko29c21fd2018-07-30 18:52:30 +030064Use unicast:
Tomáš Kukrál1431a922017-05-25 17:04:18 +020065
66.. code-block:: yaml
67
68 keepalived:
69 cluster:
70 enabled: True
71 instance:
72 VIP1:
73 nopreempt: True
74 priority: 100 (highest priority must be on primary server, different for cluster members)
75 virtual_router_id: 51
76 password: pass
77 address: 192.168.10.1
78 interface: eth0
79 unicast_src_ip: 172.16.10.1
80 unicast_peer:
81 172.16.10.2
82 172.16.10.3
83
OlgaGusarenko29c21fd2018-07-30 18:52:30 +030084Disable nopreempt mode to have Master. Highest priority is taken
85in all cases:
Jakub Pavlik2680d652016-08-26 17:35:40 +020086
87.. code-block:: yaml
88
89 keepalived:
90 cluster:
91 enabled: True
92 instance:
93 VIP1:
94 nopreempt: False
95 priority: 100 (highest priority must be on primary server, different for cluster members)
96 virtual_router_id: 51
97 password: pass
98 addresses:
99 - 192.168.10.1
100 - 192.168.10.2
101 interface: eth0
102
OlgaGusarenko29c21fd2018-07-30 18:52:30 +0300103Notify action in keepalived:
Jakub Pavlik2680d652016-08-26 17:35:40 +0200104
105.. code-block:: yaml
106
107 keepalived:
108 cluster:
109 enabled: True
110 instance:
111 VIP1:
112 nopreempt: True
Filip Pytloun424120b2016-08-26 19:31:42 +0200113 notify_action:
114 master:
115 - /usr/bin/docker start jenkins
116 - /usr/bin/docker start gerrit
117 backup:
118 - /usr/bin/docker stop jenkins
119 - /usr/bin/docker stop gerrit
120 fault:
121 - /usr/bin/docker stop jenkins
122 - /usr/bin/docker stop gerrit
123 priority: 100 # highest priority must be on primary server, different for cluster members
Ales Komarek733b0922016-01-05 16:27:21 +0100124 virtual_router_id: 51
125 password: pass
126 addresses:
127 - 192.168.10.1
128 - 192.168.10.2
129 interface: eth0
Filip Pytloun4ab64a02015-10-06 16:28:32 +0200130
Petr Michalec97aab162017-02-21 14:16:18 +0100131Track/vrrp scripts for keepalived instance:
132
133.. code-block:: yaml
134
135 keepalived:
136 cluster:
137 enabled: True
138 instance:
139 VIP2:
140 priority: 100
141 virtual_router_id: 10
142 password: pass
143 addresses:
144 - 192.168.11.1
145 - 192.168.11.2
146 interface: eth0
Petr Michalec8863f472017-05-05 15:57:22 +0200147 track_script: check_haproxy
Petr Michalec97aab162017-02-21 14:16:18 +0100148 VIP3:
149 priority: 100
150 virtual_router_id: 11
151 password: pass
152 addresses:
153 - 192.168.10.1
154 - 192.168.10.2
155 interface: eth0
Petr Michalecb48338d2017-05-18 15:20:55 +0200156 track_script:
157 check_random_exit:
158 interval: 10
159 check_port:
160 weight: 50
Petr Michalec97aab162017-02-21 14:16:18 +0100161 vrrp_scripts:
Petr Michalec8863f472017-05-05 15:57:22 +0200162 check_haproxy:
163 name: check_pidof
164 args:
165 - haproxy
166 check_mysql_port:
167 name: check_port
168 args:
169 - 3306
170 - TCP
171 - 4
172 check_ssh:
173 name: check_port
174 args: "22"
175 check_mysql_cluster:
176 args:
177 # github: olafz/percona-clustercheck
178 # <user> <pass> <available_when_donor=0|1> <log_file> <available_when_readonly=0|1> <defaults_extra_file>
179 - clustercheck
180 - clustercheck
181 - available_when_donor=0
182 - available_when_readonly=0
183 check_random_exit:
Petr Michalec97aab162017-02-21 14:16:18 +0100184 interval: 10
Kostiantyn Kalynovskyid7cc29d2018-12-13 10:56:10 +0200185 timeout: 5
Petr Michalec97aab162017-02-21 14:16:18 +0100186 content: |
187 #!/bin/bash
188 exit $(($RANDOM%2))
Petr Michalecb48338d2017-05-18 15:20:55 +0200189 weight: 50
Petr Michalec97aab162017-02-21 14:16:18 +0100190
Filip Pytloun4ab64a02015-10-06 16:28:32 +0200191Read more
192=========
193
194* https://raymii.org/s/tutorials/Keepalived-Simple-IP-failover-on-Ubuntu.html