keepalived的工作原理基于三個(gè)層面,分別時(shí)IP層,TCP層和應(yīng)用層
IP
層:keepalived會(huì)定期向服務(wù)器集群中的服務(wù)器發(fā)送一個(gè)類似于ping程序的ICMP數(shù)據(jù)包。通俗理解就是我keepalived來(lái)ping你服
務(wù)器,我要是ping通了,那我知道你還活著,咱們可以繼續(xù)合作,如果不幸發(fā)現(xiàn)你掛了,那就得把這臺(tái)服務(wù)器踢了。該層就是確保服務(wù)器ip地址有效,一次來(lái)
判斷這臺(tái)服務(wù)器可否繼續(xù)在崗謀職。
TCP層:這一層和IP層類似,只不過(guò)IP層檢查的是IP,該層檢查TCP端口。keepalived在IP層
且報(bào)你服務(wù)器的IP有效,然后繼續(xù)看你的TCP端口,比如說(shuō)你是web
server,那你的80端口就應(yīng)該開啟,如果keepalived發(fā)現(xiàn)你的80端口沒有啟動(dòng)。那么它就會(huì)認(rèn)為你已經(jīng)掛掉,然后剔除。
應(yīng)用層:這一層就是具體的工作程序了,keepalived是個(gè)恪盡職守的檢察官,應(yīng)用層的程序與用戶的設(shè)定息息相關(guān),keepalived則通過(guò)檢查服務(wù)器的運(yùn)行是否和用戶設(shè)定一致,如果不一致,keepalived就會(huì)宣判這臺(tái)服務(wù)器犧牲。
創(chuàng)新互聯(lián)建站是一家專注于做網(wǎng)站、網(wǎng)站制作與策劃設(shè)計(jì),龍泉驛網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)建站做網(wǎng)站,專注于網(wǎng)站建設(shè)10余年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:龍泉驛等地區(qū)。龍泉驛做網(wǎng)站價(jià)格咨詢:028-86922220
主機(jī):172.25.44.3 server3
備機(jī):172.25.44.4 server4
[root@server3 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0:0DEVICE=eth0:0TYPE=EthernetONBOOT=yesBOOTPROTO=staticDNS1=172.25.44.44IPADDR=172.25.44.100NETMASK=255.255.255.0GETWAY=172.25.44.44[root@server3 ~]# /etc/init.d/network restart[root@server3 ~]# ifconfigeth0 Link encap:Ethernet HWaddr 52:54:00:48:60:3E inet addr:172.25.44.4 Bcast:172.25.44.255 Mask:255.255.255.0 inet6 addr: fe80::5054:ff:fe48:603e/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:11926 errors:0 dropped:0 overruns:0 frame:0 TX packets:6533 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:25662550 (24.4 MiB) TX bytes:876645 (856.0 KiB) eth0:0 Link encap:Ethernet HWaddr 52:54:00:48:60:3E inet addr:172.25.44.100 Bcast:172.25.44.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:36283 errors:0 dropped:0 overruns:0 frame:0 TX packets:36283 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1982812 (1.8 MiB) TX bytes:1982812 (1.8 MiB)
安裝包:nginx-1.10.3.tar.gz
解壓安裝包:tar zxf nginx-1.10.3.tar.gz
[root@server3 software]# cd nginx-1.10.3 —prefix=/usr/local/lnmp/nignx [root@server3 nginx-1.10.3]# ./configure [root@server3 nginx-1.10.3]# make [root@server3 nginx-1.10.3]# make install [root@server3 nginx-1.10.3]# ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/ #創(chuàng)建nginx的軟鏈接
[root@server3 nginx-1.10.3]# cd /usr/local/lnmp/nginx/conf[root@server3 conf]# vim nginx.conf/#訪問(wèn)8088端口是的發(fā)布目錄為/var/www/html,而nginx的默認(rèn)發(fā)布目錄還是/usr/local/lnmp/nginx/html server { listen 8088;#監(jiān)聽8088端口 server_name localhost; location / { root /var/www/html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/local/lnmp/nginx/html; } } [root@server3 conf]# cd /var/www/html[root@server3 html]# vim index.html <html> <head> <title>Welcome to nginx!</title> </head> <body bgcolor="white" text="black"> <center><h2>Welcome to nginx! 172.25.44.3</h2></center> </body> </html> [root@server3 html]# nginx
安裝包:keepalived-1.2.2.tar.gz
[root@server3 software]# wget http://www.keepalived.org/software/keepalived-1.2.2.tar.gz [root@server3 software]# tar zxf keepalived-1.2.2.tar.gz [root@server3 software]# cd keepalived-1.2.2 [root@server3 keepalived-1.2.2]# ./configure [root@server3 keepalived-1.2.2]# make [root@server3 keepalived-1.2.2]# make install [root@server3 keepalived-1.2.2]# cp /usr/local/sbin/keepalived /usr/sbin/ [root@server3 keepalived-1.2.2]# cp /usr/local/etc/rc.d/init.d/keepalived /etc/init.d/ [root@server3 keepalived-1.2.2]# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/ [root@server3 keepalived-1.2.2]# cp -r /usr/local/etc/keepalived/ /etc/
[root@server3 keepalived-1.2.2]# vim /var/www/html/index.html global_defs { router_id LVS_DEVEL } vrrp_script chk_http_port { script “</dev/tcp/127.0.0.1/8088” interval 1 weight -2 } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 172.25.44.100 } track_script { chk_http_port }
[root@server3 keepalived-1.2.2]# /etc/init.d/keepalived start
備機(jī)次同步主機(jī)的操作步驟:keepalived的配置文件中,主機(jī)的state為MASTER,備機(jī)的state為BACKUP,備機(jī)的priority要小于主機(jī)
[root@server3 software]# /etc/init.d/keepalived stop Stopping keepalived: [ OK ]
[root@server4 conf]# ip a 1: lo: mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 52:54:00:48:60:3e brd ff:ff:ff:ff:ff:ff inet 172.25.44.4/24 brd 172.25.44.255 scope global eth0 inet 172.25.254.104/24 brd 172.25.254.255 scope global eth0 inet 172.25.44.100/32 scope global eth0 inet 172.25.44.100/24 brd 172.25.44.255 scope global secondary eth0:0 inet6 fe80::5054:ff:fe48:603e/64 scope link valid_lft forever preferred_lft forever
[root@server3 software]# /etc/init.d/keepalived start Starting keepalived: [ OK ]
[root@server3 software]# ip a 1: lo: mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 52:54:00:b4:14:0d brd ff:ff:ff:ff:ff:ff inet 172.25.44.3/24 brd 172.25.44.255 scope global eth0 inet 172.25.254.103/24 brd 172.25.254.255 scope global eth0 inet 172.25.44.100/32 scope global eth0 inet6 fe80::5054:ff:feb4:140d/64 scope link valid_lft forever preferred_lft forever
[root@server3 software]# killall nginx
問(wèn)題補(bǔ)充:在備機(jī)keepalived的配合配置文件中,如果補(bǔ)修改state的情況下實(shí)驗(yàn)也是可以成功的,我覺得應(yīng)該時(shí)兩個(gè)機(jī)子通過(guò)priority優(yōu)先級(jí)競(jìng)爭(zhēng)。
分享標(biāo)題:keepalived+nginx
地址分享:http://jinyejixie.com/article44/jjhsee.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、虛擬主機(jī)、面包屑導(dǎo)航、手機(jī)網(wǎng)站建設(shè)、移動(dòng)網(wǎng)站建設(shè)、響應(yīng)式網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)