两台虚拟机

两台配置操作一样

环境配置

[root@lb01 /]# yum -y install openssl openssl-devel
[root@lb01 /]# yum -y install kernel-devel 

做个软连接  用tab键补全2.6.32-642.6.2.el6.x86_64

[root@lb01 /]# ln -s /usr/src/kernels/2.6.-642.6..el6.x86_64/ /usr/src/linux
[root@lb01 /]# ls -l /usr/src/
total
drwxr-xr-x. root root Sep debug
drwxr-xr-x. root root Oct : kernels
lrwxrwxrwx root root Oct : linux -> /usr/src/kernels/2.6.-642.6..el6.x86_64/

下载软件、解压、配置、编译、安装

[root@lb01 /]# wget http://www.keepalived.org/software/keepalived-1.2.16.tar.gz
[root@lb01 /]# tar zxvf keepalived-1.2..tar.gz
[root@lb01 /]# cd keepalived-1.2.
[root@lb01 keepalived-1.2.]# ./configure
Keepalived configuration
------------------------
Keepalived version : 1.2.
Compiler : gcc
Compiler flags : -g -O2
Extra Lib : -lssl -lcrypto -lcrypt
Use IPVS Framework : Yes
IPVS sync daemon support : Yes
IPVS use libnl : No
fwmark socket support : Yes
Use VRRP Framework : Yes
Use VRRP VMAC : Yes
SNMP support : No
SHA1 support : No
Use Debug flags : No
[root@lb01 keepalived-1.2.]# make
[root@lb01 keepalived-1.2.]# make install

配置规范启动

[root@lb01 keepalived-1.2.]# cp /usr/local/etc/rc.d/init.d/keepalived /etc/init.d/      #生成启动脚本
[root@lb01 keepalived-1.2.]# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/ #配置启动脚本的参数
[root@lb01 keepalived-1.2.]# mkdir /etc/keepalived #创建默认的keepalived配置文件路径
[root@lb01 keepalived-1.2.]# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/ #把keepalived.conf模板拷贝到/etckeepalived下
[root@lb01 keepalived-1.2.]# cp /usr/local/sbin/keepalived /usr/sbin/
[root@lb01 keepalived-1.2.]# /etc/init.d/keepalived start
Starting keepalived: [ OK ]
[root@lb01 keepalived-1.2.]# ps -ef | grep keep
root : ? :: keepalived -D
root : ? :: keepalived -D
root : ? :: keepalived -D
root : pts/ :: grep keep
[root@lb01 keepalived-1.2.]# /etc/init.d/keepalived stop
Stopping keepalived: [ OK ]

配置文件详解

[root@lb01 keepalived-1.2.]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived #注释 global_defs { #全局配置
notification_email {      #邮件报警
acassen@firewall.loc #收件人
failover@firewall.loc   #收件人
sysadmin@firewall.loc   #收件人
}
notification_email_from Alexandre.Cassen@firewall.loc #发件人
smtp_server 192.168.200.1 #邮件服务器地址
smtp_connect_timeout 30    #超时时间
router_id LVS_DEVEL #keepavlied ID
} vrrp_instance VI_1 {        #VRRP的实例
state MASTER           #服务器的状态
interface eth0         #通信的端口
virtual_router_id 51      #这个实例的ID
priority 100           #优先级
advert_int 1           #心跳的间隔
authentication {       #通信的密钥对
auth_type PASS
auth_pass 1111    #越简单越好 保持默认就行
}
virtual_ipaddress {    #VIP地址
192.168.200.16
192.168.200.17
192.168.200.18
}
}

修改配置文件

先备份一个配置文件

lb01配置文件

[root@lb01 keepalived-1.2.]# cd /etc/keepalived/
[root@lb01 keepalived]# cp keepalived.conf keepalived.conf.bak
[root@lb01 keepalived]# vim keepalived.conf
! Configuration File for keepalived global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout
router_id LVS_01
} vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id
priority
advert_int
authentication {
auth_type PASS
auth_pass
}
virtual_ipaddress {
192.168.119.150/
}
}

lb02配置文件

[root@lb02 keepalived-1.2.]# cd /etc/keepalived/
[root@lb02 keepalived]# cp keepalived.conf keepalived.conf.bak
[root@lb02 keepalived]# vim keepalived.conf
! Configuration File for keepalived global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout
router_id LVS_02
} vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id
priority
advert_int
authentication {
auth_type PASS
auth_pass
}
virtual_ipaddress {
192.168.119.150/
}
}

启动keepalived

[root@lb01 keepalived]# /etc/init.d/keepalived start
Starting keepalived: [ OK ]
[root@lb02 keepalived]# /etc/init.d/keepalived start
Starting keepalived: [ OK ]

在master(lb01)查看虚拟IP(192.168.119.150)

提示:使用ifconfig是查不到的;使用 ip add查询

[root@lb01 keepalived]# ip add | grep 192.168.119.150
inet 192.168.119.150/ scope global secondary eth0

在backup(lb02)查看(没有虚拟IP)

[root@lb02 keepalived]# ip add | grep 192.168.119.150

把master的keepalived服务down、虚拟IP就会自动切换到backup

[root@lb01 keepalived]# /etc/init.d/keepalived stop
Stopping keepalived: [ OK ]
[root@lb01 keepalived]# ip add | grep 192.168.119.150
[root@lb01 keepalived]#

backup查询

[root@lb02 keepalived]# ip add | grep 192.168.119.150
[root@lb02 keepalived]# ip add | grep 192.168.119.150
[root@lb02 keepalived]# ip add | grep 192.168.119.150
[root@lb02 keepalived]# ip add | grep 192.168.119.150
[root@lb02 keepalived]# ip add | grep 192.168.119.150
inet 192.168.119.150/ scope global secondary eth0
[root@lb02 keepalived]# ip add | grep 192.168.119.150
inet 192.168.119.150/ scope global secondary eth0

当master的keepalived服务启动时、虚拟IP会自动从backup切回到master

keepalived安装的更多相关文章

  1. Linux下Keepalived 安装与配置

    Keepalived 安装与配置 一.环境说明 1.操作系统内核版本:2.6.9-78.ELsmp 2.Keepalived软件版本:keepalived-1.1.20.tar.gz 二.环境配置 1 ...

  2. lvs keepalived 安装配置详解【转】

    lvs keepalived 安装配置详解 张映 发表于 2012-06-20 分类目录: 服务器相关 前段时间看了一篇文章,lvs做负载均衡根F5差不多,说实话不怎么相信,因为F5没玩过,也无法比较 ...

  3. keepalived安装与配置,组建高可用服务器

    一.准备环境 linux系统:CentOS7 keepalived版本:keepalived-1.3.5.tar.gz keepalived下载地址:http://www.keepalived.org ...

  4. Keepalived详解(二):Keepalived安装与配置【转】

    一.Keepalived安装与配置: 1.Keepalived的安装过程: Keepalived的安装非常简单,本实例以源码安装讲解: Keepalived的官方网址:http://www.keepa ...

  5. MYSQL + MHA +keepalive + VIP安装配置(三)--keepalived安装配置

    一.概述 keepalived介绍:Keepalived的作用是检测web服务器的状态,如果有一台web服务器死机,或工作出现故障,Keepalived将检测到,并将有故障的web 服务器从系统中剔除 ...

  6. Keepalived 安装

    Keepalived 安装安装环境 keepalived-1.2.18.tar.gz VM虚拟机redhat6.5-x64:192.168.1.201 Xshell4 部署方案 201部署 安装步骤  ...

  7. keepalived安装配置实战心得(实现高可用保证网络服务不间断)

    keepalived安装配置实战心得(实现高可用保证网络服务不间断) 一.准备2台虚拟机     安装的系统是:centos-release-7-1.1503.el7.centos.2.8.x86_6 ...

  8. keepalived安装文档

      安装依赖 su - root yum -y install kernel-devel* yum -y install openssl-* yum -y install popt-devel yum ...

  9. Keepalived 安装与简单配置

    Keepalived 安装与简单配置 http://sivxy.lofter.com/post/1d21ebb9_7e15000

  10. 【检测工具】keepalived安装及配置

    一.keepalived安装 keepalived是一个检测服务器状态的脚本,在高可用机制上经常可以看到它的身影. 在Linux中安装keepalived: 1.在网上直接下载相应的压缩包,推荐链接 ...

随机推荐

  1. CSS3定位和浮动详解

    本文为大家分享CSS3定位和浮动的基础概念,与使用方法,供大家参考,具体内容如下 一.定位 1. css定位: 改变元素在页面上的位置 2. css定位机制: 普通流: 浮动: 绝对布局: 3. cs ...

  2. angularjs中$watch监听model(对象属性、对象)变化

    昨天看了一下教学视频,学到了有关$watch的用法,想到最近做的一个页面中有个select下拉选项(select中的值变化了,则后面input中的值也跟着相应的变化),不知是否可以使用$watch来代 ...

  3. 三大WEB服务器对比分析(apache ,lighttpd,nginx)

    一.软件介绍(apache  lighttpd  nginx) 1. lighttpd Lighttpd是一个具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点.lighttpd是众多 ...

  4. yourphp数据库介绍

    yt_attachment 编辑器图片上传存放的表

  5. SRS(simple-rtmp-server)

     1.Push h.264 to rtmp server from tcp.

  6. MyEclipse 中各种 libraries 的含义

    MyEclipse 中各种 libraries 的含义       JRE System Library,Java EE 5 Libraries,Referenced  Libraries这三个都是各 ...

  7. maven 入门

    Apache Maven 入门篇 ( 上 ) 作者:George Ma 写这个 maven 的入门篇是因为之前在一个开发者会的动手实验中发现挺多人对于 maven 不是那么了解,所以就有了这个想法.这 ...

  8. OC-ARC

    一. 基本简介 ARC是自iOS 5之后增加的新特性,完全消除了手动管理内存的烦琐,编译器会自动在适当的地方插入适当的retain.release.autorelease语句.你不再需要担心内存管理, ...

  9. apache禁止访问文件或目录执行权限、禁止运行脚本PHP文件的设置方法

      <Directory "要去掉PHP执行权限的目录路径,例如:D:/piaoyun.cc/upload"> ErrorDocument 404 /404/404.h ...

  10. Thinkphp 模板中直接对数据处理 模板中使用函数 中文字符串截取

    1.Thinkphp 模板中直接对数据处理:{$data.name|substr=0,3} 2.中文字符串截取函数:mb_substr=0,14,'utf-8' 3.中文字符串统计:iconv_str ...