keepalived.conf說明
from http://openwares.net/database/keepalived-postgresql-streaming-replication-auto-failover.html
from https://www.zhangluya.com/?p=190
from https://mag.osdn.jp/13/05/14/083000/4
# Configuration File for keepalivedglobal_defs { notification_email { admin@domain.tld # 接收通知的email } notification_email_from admin@domain.tld # 发送通知的email地址 smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id vmin # 标识机器,可以使用机器名,主备不能相同}vrrp_script chk_pgsql { # script "/path/script.sh" script "sudo -u postgres psql -c 'select 1'" interval 2 # 2秒检查一次 weight -2 # 检查失败(返回值非0)时,优先级加-2,其他情况优先级保持不变.默认值为2}vrrp_instance VI_1 { state BACKUP # 初始状态,主备可都设置为BACKUP,启动后会自动选举优先级高者为master # 如果高优先级的服务器设置为MASTER,就算设置了nopreempt,当重新启动keepalived实例时,仍然会抢占vip interface br0 # vrrp绑定接口 #use_vmac # 使用虚拟MAC地址,地址格式为00-00-5E-00-01-<virtual_router_id>,主备设置相同 #vmac_xmit_base # 不使用虚拟接口收发VRRP报文 virtual_router_id 50 # 虚拟路由id,主备必须使用相同的配置 track_interface { br0 # 监测的网络接口,当此接口不可用时会引起主备切换,可有多个被监测的接口 } nopreempt # 非抢占模式,master设置为nopreempt,backup不要设置, # 当高优先级的master重新恢复上线时,不会抢占当前低优先级的backup priority 100 # 初始优先级,取值范围为0-255, master可设置为100, backup设置为99 advert_int 1 # VRRP 通告时间间隔 virtual_ipaddress { 192.168.0.200 # 对外提供服务器的虚拟地址,主备设置相同 } authentication { auth_type PASS # 认证类型,master与backup必须一致 auth_pass 1234 # 认证密码,只使用前8个字符,master与backup必须一致 } # 如果使用参数调用的脚本,将脚本及参数用引号包围 notify_master "/usr/local/bin/notify.sh master" # 状态转移为master时执行的脚本 notify_backup "/usr/local/bin/notify.sh backup" # 状态转移为backup时执行的脚本 notify_fault "/usr/local/bin/nofity.sh fault" # 状态转移为故障时执行的脚本 # 当发生任何的状态变化时,在nofity_*脚本之后被调用,调用时会提供三个参数: # $1 = "GROUP"|"INSTANCE" # $2 = 组或实例的名字 # $3 = 变化的目标状态 # ("MASTER"|"BACKUP"|"FAULT") nofity "/usr/local/bin/notify.sh" # 发送邮件通知,使用global_defs中的定义 # smtp_alert track_script { chk_pgsql # 使用检查脚本 }}from https://www.zhangluya.com/?p=190
#unicast_src_ip 表示发送VRRP单播报文使用的源IP地址 Master本地内网IP地址
unicast_src_ip 10.10.0.15
unicast_src_ip 10.10.0.15
#unicast_peer 表示对端接收VRRP单播报文的IP地址
unicast_peer {
10.10.0.16
}
unicast_peer {
10.10.0.16
}
from https://mag.osdn.jp/13/05/14/083000/4
! Configuration File for Keepalived
global_defs {
notification_email {
hirom@example.org ←通知メールの送信先メールアドレスを指定
}
notification_email_from hirom@example.org ←通知メールの送信元メールアドレスを指定
smtp_server 203.0.113.200 ←メール送信に使用するSMTPサーバーのIPアドレスを指定
smtp_connect_timeout 30
router_id LVS_DEVEL ←ロードバランサを識別するための名前を指定
}
vrrp_instance Sakura { ←VRRP設定名を指定
state BACKUP ←「BACKUP」もしくは「MASTER」を指定
interface eth0 ←クライアントが接続する側のNICを指定
garp_master_delay 5 ←バックアップがマスターに昇格後、Gratuitous ARPパケットを送信するまでの待機時間を秒で指定
virtual_router_id 1 ←仮想ルーターIDを指定
priority 100 ←優先度を指定
nopreempt ←停止していたマスターが復帰した際にマスターを譲らない
advert_int 3 ←VRRP広告パケットの送信間隔を秒で指定
authentication { ←認証に関する設定
auth_type AH ←認証タイプとしてIPsec AHを使用
auth_pass sfjpvrrp ←認証用のパスワード文字列
}
virtual_ipaddress { ←使用する仮想IPアドレスを指定
133.242.98.142 dev eth0 ←eth0側のIPアドレスを指定
192.168.100.100/24 dev eth1 ←eth1側のIPアドレスを指定
}
}
virtual_server 203.0.113.100 80 { ←対象とする仮想サービスを指定
delay_loop 5 ←死活監視のためのポーリング間隔を秒で指定
lvs_sched rr ←負荷分散方式を指定
lvs_method NAT ←パケットの転送方式を指定
protocol TCP ←対象とするプロトコルを指定
sorry_server 192.168.100.20 80 ←サーバーがすべて停止した場合のパケット転送先を指定
real_server 192.168.100.21 80 { ←仮想サービスに対応するサーバーを指定
weight 1 ←負荷分散の重みを指定
inhibit_on_failure ←サービスが停止した場合には重みを0にする
HTTP_GET { ←ポーリングに使用するプロトコルを指定
url {
path / ←ポーリング先URLを指定
status_code 200 ←正常な場合に返されるステータスコードを指定
}
connect_timeout 5 ←ポーリングのタイムアウト時間を秒で指定
nb_get_retry 3 ←リトライ回数を指定
delay_before_retry 3 ←リトライ時に待機する時間を秒で指定
}
}
real_server 192.168.100.22 80 {
weight 1
inhibit_on_failure
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 5
nb_get_retry 3
delay_before_retry 3
}
}
}
留言
張貼留言