文章目录

  • 安装nginx
  • keepalived+nginx实现nginx的高可用


安装nginx

1.获得nginx的安装包,并且解压

keepalived nginx双主 nginx和keepalived结合_nginx

2.查看目录里的文件

keepalived nginx双主 nginx和keepalived结合_服务器_02


3.首先需要安装一些依赖软件

keepalived nginx双主 nginx和keepalived结合_keepalived nginx双主_03

keepalived nginx双主 nginx和keepalived结合_nginx_04

4.必须进入到保存nginx的目录中(configure具有可执行权限)

keepalived nginx双主 nginx和keepalived结合_nginx_05

keepalived nginx双主 nginx和keepalived结合_高可用_06

keepalived nginx双主 nginx和keepalived结合_高可用_07

keepalived nginx双主 nginx和keepalived结合_keepalived nginx双主_08

5.发现makefile文件

keepalived nginx双主 nginx和keepalived结合_keepalived nginx双主_09

6.安装

keepalived nginx双主 nginx和keepalived结合_服务器_10

keepalived nginx双主 nginx和keepalived结合_keepalived nginx双主_11

7.安装完成查看文件

keepalived nginx双主 nginx和keepalived结合_nginx_12

8.启动nginx

keepalived nginx双主 nginx和keepalived结合_keepalived nginx双主_13

9.查看到两个紧挨的端口说明启动成功

keepalived nginx双主 nginx和keepalived结合_nginx_14

10.在浏览器访问anzhaungngix的服务器的ip,出现如下界面说明启动成功

keepalived nginx双主 nginx和keepalived结合_keepalived nginx双主_15

keepalived+nginx实现nginx的高可用

实验背景:

172.25.2.10 myserver1 (主nginx)
172.25.2.11 myserver2 (备用ngix)
172.25.2.250 真机  (测试设备)

并且关闭三台主机的防火墙,selinx

实现步骤:

1.首先给两台主机(server1和server2)都安装nginx,具体操作同上文,再给两个主机都安装keepalived。

keepalived nginx双主 nginx和keepalived结合_服务器_16


2.在myserver1上,设置它是主服务器

keepalived nginx双主 nginx和keepalived结合_服务器_17

keepalived nginx双主 nginx和keepalived结合_keepalived nginx双主_18

keepalived nginx双主 nginx和keepalived结合_nginx_19

keepalived nginx双主 nginx和keepalived结合_服务器_20

其他地方不做改动2.将mysrever1的此文件拷贝一份给myserver2
设置myserver2是备用机器

keepalived nginx双主 nginx和keepalived结合_nginx_21

3.分别开启两个服务器的keepalived和nginx

keepalived nginx双主 nginx和keepalived结合_nginx_22

keepalived nginx双主 nginx和keepalived结合_高可用_23

4.发现myserver1获得vip

keepalived nginx双主 nginx和keepalived结合_keepalived nginx双主_24

在浏览器中访问vip,发现nginx的页面

172.25.2.10 是myserver1服务器的,172.25.2.100是vip的

keepalived nginx双主 nginx和keepalived结合_nginx_25


keepalived nginx双主 nginx和keepalived结合_高可用_26

5.当myserevr1的keepalived停止之后,myserver2自动获得vip

keepalived nginx双主 nginx和keepalived结合_服务器_27

在server2中,发现myserevr2(自动获得vip

keepalived nginx双主 nginx和keepalived结合_nginx_28

keepalived nginx双主 nginx和keepalived结合_keepalived nginx双主_29

keepalived nginx双主 nginx和keepalived结合_keepalived nginx双主_30

6.当重新开启myserevr1的keepalived之后,发现serevr1自动接管资源,因为它是主的

keepalived nginx双主 nginx和keepalived结合_nginx_31

keepalived nginx双主 nginx和keepalived结合_服务器_32

keepalived nginx双主 nginx和keepalived结合_服务器_33