Keepaliev+Nginx+http

建站服務(wù)器

[root@shiyan~]#systemctldisablefirewalld
[root@shiyan~]#systemctlstopfirewalld
[root@shiyan~]#iptables–F

[root@shiyan~]#vim/etc/selinux/config
SELINUX=disabled
#保存重啟系統(tǒng)生效

[root@shiyan~]#yuminstallkeepalivedhttpdnginx#(Nginx需要單獨配置EPEL源)

[root@shiyan~]#yuminstallhttpd

[root@shiyan3~]#mkdir-p/app/apache/html/
[root@shiyan3~]#chown-Rapache.apache/app/apache/html/
[root@shiyan3~]#echoApacheServer1>/app/apache/html/index.html
[root@shiyan3~]#vim/etc/httpd/conf/httpd.conf
#此處是更改httpd.conf中的內(nèi)容,并非添加內(nèi)容
DocumentRoot/app/apache/html
#更改為自定義的路徑

#
#Relaxaccesstocontentwithin/var/www.
#
<Directory/app/apache>#更改為自定義的路徑
AllowOverrideNone
#Allowopenaccess:
Requireallgranted
</Directory>

#Furtherrelaxaccesstothedefaultdocumentroot:
<Directory/app/apache/html>#更改為自定義的路徑.
[root@shiyan3~]#systemctlrestarthttpd

#測試網(wǎng)站是否正常運行
[root@yum~]#curlhttp://172.18.17.33
ApacheServer1#測試成功

[root@shiyan4~]#mkdir-p/app/apache/html/
[root@shiyan4~]#chown-Rapache.apache/app/apache/html/
[root@shiyan4~]#echoApacheServer2>/app/apache/html/index.html
[root@shiyan4~]#vim/etc/httpd/conf/httpd.conf
#此處是更改httpd.conf中的內(nèi)容,并非添加內(nèi)容
DocumentRoot/app/apache/html
#更改為自定義的路徑

#
#Relaxaccesstocontentwithin/var/www.
#
<Directory/app/apache>#更改為自定義的路徑
AllowOverrideNone
#Allowopenaccess:
Requireallgranted
</Directory>

#Furtherrelaxaccesstothedefaultdocumentroot:
<Directory/app/apache/html>#更改為自定義的路徑.
[root@shiyan4~]#systemctlrestarthttpd
#測試網(wǎng)站是否正常運行
[root@yum~]#curlhttp://172.18.17.34
ApacheServer2#測試成功

配置Sorry-Server
[root@shiyan1~]#mkdir-p/app/apache/html/
[root@shiyan1~]#chown-Rapache.apache/app/apache/html/
[root@shiyan1~]#echo<h2>SorryServer1</h2>>/app/apache/html/index.html
[root@shiyan1~]#vim/etc/httpd/conf/httpd.conf
#此處是更改httpd.conf中的內(nèi)容,并非添加內(nèi)容
Listen8080
DocumentRoot/app/apache/html
#更改為自定義的路徑

#
#Relaxaccesstocontentwithin/var/www.
#
<Directory/app/apache>#更改為自定義的路徑
AllowOverrideNone
#Allowopenaccess:
Requireallgranted
</Directory>

#Furtherrelaxaccesstothedefaultdocumentroot:
<Directory/app/apache/html>#更改為自定義的路徑.
[root@shiyan1~]#systemctlrestarthttp
#測試網(wǎng)站是否正常運行
[root@yum~]#curlhttp://172.18.17.31:8080
<h2>SorryServer1</h2>#測試成功
配置Keepalived
[root@shiyan1~]#cp/etc/keepalived/keepalived.conf{,.bak}#備份文件
[root@shiyan1~]#vim/etc/keepalived/keepalived.conf
global_defs{
notification_email{
root#定義收郵件的用戶
}
notification_email_fromAlexandre.Cassen@firewall.loc
smtp_server172.18.17.31#定義郵件地址
smtp_connect_timeout30
router_idnode1#定義節(jié)點名稱
}

vrrp_instanceVI_1{
stateMASTER#定義節(jié)點為主節(jié)點模式
interfaceens33#定義使用ens33為VIP網(wǎng)卡
virtual_router_id51#定義節(jié)點編號
priority150#定義優(yōu)先級
advert_int1
authentication{
auth_typePASS
auth_pass1111
}
virtual_ipaddress{
172.18.17.30#定義VIP
}
}
~配置Nginx服務(wù)
[root@shiyan1~]#vim/etc/nginx/nginx.conf
#添加nginx集群
upstreamwebsrvs{
server172.18.17.33:80;
server172.18.17.34:80;
server127.0.0.1:8080backup;
}
#server部分的內(nèi)容需要全部注釋掉

[root@shiyan1~]#vim/etc/nginx/conf.d/default.conf
server{
listen80;
location/{
roothtml;
proxy_passhttp://websrvs;
indexindex.htmlindex.htm;
}
}
[root@shiyan1~]#systemctlrestartnginx
[root@shiyan1~]#systemctlrestartkeepalived
[root@shiyan1~]#systemctlrestarthttpd

創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站建設(shè)、成都做網(wǎng)站、岐山網(wǎng)絡(luò)推廣、微信小程序定制開發(fā)、岐山網(wǎng)絡(luò)營銷、岐山企業(yè)策劃、岐山品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們大的嘉獎;創(chuàng)新互聯(lián)公司為所有大學(xué)生創(chuàng)業(yè)者提供岐山建站搭建服務(wù),24小時服務(wù)熱線:18982081108,官方網(wǎng)址:muchs.cn
配置Sorry-Server
[root@shiyan2~]#mkdir-p/app/apache/html/
[root@shiyan2~]#chown-Rapache.apache/app/apache/html/
[root@shiyan2~]#echo<h2>SorryServer2</h2>>/app/apache/html/index.html
[root@shiyan2~]#vim/etc/httpd/conf/httpd.conf
#此處是更改httpd.conf中的內(nèi)容,并非添加內(nèi)容
Listen8080
DocumentRoot/app/apache/html
#更改為自定義的路徑

#
#Relaxaccesstocontentwithin/var/www.
#
<Directory/app/apache>#更改為自定義的路徑
AllowOverrideNone
#Allowopenaccess:
Requireallgranted
</Directory>

#Furtherrelaxaccesstothedefaultdocumentroot:
<Directory/app/apache/html>#更改為自定義的路徑.
[root@shiyan2~]#systemctlrestarthttp
#測試網(wǎng)站是否正常運行
[root@yum~]#curlhttp://172.18.17.31:8080
<h2>SorryServer2</h2>#測試成功
配置Keepalived
[root@shiyan2~]#cp/etc/keepalived/keepalived.conf{,.bak}#備份文件
[root@shiyan2~]#vim/etc/keepalived/keepalived.conf
global_defs{
notification_email{
root#定義收郵件的用戶
}
notification_email_fromAlexandre.Cassen@firewall.loc
smtp_server172.18.17.31#定義郵件地址
smtp_connect_timeout30
router_idnode1#定義節(jié)點名稱
}

vrrp_instanceVI_1{
stateMASTER#定義節(jié)點為主節(jié)點模式
interfaceens33#定義使用ens33為VIP網(wǎng)卡
virtual_router_id51#定義節(jié)點編號
priority150#定義優(yōu)先級
advert_int1
authentication{
auth_typePASS
auth_pass1111
}
virtual_ipaddress{
172.18.17.30#定義VIP
}
}
~配置Nginx服務(wù)
[root@shiyan2~]#vim/etc/nginx/nginx.conf
#添加nginx集群
upstreamwebsrvs{
server172.18.17.33:80;
server172.18.17.34:80;
server127.0.0.1:8080backup;
}
#server部分的內(nèi)容需要全部注釋掉

[root@shiyan2~]#vim/etc/nginx/conf.d/default.conf
server{
listen80;
location/{
roothtml;
proxy_passhttp://websrvs;
indexindex.htmlindex.htm;
}
}
[root@shiyan2~]#systemctlrestartkeepalived
[root@shiyan2~]#systemctlrestartnginx
[root@shiyan2~]#systemctlrestarthttpd

#默認(rèn)使用rr算法依次輪詢訪問后端httpd服務(wù)器
[root@yum~]#curlhttp://172.18.17.30
ApacheServer1
[root@yum~]#curlhttp://172.18.17.30
ApacheServer2

#關(guān)閉后端http1服務(wù),這樣只能訪問httpd2的服務(wù)
[root@yum~]#curlhttp://172.18.17.30
ApacheServer2
[root@yum~]#curlhttp://172.18.17.30
ApacheServer2

#關(guān)閉兩臺后端主機(jī)的httpd服務(wù),這樣因為沒有后端服務(wù)器所以Master的sorry-server提供服務(wù)
[root@yum~]#curlhttp://172.18.17.30
<h2>SorryServer1</h2>
#關(guān)閉Master測試
[root@yum~]#curlhttp://172.18.17.30
<h2>SorryServer2</h2>

標(biāo)題名稱:Keepaliev+Nginx+http
標(biāo)題URL:http://muchs.cn/article6/chshog.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站網(wǎng)站營銷、網(wǎng)頁設(shè)計公司、定制開發(fā)、微信小程序、網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)