LVS三种模式详解 - DR

DR模式(直接路由模式)

        Virtual server via direct routing (vs/dr)

        DR模式是通过改写请求报文的目标MAC地址,将请求发给真实服务器的,而真实服务器响应后的处理结果直接返回给客户端用户。

阅读全文 >>

keepalived 的启动脚本和安装脚本 的结合配置文件详解

keepalived 的启动脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/sh
#
# Startup script for the Keepalived daemon
#
# processname: keepalived
# pidfile: /var/run/keepalived.pid
# config: /etc/keepalived/keepalived.conf
# chkconfig: - 21 79
# description: Start and stop Keepalived
. /etc/init.d/functions
# Source configuration file (we set KEEPALIVED_OPTIONS there)
#. /etc/sysconfig/keepalived
KEEP_CONF="/export/servers/keepalived-1.2.13/conf/keepalived.conf"
KEEP_SBIN="/export/servers/keepalived-1.2.13/sbin/keepalived"
KEEP_PID="/var/run/keepalived.pid "
RETVAL=0
prog="keepalived"
start() {
echo -n $"Starting $prog: "
daemon $KEEP_SBIN --use-file=$KEEP_CONF
RETVAL=$?
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p $KEEP_PID $KEEP_SBIN -TERM
RETVAL=$?
echo
#[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
return $RETVAL
}
reload() {
echo -n $"Reloading $prog: "
#killproc keepalived -1
killproc -p $KEEP_PID $KEEP_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/lock/subsys/$prog ]; then
stop
start
fi
;;
status)
status keepalived
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|reload|restart|condrestart|status}"
RETVAL=1
esac
exit $RETVAL
=======
#!/bin/sh
#
# Startup script for the Keepalived daemon
#
# processname: keepalived
# pidfile: /var/run/keepalived.pid
# config: /etc/keepalived/keepalived.conf
# chkconfig: - 21 79
# description: Start and stop Keepalived
# Source function library
. /etc/init.d/functions
# Source configuration file (we set KEEPALIVED_OPTIONS there)
#. /etc/sysconfig/keepalived
KEEP_CONF="/export/servers/keepalived-1.2.13/conf/keepalived.conf"
KEEP_SBIN="/export/servers/keepalived-1.2.13/sbin/keepalived"
KEEP_PID="/var/run/keepalived.pid "
RETVAL=0
prog="keepalived"
start() {
echo -n $"Starting $prog: "
daemon $KEEP_SBIN --use-file=$KEEP_CONF
RETVAL=$?
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p $KEEP_PID $KEEP_SBIN -TERM
RETVAL=$?
echo
#[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
return $RETVAL
}
reload() {
echo -n $"Reloading $prog: "
#killproc keepalived -1
killproc -p $KEEP_PID $KEEP_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/lock/subsys/$prog ]; then
stop
start
fi
;;
status)
status keepalived
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|reload|restart|condrestart|status}"
RETVAL=1
esac
exit $RETVAL
>>>>>>> .r3360

阅读全文 >>

LVS原理详解及部署之四:keepalived介绍

一、keepalived原理介绍

keepalived简介

        Keepalived的功能有点像是两个人互相看着一个工作,如果一个人离开岗位另外一个人就会接替,这个keepalived就是他们之间保持这样“替换机制”的工具。keepalived是一个类似于layer3, 4 & 5交换机制的软件,也就是我们平时说的第3层、第4层和第5层交换。Keepalived的作用是检测web服务器的状态,如果有一台web服务器死机,或工作出现故障,Keepalived将检测到,并将有故障的web服务器从系统中剔除,当web服务器工作正常后Keepalived自动将web服务器加入到服务器群中,这些工作全部自动完成,不需要人工干涉,需要人工做的只是修复故障的web服务器。

阅读全文 >>

LVS原理详解及部署之五:LVS+keepalived实现负载均衡&高可用

一、实验环境需求&准备

        这次实验要完成的一个架构如下图所示,通过LVS-DR-MASTER,LVS-DR-BACKUP作为LVS负载均衡调度器,并且两者之间通过keepalived来两者之间的HA。keepalived本身就是为了LVS为开发的,所以说通过keepalived来进行LVS的配置就显得十分的方便。而且keepalived是直接操作ip_vs不用通过ipvsadm,所以更加方便。

阅读全文 >>

LVS的DR设置

1.环境说明

        三台机器

        director (eth0: 192.168.0.67, vip eth0:0: 192.168.0.64)

        real server1 (eth0 rip:192.168.0.66 ,vip lo:0:192.168.0.64)

        real server2 (eth0 rip:192.168.0.65 ,vip lo:0:192.168.0.64)

阅读全文 >>

LVS调度算法

        LVS主要的调度算法

        轮询调度-加权轮询调度-最小连接调度-加权最小连接调度-基于局部性的最少连接-带复制的基于局部性的最少连接-目标地址散列调度-源地址散列调度

阅读全文 >>

keepalived之vrrp_script总结

        通常情况下,利用keepalived做热备,其中一台设置为master,一台设置为backup。当master出现异常后,backup自动切换为master。当backup成为master后,master恢复正常后会再次抢占成为master,导致不必要的主备切换。因此可以将两台keepalived初始状态均配置为backup,设置不同的优先级,优先级高的设置nopreempt解决异常恢复后再次抢占的问题。

        然而keepalived只能做到对网络故障和keepalived本身的监控,即当出现网络故障或 者keepalived本身出现问题时,进行切换。但是这些还不够,我们还需要监控 keepalived所在服务器上的其他业务进程,根据业务进程的运行状态决定是否需要进行主备切换。这个时候,我们可以通过编写脚本对业务进程进行检测监控。

阅读全文 >>