keepalived最初設計的目的是爲了實現lvs前端director的高可用,很是輕量級。主要的實現的vrrp協議。前端
VRRP是一種容錯協議,它保證當主機的下一跳路由器出現故障時,由另外一臺路由器來代替出現故障的路由器進行工做,從而保持網絡通訊的連續性和可靠性。vim
簡化網絡管理:在具備多播或廣播能力的局域網(如以太網)中,藉助VRRP 能在某臺設備出現故障時仍然提供高可靠的缺省鏈路,有效避免單一鏈路發生故障後網絡中斷的問題,而無需修改動態路由協議、路由發現協議等配置信息,也無需修改主機的默認網關配置。瀏覽器
適應性強:VRRP 報文封裝在 IP 報文中,支持各類上層協議。網絡
網絡開銷小:VRRP 只定義了一種報文——VRRP 通告報文,而且只有處於Master 狀態的路由器能夠發送 VRRP 報文。負載均衡
LAMP平臺實現搭建好了。。若有須要請參考上一篇文章。yum搭建的很快捷、、主要想演示keepalived。ide
主server 192.168.1.111 eth0測試
備server 192.168.1.10 eth0spa
vip 192。168.1.222設計
yum -y install gcc*rest
yum install -y openssl openssl-devel poptpopt-devel libnl libnl-devel kernel-devel
mkdir /usr/local/keepalived
yum install popt-devel -y
mv Desktop/keepalived-1.2.2.tar.gz /home/
cd /home/
tar -zxvf keepalived-1.2.2.tar.gz
cd keepalived-1.2.2
./configure --prefix=/usr/local/keepalived
make && make install
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
chkconfig --add keepalived
chkconfig keepalived on
vim /etc/keepalived/keepalived.conf --編輯主機的配置文件
service keepalived restart
用ip a 進行查看。
備機安裝keepalived的方式與主機同樣,不作解釋。。
備機的配置文件也要進行修改:
ip addr show dev eth0
查看關聯的ip
好咱們測試:
下面咱們模擬主機宕機一下。
service keepalived stop
而後在備機上查看關聯ip
在瀏覽器上查看
完事。主備機的實驗就完成,,很簡單。。還有主主的服務負載均衡,改天再給你們演示。