欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Linux利用keepalived實(shí)現(xiàn)lvs的高可用性的操作方法

 更新時(shí)間:2018年09月02日 17:02:53   作者:OrochWang  
LVS是Linux Virtual Server的簡寫,意即Linux虛擬服務(wù)器,是一個(gè)虛擬的服務(wù)器集群系統(tǒng)。這篇文章主要介紹了Linux利用keepalived實(shí)現(xiàn)lvs的高可用性 ,需要的朋友可以參考下

lvs+keepalived是什么?

keepalived工作原理

keepalived是集群管理中保證集群高可用的一個(gè)服務(wù)軟件,其功能類似于heartbeat,用來防止單點(diǎn)故障。 keepalived是以VRRP協(xié)議為實(shí)現(xiàn)基礎(chǔ)的,VRRP全稱Virtual Router Redundancy Protocol,即虛擬路由冗余協(xié)議。 虛擬路由冗余協(xié)議,可以認(rèn)為是實(shí)現(xiàn)路由器高可用的協(xié)議,即將N臺(tái)提供相同功能的路由器組成一個(gè)路由器組,這個(gè)組里面有一個(gè)master和多個(gè)backup,master上面有一個(gè)對外提供服務(wù)的vip(該路由器所在局域網(wǎng)內(nèi)其他機(jī)器的默認(rèn)路由為該vip),master會(huì)發(fā)組播,當(dāng)backup收不到vrrp包時(shí)就認(rèn)為master宕掉了,這時(shí)就需要根據(jù)VRRP的優(yōu)先級(jí)來選舉一個(gè)backup當(dāng)master。這樣的話就可以保證路由器的高可用了。

 LVS簡介

LVS是Linux Virtual Server的簡寫,意即Linux虛擬服務(wù)器,是一個(gè)虛擬的服務(wù)器集群系統(tǒng)。本項(xiàng)目在1998年5月由章文嵩博士成立,是中國國內(nèi)最早出現(xiàn)的自由軟件項(xiàng)目之一。目前有三種IP負(fù)載均衡技術(shù)(VS/NAT、VS/TUN和VS/DR),十種調(diào)度算法。

本文重點(diǎn)給大家介紹Linux利用keepalived實(shí)現(xiàn)lvs的高可用性的操作方法,感興趣的朋友參考下吧。

image

單主模型IPVS示例

配置keepalive

高可用的ipvs集群示例:修改keepalived配置文件

修改主機(jī):192.168.234.27的keepalived配置文件

[root@234c27 ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost //接受郵件地址
}
notification_email_from keepalived@localhost //發(fā)送郵件地址
smtp_server 127.0.0.1 //發(fā)送郵件服務(wù)器IP
smtp_connect_timeout 30 //郵件連接超時(shí)時(shí)長
router_id kptwo //路由id
vrrp _mcast_group4 234.10.10.10 //指定vrrp協(xié)議的多播地址
}
vrrp_instance VI_1 { //vrrp協(xié)議的
state MASTER //lvs的MASTER服務(wù)器
interface ens37 //
virtual_router_id 50 //虛擬路由
priority 100 //權(quán)重為100.越大越先
advert_int 1 //發(fā)送組博包的間隔
authentication { //驗(yàn)證
auth_type PASS //方式為pass( 明文)
auth_pass 1111 //密碼
}
virtual_ipaddress { //keepalived虛擬ip
10.0.0.100/24
}
}
virtual_server 10.0.0.100 80 {
 delay_loop 6 //檢查后端服務(wù)器的時(shí)間間隔
 lb_algo wrr //定義調(diào)度方法
 lb_kind DR //集群的類型
 #persistence_timeout 50 //持久連接時(shí)長
 protocol TCP //服務(wù)協(xié)議,僅支持TCP
 real_server 192.168.234.47 80 { //后端real_server服務(wù)器地址
  weight 1 //權(quán)重
  HTTP_GET { //應(yīng)用層檢測
   url {
    path / //定義要監(jiān)控的URL
    status_code 200 //判斷上述檢測機(jī)制為健康狀態(tài)的響應(yīng)碼
   }
   connect_timeout 3 //連接請求的超時(shí)時(shí)長
   nb_get_retry 3 //重試次數(shù)
   delay_before_retry 3 //重試之前的延遲時(shí)長
  }
 }
 real_server 192.168.234.57 80 {
  weight 2
  HTTP_GET {
   url {
    path /
    status_code 200
   }
   connect_timeout 3
   nb_get_retry 3
   delay_before_retry 3
  }
 }
}

修改主機(jī):192.168.234.37的keepalived配置文件

[root@234c37 ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
 notification_email {
  root@localhost
 }
 notification_email_from keepalived@localhost
 smtp_server 127.0.0.1
 smtp_connect_timeout 30
 router_id kptwo
 vrrp _mcast_group4 234.10.10.10
}
vrrp_instance VI_1 {
 state BACKUP
 interface ens37
 virtual_router_id 50
 priority 80
 advert_int 1
 authentication {
  auth_type PASS
  auth_pass 1111
 }
 virtual_ipaddress {
  10.0.0.100/24
 }
}
virtual_server 10.0.0.100 80 {
 delay_loop 6
 lb_algo wrr
 lb_kind DR
 #persistence_timeout 50
 protocol TCP
 sorry_server 127.0.0.1:80
 real_server 192.168.234.47 80 {
  weight 1
  HTTP_GET {
   url {
    path /
    status_code 200
   }
   connect_timeout 3
   nb_get_retry 3
   delay_before_retry 3
  }
 }
 real_server 192.168.234.57 80 {
  weight 2
  HTTP_GET {
   url {
    path /
    status_code 200
   }
   connect_timeout 3
   nb_get_retry 3
   delay_before_retry 3
  }
 }
}

查看keepalived

[root@234c37 ~]# systemctl status keepalived
● keepalived.service - LVS and VRRP High Availability Monitor
 Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
 Active: inactive (dead)
…………
[root@234c37 ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
 -> RemoteAddress:Port   Forward Weight ActiveConn InActConn
//暫無ipvsadm

啟動(dòng)服務(wù)

image

[root@234c27 keepalived]# systemctl start keepalived.service
[root@234c27 keepalived]# systemctl status keepalived.service
● keepalived.service - LVS and VRRP High Availability Monitor
 Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
 Active: active (running) since Fri 2018-08-31 20:30:02 CST; 12s ago
 Process: 9657 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 9658 (keepalived)
………………
[root@234c27 keepalived]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
 -> RemoteAddress:Port   Forward Weight ActiveConn InActConn
TCP 10.0.0.100:80 wrr
 -> 192.168.234.47:80   Route 1  0   0
 -> 192.168.234.57:80   Route 2  0   0
//啟動(dòng)服務(wù)lvs vs已配置好

后端real_server準(zhǔn)備

增加ip在網(wǎng)卡上 修改限制arp通告及應(yīng)答級(jí)別 rs1 rs2都做,網(wǎng)關(guān)并指向路由

ip a a 10.0.0.100/32 dev ens37
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
route add default gw 192.168.234.17

安裝httpd服務(wù) 寫好網(wǎng)頁文件

啟動(dòng)服務(wù)

image

多主模型IPVS示例

image

配置keepalive

高可用的ipvs集群示例:修改keepalived配置文件

修改主機(jī):192.168.234.27的keepalived配置文件

[root@234c27 keepalived]# vim /etc/keepalived/keepalived.conf
global_defs {
  notification_email {
   root@localhost
  }
  notification_email_from keepalived@localhost
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  router_id kpone
  vrrp _mcast_group4 234.10.10.10
}
vrrp_instance VI_1 {
  state MASTER
  interface ens37
  virtual_router_id 50
  priority 100
  advert_int 1
  authentication {
    auth_type PASS
    auth_pass 1111
  }
  virtual_ipaddress {
    10.0.0.100/24
  }
}
vrrp_instance VI_2 {
  state BACKUP
  interface ens37
  virtual_router_id 51
  priority 80
  advert_int 1
  authentication {
    auth_type PASS
    auth_pass 2222
  }
  virtual_ipaddress {
    10.0.0.200/24
  }
}
virtual_server 10.0.0.100 80 {
  delay_loop 6
  lb_algo wrr
  lb_kind DR
  #persistence_timeout 50
  protocol TCP
  #sorry_server 127.0.0.1:80
  real_server 192.168.234.47 80 {
    weight 1
    HTTP_GET {
      url {
       path /
       status_code 200
      }
      connect_timeout 3
      nb_get_retry 3
      delay_before_retry 3
    }
  }
}
virtual_server 10.0.0.200 80 {
  delay_loop 6
  lb_algo wrr
  lb_kind DR
  #persistence_timeout 50
  protocol TCP
  #sorry_server 127.0.0.1:80
  real_server 192.168.234.57 80 {
    weight 1
    HTTP_GET {
      url {
       path /
       status_code 200
      }
      connect_timeout 3
      nb_get_retry 3
      delay_before_retry 3
    }
  }
}

修改主機(jī):192.168.234.37的keepalived配置文件

[root@234c37 ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
  notification_email {
   root@localhost
  }
  notification_email_from keepalived@localhost
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  router_id kptwo
  vrrp _mcast_group4 234.10.10.10
}
vrrp_instance VI_1 {
  state BACKUP
  interface ens37
  virtual_router_id 50
  priority 80
  advert_int 1
  authentication {
    auth_type PASS
    auth_pass 1111
  }
  virtual_ipaddress {
    10.0.0.100/24
  }
}
vrrp_instance VI_2 {
  state MASTER
  interface ens37
  virtual_router_id 51
  priority 100
  advert_int 1
  authentication {
    auth_type PASS
    auth_pass 2222
  }
  virtual_ipaddress {
    10.0.0.200/24
  }
}
virtual_server 10.0.0.100 80 {
  delay_loop 6
  lb_algo wrr
  lb_kind DR
  #persistence_timeout 50
  protocol TCP
  #sorry_server 127.0.0.1:80
  real_server 192.168.234.47 80 {
    weight 1
    HTTP_GET {
      url {
       path /
       status_code 200
      }
      connect_timeout 3
      nb_get_retry 3
      delay_before_retry 3
    }
  }
}
virtual_server 10.0.0.200 80 {
  delay_loop 6
  lb_algo wrr
  lb_kind DR
  #persistence_timeout 50
  protocol TCP
  #sorry_server 127.0.0.1:80
  real_server 192.168.234.57 80 {
    weight 1
    HTTP_GET {
      url {
       path /
       status_code 200
      }
      connect_timeout 3
      nb_get_retry 3
      delay_before_retry 3
    }
  }
}

讓10.0.0.100的ip優(yōu)先分配至192.168.234.47 192.168.234.57備用

讓10.0.0.200的ip優(yōu)先分配至192.168.234.57 192.168.234.47備用

后端real_server準(zhǔn)備

修改192.168.234.57的vip為10.0.0.200/32

  [root@234c27 keepalived]# ipvsadm -Ln
  IP Virtual Server version 1.2.1 (size=4096)
  Prot LocalAddress:Port Scheduler Flags
   -> RemoteAddress:Port      Forward Weight ActiveConn InActConn
  TCP 10.0.0.100:80 wrr
   -> 192.168.234.47:80      Route  1   0     0
  TCP 10.0.0.200:80 wrr
  -> 192.168.234.57:80      Route  1   0     0

現(xiàn)在宕掉一個(gè)lvs

image

  [root@234c27 keepalived]# systemctl stop keepalived.service
  [root@234c27 keepalived]# ipvsadm -Ln
  IP Virtual Server version 1.2.1 (size=4096)
  Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port      Forward Weight ActiveConn InActConn

依然提供服務(wù)

image

 [root@234c37 ~]# ipvsadm -Ln
 IP Virtual Server version 1.2.1 (size=4096)
  Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port      Forward Weight ActiveConn InActConn
  TCP 10.0.0.100:80 wrr
   -> 192.168.234.47:80      Route  1   0     21
  TCP 10.0.0.200:80 wrr
   -> 192.168.234.57:80      Route  1   0     39

后一個(gè)實(shí)現(xiàn)基于前一個(gè)的基礎(chǔ)上修改來的

假設(shè)要實(shí)現(xiàn)sorry_server

1.把rs服務(wù)都停掉。然后在lvs上安裝apache或者nginx服務(wù)

2.將keepalived配置文件中的

virtual_server 10.0.0.200 80 {
  delay_loop 6
  lb_algo wrr
  lb_kind DR
  #persistence_timeout 50
  protocol TCP
  #sorry_server 127.0.0.1:80 //這一行來修改 寫出服務(wù)出錯(cuò)之后的頁面
  real_server 192.168.234.57 80 {
    weight 1
    HTTP_GET {
      url {
       path /
       status_code 200
      }
      connect_timeout 3
      nb_get_retry 3
      delay_before_retry 3
    }
  }
}

相關(guān)文章

  • linux系統(tǒng)用戶管理與grep正則表達(dá)式示例教程

    linux系統(tǒng)用戶管理與grep正則表達(dá)式示例教程

    這篇文章主要給大家介紹了關(guān)于linux系統(tǒng)用戶管理與grep正則表達(dá)式的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用linux系統(tǒng)具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-03-03
  • linux系統(tǒng)下用戶管理相關(guān)介紹

    linux系統(tǒng)下用戶管理相關(guān)介紹

    大家好,本篇文章主要講的是linux系統(tǒng)下用戶管理相關(guān)介紹,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下哦,方便下次瀏覽
    2021-12-12
  • Linux系統(tǒng)下安裝jdbc與tomcat的圖文教程

    Linux系統(tǒng)下安裝jdbc與tomcat的圖文教程

    本文通過圖文并茂的形式給大家介紹了Linux系統(tǒng)下安裝jdbc與tomcat的方法,本文給大家介紹的非常詳細(xì),具有參考借鑒價(jià)值,需要的朋友參考下吧
    2018-01-01
  • 詳解linux下make命令的使用方法

    詳解linux下make命令的使用方法

    這篇文章主要介紹了linux下make命令的使用方法,Linux 下 make 命令是系統(tǒng)管理員和程序員用的最頻繁的命令之一,感興趣的朋友可以參考一下
    2016-01-01
  • 解決“WARNINGThe?remote?SSH?server?rejected?X11?forwarding?request.“警告(推薦)

    解決“WARNINGThe?remote?SSH?server?rejected?X11?forwardin

    使用xshell連接服務(wù)器時(shí),出現(xiàn)了“WARNING!?The?remote?SSH?server?rejected?X11?forwarding?request.”,意思是“遠(yuǎn)程SSH服務(wù)器拒絕X11轉(zhuǎn)發(fā)請求”,這篇文章主要介紹了解決“WARNINGThe?remote?SSH?server?rejected?X11?forwarding?request.“警告,需要的朋友可以參考下
    2022-08-08
  • Linux使用Sudo委派權(quán)限

    Linux使用Sudo委派權(quán)限

    今天小編就為大家分享一篇關(guān)于Linux使用Sudo委派權(quán)限的文章,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2018-10-10
  • environments was not found on the java.library.path 問題的解決方法

    environments was not found on the java.library.path 問題的解決方法

    The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path 問題的解決方法,需要的朋友可以參考下
    2016-08-08
  • linux大于2T的磁盤使用GPT分區(qū)的方法分享

    linux大于2T的磁盤使用GPT分區(qū)的方法分享

    眾所周知,在linux下磁盤分區(qū)大于2TB的時(shí)候我不能使用常用Fdisk命令。是不是就沒有辦法在linux使用大容量的磁盤呢?答案:不是
    2012-11-11
  • linux中chmod命令用法詳解

    linux中chmod命令用法詳解

    在本篇文章里小編給大家分享了關(guān)于linux中chmod命令用法和相關(guān)知識(shí)點(diǎn),需要的朋友們跟著學(xué)習(xí)下。
    2019-04-04
  • Linux 解決Deepin無法在root用戶啟動(dòng)Google Chrome瀏覽器的問題

    Linux 解決Deepin無法在root用戶啟動(dòng)Google Chrome瀏覽器的問題

    這篇文章主要介紹了Linux 解決Deepin無法在root用戶啟動(dòng)Google Chrome瀏覽器的問題,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-07-07

最新評(píng)論