码迷,mamicode.com
首页 > 其他好文 > 详细

keepalived高可用搭建

时间:2018-11-13 20:15:19      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:出现   _id   编译   config   vrrp   服务启动   efs   ipad   默认   

- [1. keepalived 简介 ##](#1-keepalived-简介-) - [1. keepalived](#1-keepalived) - [2. 安装keepalived](#2-安装keepalived) - [2. keepalived 高可用配置 ##](#2-keepalived-高可用配置-) - [1. 安装keepalived](#1-安装keepalived) - [2. 配置keepalived以实现虚拟IP绑定](#2-配置keepalived以实现虚拟ip绑定)

1. keepalived 简介

1. keepalived

Keepalived的作用是检测服务器的状态,如果有一台web服务器宕机,或工作出现故障,Keepalived将检测到,并将有故障的服务器从系统中剔除,同时使用其他服务器代替该服务器的工作,当服务器工作正常后Keepalived自动将服务器加入到服务器群中,这些工作全部自动完成,不需要人工干涉,需要人工做的只是修复故障的服务器。

2. 安装keepalived

Centos7 默认的keepalived版本有问题,直接源码编译安装
这里下载的keepadlived版本为2.0.7
首先安装依赖文件(两台机器)

# yum install -y gcc gcc-c++  openssl-devel

然后执行编译安装(两台机器)

# tar xvf keepalived-2.0.7.tar
# cd keepalived-2.0.7
# ./configure
# make
# make install

复制配置文件(两台机器)

# mkdir /etc/keepalived
# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf

2. keepalived 高可用配置

这里的两台服务器使用keepalived执行虚拟IP的动态切换,具体要求如下:

1. 安装keepalived

首先两台服务器均要按照上一节描述的方法来进行Keepalived的安装

2. 配置keepalived以实现虚拟IP绑定

修改配置文件:/etc/keepalived/keepalived.conf(主)

1 ! Configuration File for keepalived
2
3 global_defs {
4    router_id master
5 }
6
7 vrrp_instance VI_1 {
8     state MASTER
9     interface em2
10     virtual_router_id 52
11     priority 100
12     advert_int 1
13     authentication {
14         auth_type PASS
15         auth_pass 1111
16     }
17     virtual_ipaddress {
18         172.16.0.8/24
19     }
20 }
21
22 virtual_server 192.168.200.100 443 {

注: 文件其他部分不动

修改配置文件:/etc/keepalived/keepalived.conf(备)

1 ! Configuration File for keepalived
2
3 global_defs {
4    router_id backup
5 }
6
7 vrrp_instance VI_1 {
8     state BACKUP
9     interface em2
10     virtual_router_id 52
11     priority 90
12     advert_int 1
13     authentication {
14         auth_type PASS
15         auth_pass 1111
16     }
17     virtual_ipaddress {
18         172.16.0.8/24
19     }
20 }
21
22 virtual_server 192.168.200.100 443 {

注: 文件其他部分不动

两机器都设置服务启动,并通过ps查看进程是否运行

# systemctl start keepalived
# systemctl enable keepalived

然后通过 ip a 来查看虚拟IP是否绑定成功

# ip a

keepalived高可用搭建

标签:出现   _id   编译   config   vrrp   服务启动   efs   ipad   默认   

原文地址:http://blog.51cto.com/12734862/2316545

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!