码迷,mamicode.com
首页 > Web开发 > 详细

keepalived实现web高可用集群

时间:2020-04-11 10:12:55      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:实验环境   enable   info   开机   har   share   http   自启动   笔记   

1、实验环境

两台CentOS-7.5虚拟机
web1:10.0.11.203
web2:10.0.11.204
VIP :10.0.11.210
web类型:nginx
客户端:自用笔记本(win10)

2、准备两台web服务器

1)web1网卡情况
[root@CentOS ~]#
[root@CentOS ~]# ip a
技术图片

2)web2网卡情况
[root@CentOS-2 ~]#
[root@CentOS-2 ~]# ip a
技术图片

3)安装nginx

web1端:
[root@CentOS ~]#
[root@CentOS ~]# yum install nginx
[root@CentOS ~]# rpm -qa nginx
nginx-1.16.1-1.el7.x86_64
[root@CentOS ~]#
[root@CentOS ~]#
[root@CentOS ~]# > /usr/share/nginx/html/index.html #清空默认网页
[root@CentOS ~]# echo web1 > /usr/share/nginx/html/index.html #让网页显示web1
[root@CentOS ~]# cat /usr/share/nginx/html/index.html
web1
[root@CentOS ~]#
[root@CentOS ~]# systemctl start nginx #启动nginx
[root@CentOS ~]# systemctl enable nginx #设置nginx开机自启动
C:\Users\Administrator>curl 10.0.11.203
技术图片

web2端:
[root@CentOS-2 ~]#
[root@CentOS-2 ~]# yum install nginx
[root@CentOS-2 ~]# rpm -qa nginx
nginx-1.16.1-1.el7.x86_64
[root@CentOS-2 ~]#
[root@CentOS-2 ~]#
[root@CentOS-2 ~]# > /usr/share/nginx/html/index.html
[root@CentOS-2 ~]# echo web2 > /usr/share/nginx/html/index.html
[root@CentOS-2 ~]# cat /usr/share/nginx/html/index.html
web2
[root@CentOS-2 ~]#
[root@CentOS-2 ~]# systemctl start nginx
[root@CentOS-2 ~]# systemctl enable nginx
C:\Users\Administrator>curl 10.0.11.204
技术图片

4)安装keepalived
说明:两台web服务器都需要安装keepalived服务

web1端:
[root@CentOS ~]#
[root@CentOS ~]# yum install keepalived
[root@CentOS ~]# rpm -qa keepalived
keepalived-1.3.5-16.el7.x86_64
[root@CentOS ~]#

web2端:
[root@CentOS-2 ~]#
[root@CentOS-2 ~]# yum install keepalived
[root@CentOS-2 ~]# rpm -qa keepalived
keepalived-1.3.5-16.el7.x86_64
[root@CentOS-2 ~]#

5)配置两台keepalived并启动

web1端:
[root@CentOS ~]#
[root@CentOS ~]# > /etc/keepalived/keepalived.conf #清空原来的配置
[root@CentOS ~]# vim /etc/keepalived/keepalived.conf #编辑配置文件,自定义keepalived配置文件
[root@CentOS ~]# cat /etc/keepalived/keepalived.conf
技术图片
[root@CentOS ~]#
[root@CentOS ~]# systemctl start keepalived #启动
[root@CentOS ~]# systemctl enable keepalived #设置开机启动

web2端:
[root@CentOS-2 ~]#
[root@CentOS-2 ~]# > /etc/keepalived/keepalived.conf
[root@CentOS-2 ~]# vim /etc/keepalived/keepalived.conf
[root@CentOS-2 ~]# cat /etc/keepalived/keepalived.conf
技术图片
[root@CentOS-2 ~]#
[root@CentOS-2 ~]# systemctl start keepalived #启动
[root@CentOS-2 ~]# systemctl enable keepalived #设置开机启动

3、测试访问
方法:用客户端通过VIP测试访问web

C:\Users\Administrator>curl 10.0.11.210 #个人笔记本通过VIP测试访问web
技术图片

拔掉web1服务器的网线,用客户端通过VIP测试访问web:
C:\Users\Administrator>curl 10.0.11.210
技术图片

再次将web1服务器的网线接好,用客户端通过VIP测试访问web:
C:\Users\Administrator>curl 10.0.11.210
技术图片

4、实验结论:
利用keepalived成功实现了web服务器集群的高可用

keepalived实现web高可用集群

标签:实验环境   enable   info   开机   har   share   http   自启动   笔记   

原文地址:https://blog.51cto.com/14783377/2486373

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