keepalived nginx負載安裝

2022-06-17 14:30:12 字數 2536 閱讀 3992

環境:centos7.6

keepalived工具可以生成虛擬浮動ip,繫結到網絡卡上。

172.21.210.19  master

172.21.210.20  backup

172.21.210.30  vip(浮動ip)

1、兩個節點安裝keepalived

yum -y install keepalived

2、確定要繫結的網絡卡(這兒使用eth0)

[root@tool-19 ~]# ip a

1: lo: mtu 65536 qdisc noqueue state unknown group default qlen 1000

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet

127.0.0.1/8

scope host lo

valid_lft forever preferred_lft forever

inet6 ::

1/128

scope host

valid_lft forever preferred_lft forever

2: eth0:

mtu 1500 qdisc pfifo_fast state up group default qlen 1000

link/ether fa:16

:3e:c5:ac:f5 brd ff:ff:ff:ff:ff:ff

inet

172.21.210.19/25 brd 172.21.210.127 scope global

noprefixroute eth0

valid_lft forever preferred_lft forever

inet6 fe80::f816:3eff:fec5:acf5/64

scope link

valid_lft forever preferred_lft forever

3、master配置

[root@tool-19 ~]# more /etc/keepalived/keepalived.conf 

! configuration file for

keepalived

global_defs

vrrp_instance vi_1

virtual_ipaddress

}

3、backup節點配置

[root@harbor-20 ~]# more /etc/keepalived/keepalived.conf 

! configuration file for

keepalived

global_defs

vrrp_instance vi_1

virtual_ipaddress

}

4、啟動服務

systemctl enable keepalived && systemctl start keepalived && systemctl status keepalived

5、進行驗證

[root@harbor-20 ~]# ip a

1: lo: mtu 65536 qdisc noqueue state unknown group default qlen 1000

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet

127.0.0.1/8

scope host lo

valid_lft forever preferred_lft forever

inet6 ::

1/128

scope host

valid_lft forever preferred_lft forever

2: eth0:

mtu 1500 qdisc pfifo_fast state up group default qlen 1000

link/ether fa:16:3e:c0:74

:1e brd ff:ff:ff:ff:ff:ff

inet

172.21.210.20/25 brd 172.21.210.127 scope global

noprefixroute eth0

valid_lft forever preferred_lft forever

inet

172.21.210.30/25 scope global

secondary eth0

valid_lft forever preferred_lft forever

現在在20上,重啟20的keeplived服務,可以看到ip自動跳轉到19

systemctl restart keepalived

6、配置nginx,兩邊配置一樣服務,每次vip跳轉到該伺服器都是用一樣的nginx,nginx具體的安裝可以參考:

keepalived nginx主從切換

五 nginx指令碼,新建nginx check.sh指令碼放到 etc keepalived下 指令碼內容 bin bash a ps c nginx no header wc l if a eq 0 then usr local nginx sbin nginx sleep 2 if ps c ...

keepalived nginx集群部署

192.168.132.130 伺服器1 192.168.132.132 伺服器2 虛擬ip 192.168.132.131 yum install gcc c gcc是gnu的c語言編譯器,至於c 編譯器,它的名字叫做g yum install y pcre pcre devel 在nginx編譯...

keepalived nginx離線安裝

keepalived nginx安裝 把keepalived 1.2.23.tar.gz傳送到 opt下 cd opt tar zxvf keepalived 1.2.23.tar.gz cd keepalived 1.2.23 configure prefix usr local keepaliv...