中文字幕日韩精品一区二区免费_精品一区二区三区国产精品无卡在_国精品无码专区一区二区三区_国产αv三级中文在线

keepalived+nginx+tomcat搭建高性能web服務(wù)器集群

建站服務(wù)器

使用keepalived+nginx+tomcat搭建高性能web服務(wù)器集群,前端用nginx做反向代理實(shí)現(xiàn)負(fù)載均衡,同時(shí)結(jié)合keepalived對(duì)nginx實(shí)現(xiàn)高可用,后端使用tomcat做動(dòng)態(tài)jsp解析,實(shí)現(xiàn)了動(dòng)靜分離。

十余年的滁州網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開(kāi)發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。營(yíng)銷(xiāo)型網(wǎng)站建設(shè)的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整滁州建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“滁州網(wǎng)站設(shè)計(jì)”,“滁州網(wǎng)站推廣”以來(lái),每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。

(本文永久地址:http://woymk.blog.51cto.com/10000269/1928716)

搭建環(huán)境:centos 6.9

準(zhǔn)備四臺(tái)服務(wù)器
vip: 192.168.75.130
master: 192.168.75.131 (安裝nginx做反向代理實(shí)現(xiàn)負(fù)載勻衡,結(jié)合keepalived實(shí)現(xiàn)高可用)
backup: 192.168.75.132 (同上)
web1: 192.168.75.151 (安裝nginx和tomcat實(shí)現(xiàn)動(dòng)靜分離)
web2: 192.168.75.152 (同上)
這里為節(jié)省服務(wù)器,nginx和tomcat裝在了一臺(tái)服務(wù)上,也可以分開(kāi)配置。

配置步驟如下:

1. 安裝nginx、tomcat軟件

四臺(tái)服務(wù)器分別安裝好nginx
安裝方法參見(jiàn):LNMP環(huán)境搭建

web1,web2上分別安裝好tomcat

安裝方法參見(jiàn):Tomcat8.5的安裝配置

web1, web2上分別啟動(dòng)nginx和tomcat
service nginx start
service tomcat start

2. 在master和backup上配置nginx

vi /usr/local/nginx/conf/nginx.conf

加入或修改以下內(nèi)容:

upstreamweb_nginx {
server 192.168.75.151;
server 192.168.75.152;
}

upstreamweb_tomcat {

#ip_hash;

server 192.168.75.151:8080;
server 192.168.75.152:8080;
}

server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
proxy_pass http://web_nginx/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location ~ \\.jsp$ {
proxy_pass http://web_tomcat/;
}

}

分別在master和backup上啟動(dòng)nginx服務(wù)

service nginx start

3. 配置keepalived

在master和backup上分別安裝keepalived
yum install -y keepalived

1) 配置master
vi /etc/keepalived/keepalived.conf
清空原文,加入如下內(nèi)容:
! Configuration File for keepalived

global_defs {
notification_email {
#acassen@firewall.loc
#failover@firewall.loc
#sysadmin@firewall.loc
}
#notification_email_from Alexandre.Cassen@firewall.loc
#smtp_server 192.168.200.1
#smtp_connect_timeout 30
router_id LVS_DEVEL
}

vrrp_script chk_http_port {
script </dev/tcp/127.0.0.1/80
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 {
192.168.75.130
}
track_script {
chk_http_port
}
}

2) 配置backup
scp 192.168.75.131:/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf

vi /etc/keepalived/keepalived.conf
backup的配置文件只需要修改
state MASTER -> state BACKUP
priority 100 -> priority 99

最后,分別在master和backup上啟動(dòng)keepalived服務(wù),先主后備
/etc/init.d/keepalived start

4. 測(cè)試:

在master上停止nginx服務(wù)

[root@master ~]# /etc/init.d/nginx stop
停止 nginx: [確定]

在backup上查看日志

[root@backup ~]# tail -f /var/log/messages

May 23 17:21:33 backup Keepalived_vrrp[1818]: VRRP_Instance(VI_1) forcing a new MASTER election
May 23 17:21:33 backup Keepalived_vrrp[1818]: VRRP_Instance(VI_1) forcing a new MASTER election
May 23 17:21:34 backup Keepalived_vrrp[1818]: VRRP_Instance(VI_1) Transition to MASTER STATE
May 23 17:21:35 backup Keepalived_vrrp[1818]: VRRP_Instance(VI_1) Entering MASTER STATE
May 23 17:21:35 backup Keepalived_vrrp[1818]: VRRP_Instance(VI_1) setting protocol VIPs.
May 23 17:21:35 backup Keepalived_vrrp[1818]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.75.130
May 23 17:21:35 backup Keepalived_healthcheckers[1817]: Netlink reflector reports IP 192.168.75.130 added
May 23 17:21:40 backup Keepalived_vrrp[1818]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.75.130

日志顯示已經(jīng)成功切換到備用節(jié)點(diǎn)上。

[root@backup ~]# curl 192.168.75.130 -I
HTTP/1.1 200 OK
Server: nginx/1.10.3
Date: Tue, 23 May 2017 09:34:21 GMT
Content-Type: text/html
Content-Length: 616
Connection: keep-alive
Last-Modified: Mon, 22 May 2017 10:28:07 GMT
ETag: 5922bd37-268
Accept-Ranges: bytes

master停掉后,用curl訪問(wèn)web服務(wù),一切正常。

當(dāng)前名稱(chēng):keepalived+nginx+tomcat搭建高性能web服務(wù)器集群
網(wǎng)站網(wǎng)址:http://www.rwnh.cn/article4/cpjoie.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷(xiāo)微信小程序、外貿(mào)網(wǎng)站建設(shè)、面包屑導(dǎo)航企業(yè)網(wǎng)站制作、網(wǎng)站導(dǎo)航

廣告

聲明:本網(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)

綿陽(yáng)服務(wù)器托管
通江县| 凤翔县| 九江市| 冕宁县| 普格县| 汉川市| 廉江市| 武乡县| 阳谷县| 阜平县| 张家川| 济宁市| 淄博市| 深水埗区| 凌源市| 保德县| 定西市| 铁岭县| 朝阳市| 台州市| 广安市| 田东县| 遂平县| 嘉兴市| 大关县| 始兴县| 临桂县| 维西| 化州市| 苏尼特右旗| 新干县| 榆社县| 同仁县| 浦城县| 海南省| 石景山区| 克拉玛依市| 高雄县| 康平县| 马关县| 邵阳县|