`
rjhym
  • 浏览: 67042 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

keepalived配置

 
阅读更多
之前已经安装完成,接下来我们配置keepalived。
假设我的ip地址如下:
server1:192.168.0.150
server2:192.168.0.157
vip:192.168.0.50
在两台服务器上分别执行如下命令
[@server_150 keepalived]# mkdir /etc/keepalived
[@server_150 keepalived]# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
[@server_150 keepalived]# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
[@server_150 keepalived]# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
对应操作的含义:
mkdir /etc/keepalived ##为keepalived创建配置文件目录,默认配置文件从/etc/keepalived下读取
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/ ##复制keepalived的二进制命令
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/ ##提供启动脚本
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/ ##keepalived的主配置文件
编辑/etc/keepalived/keepalived.conf文件,主机修改内容如下:
!Configuration File for keepalived


global_defs {
notification_email {
test@localhost.com
}
notification_email_from localhost@localhost.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}


vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.0.50
}
}

从配置如下:
!Configuration File for keepalived


global_defs {
notification_email {
test@localhost.com
}
notification_email_from localhost@localhost.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}


vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.0.50
}
}
启动主从的keepalived:
在主从上分布执行:
[@server_150 ~]# keepalived start
[@server_150 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 78:2b:cb:66:44:2a brd ff:ff:ff:ff:ff:ff
inet 192.168.0.150/24 brd 10.10.79.255 scope global eth0
inet 192.168.0.50/32 scope global eth0
inet6 fe80::7a2b:cbff:fe66:442a/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 78:2b:cb:66:44:2c brd ff:ff:ff:ff:ff:ff
inet 220.181.26.82/24 brd 220.181.26.255 scope global eth1
inet6 fe80::7a2b:cbff:fe66:442c/64 scope link
valid_lft forever preferred_lft forever
4: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
link/ether 78:2b:cb:66:44:2e brd ff:ff:ff:ff:ff:ff
5: eth3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
link/ether 78:2b:cb:66:44:30 brd ff:ff:ff:ff:ff:ff
6: sit0: <NOARP> mtu 1480 qdisc noop
link/sit 0.0.0.0 brd 0.0.0.0
从机:
[@server_157 ~]# keepalived start
[@server_157 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 78:2b:cb:65:7f:9f brd ff:ff:ff:ff:ff:ff
inet 192.168.0.157/24 brd 10.10.79.255 scope global eth0
inet6 fe80::7a2b:cbff:fe65:7f9f/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 78:2b:cb:65:7f:a1 brd ff:ff:ff:ff:ff:ff
inet 220.181.26.92/24 brd 220.181.26.255 scope global eth1
inet6 fe80::7a2b:cbff:fe65:7fa1/64 scope link
valid_lft forever preferred_lft forever
4: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
link/ether 78:2b:cb:65:7f:a3 brd ff:ff:ff:ff:ff:ff
5: eth3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
link/ether 78:2b:cb:65:7f:a5 brd ff:ff:ff:ff:ff:ff
6: sit0: <NOARP> mtu 1480 qdisc noop
link/sit 0.0.0.0 brd 0.0.0.0
现在停止从机的keepalived服务,再次查看主从ip addr,与上面的结果一样。
启动从机的keepalived服务,然后停止主机的keepalived服务。
再次查看主从的ip addr
主机:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 78:2b:cb:66:44:2a brd ff:ff:ff:ff:ff:ff
inet 192.168.0.150/24 brd 10.10.79.255 scope global eth0
inet6 fe80::7a2b:cbff:fe66:442a/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 78:2b:cb:66:44:2c brd ff:ff:ff:ff:ff:ff
inet 220.181.26.82/24 brd 220.181.26.255 scope global eth1
inet6 fe80::7a2b:cbff:fe66:442c/64 scope link
valid_lft forever preferred_lft forever
4: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
link/ether 78:2b:cb:66:44:2e brd ff:ff:ff:ff:ff:ff
5: eth3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
link/ether 78:2b:cb:66:44:30 brd ff:ff:ff:ff:ff:ff
6: sit0: <NOARP> mtu 1480 qdisc noop
link/sit 0.0.0.0 brd 0.0.0.0
从机:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 78:2b:cb:65:7f:9f brd ff:ff:ff:ff:ff:ff
inet 192.168.0.157/24 brd 10.10.79.255 scope global eth0
inet 192.168.0.50/32 scope global eth0
inet6 fe80::7a2b:cbff:fe65:7f9f/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 78:2b:cb:65:7f:a1 brd ff:ff:ff:ff:ff:ff
inet 220.181.26.92/24 brd 220.181.26.255 scope global eth1
inet6 fe80::7a2b:cbff:fe65:7fa1/64 scope link
valid_lft forever preferred_lft forever
4: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
link/ether 78:2b:cb:65:7f:a3 brd ff:ff:ff:ff:ff:ff
5: eth3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
link/ether 78:2b:cb:65:7f:a5 brd ff:ff:ff:ff:ff:ff
6: sit0: <NOARP> mtu 1480 qdisc noop
link/sit 0.0.0.0 brd 0.0.0.0
发现虚ip已经从主机绑定到从机,配置测试完成。




分享到:
评论

相关推荐

    keepalived 配置文件 附带检测脚本示例

    《keepalived配置详解与检测脚本应用》 在高可用性和负载均衡的网络环境中,keepalived扮演着至关重要的角色。它是一个基于VRRP(Virtual Router Redundancy Protocol)协议实现的高可用性软件,能够确保网络服务的...

    keepalived配置及测试

    keepalived配置及测试

    keepalived配置文件参考

    根据自身实际使用情况,上传下keepalived配置双机nginx同时生效的参考文件,供大家学习

    keepalived配置及典型应用案例

    【标题】"Keepalived配置及典型应用案例"主要涵盖了Keepalived的配置方法和它在实际场景中的应用。Keepalived是一款开源的网络服务高可用性(HA)工具,常用于实现Linux环境下的负载均衡和故障转移。它基于VRRP协议...

    keepalived配置文件详解

    "Keepalived配置文件详解" Keepalived配置文件是Keepalived集群系统的核心组件之一,它定义了Keepalived的行为和配置参数。下面是Keepalived配置文件的详细解释: 1. global_defs:定义了Keepalived的全局配置...

    keepalived 配置redis高可用

    2. **配置vrrp_instance**:在Keepalived配置文件(通常为`/etc/keepalived/keepalived.conf`)中,定义一个vrrp_instance,指定虚拟IP地址、优先级、密码等信息。 3. **配置检查脚本**:编写一个用于检查Redis服务...

    Haproxy+keepalived配置文档

    `keepalived.conf` 文件是Keepalived的配置文件,主要包括以下部分: - `vrrp_instance`:定义VRRP实例,设置虚拟路由标识、优先级、广告间隔等参数。 - `interface`:指定监控的网络接口。 - `virtual_ipaddress`:...

    LVS+KEEPalived 配置

    **LVS+Keepalived配置步骤** 1. **安装LVS和Keepalived**:首先在所有涉及的服务器上安装LVS和Keepalived软件包,如`apt-get install lvs keepalived`(对于Debian/Ubuntu)或`yum install lvs keepalived`(对于...

    LVS+keepalived配置实战

    以下将详细介绍LVS+Keepalived配置实战中的关键知识点。 1. **LVS**:Linux Virtual Server是一个开源的负载均衡软件,它允许我们将多台服务器组织成一个集群,对外提供统一的服务。LVS支持多种负载均衡策略,如...

    keepalived 配置 高可用 负载

    ### Keepalived 高可用与负载均衡配置详解 #### 一、概述 Keepalived 是一个用于实现高可用性(HA)和负载均衡的开源工具,它通过 VRRP(虚拟路由冗余协议)和健康检查来确保服务的连续性和性能优化。本文将详细...

    Nginx+Keepalived 配置

    【Nginx+Keepalived 配置】用于实现服务器的负载均衡和高可用性,是Web...总结来说,Nginx+Keepalived配置实现了高可用性和负载均衡,使得Web服务在单个服务器故障时仍能正常提供服务,提高了系统的稳定性和可靠性。

    keepalived 详细配置文件

    #### Keepalived配置要点 1. **安装Keepalived**:可以通过编译安装或使用包管理器安装。例如,在给定文件中提到了下载`keepalived-1.1.19.tar.gz`,并进行了编译安装的过程。 2. **配置文件解析**:Keepalived的...

    中职网络搭建中出现的高可用性keepalived配置方法

    中职网络搭建中出现的高可用性keepalived配置方法,linux keepalived配置方法

    Nginx+keepalived核心配置文件

    Keepalived的配置文件`keepalived.conf`包含了健康检查、VRRP(Virtual Router Redundancy Protocol)协议配置和通知机制等。主要部分包括: 1. **global_defs**: 全局定义,一般用来设置通知邮件的发送人信息。 2....

    keepalived+redis&mysql主备高可用配置文件和脚本

    2. **配置VRRP实例**:在Keepalived配置文件(通常为`keepalived.conf`)中,定义VRRP实例,包括优先级、虚拟IP、监控的服务器和服务等。 **脚本使用** 1. **启动和停止脚本**:压缩包可能包含启动Redis、MySQL和...

Global site tag (gtag.js) - Google Analytics