网站建设资讯

NEWS

网站建设资讯

Keepaliev+Nginx+http

建站服务器

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

[root@shiyan~]#vim/etc/selinux/config
SELINUX=disabled
#保存重启系统生效

[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中的内容,并非添加内容
DocumentRoot/app/apache/html
#更改为自定义的路径

#
#Relaxaccesstocontentwithin/var/www.
#
#更改为自定义的路径
AllowOverrideNone
#Allowopenaccess:
Requireallgranted


#Furtherrelaxaccesstothedefaultdocumentroot:
#更改为自定义的路径.
[root@shiyan3~]#systemctlrestarthttpd

#测试网站是否正常运行
[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中的内容,并非添加内容
DocumentRoot/app/apache/html
#更改为自定义的路径

#
#Relaxaccesstocontentwithin/var/www.
#
#更改为自定义的路径
AllowOverrideNone
#Allowopenaccess:
Requireallgranted


#Furtherrelaxaccesstothedefaultdocumentroot:
#更改为自定义的路径.
[root@shiyan4~]#systemctlrestarthttpd
#测试网站是否正常运行
[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

SorryServer1

>/app/apache/html/index.html [root@shiyan1~]#vim/etc/httpd/conf/httpd.conf #此处是更改httpd.conf中的内容,并非添加内容 Listen8080 DocumentRoot/app/apache/html #更改为自定义的路径 # #Relaxaccesstocontentwithin/var/www. # #更改为自定义的路径 AllowOverrideNone #Allowopenaccess: Requireallgranted #Furtherrelaxaccesstothedefaultdocumentroot: #更改为自定义的路径. [root@shiyan1~]#systemctlrestarthttp #测试网站是否正常运行 [root@yum~]#curlhttp://172.18.17.31:8080

SorryServer1

#测试成功 配置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#定义节点名称 } vrrp_instanceVI_1{ stateMASTER#定义节点为主节点模式 interfaceens33#定义使用ens33为VIP网卡 virtual_router_id51#定义节点编号 priority150#定义优先级 advert_int1 authentication{ auth_typePASS auth_pass1111 } virtual_ipaddress{ 172.18.17.30#定义VIP } } ~配置Nginx服务 [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部分的内容需要全部注释掉 [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

创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于网站建设、成都做网站、岐山网络推广、微信小程序定制开发、岐山网络营销、岐山企业策划、岐山品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们大的嘉奖;创新互联公司为所有大学生创业者提供岐山建站搭建服务,24小时服务热线:18982081108,官方网址:www.cdcxhl.com
配置Sorry-Server
[root@shiyan2~]#mkdir-p/app/apache/html/
[root@shiyan2~]#chown-Rapache.apache/app/apache/html/
[root@shiyan2~]#echo

SorryServer2

>/app/apache/html/index.html [root@shiyan2~]#vim/etc/httpd/conf/httpd.conf #此处是更改httpd.conf中的内容,并非添加内容 Listen8080 DocumentRoot/app/apache/html #更改为自定义的路径 # #Relaxaccesstocontentwithin/var/www. # #更改为自定义的路径 AllowOverrideNone #Allowopenaccess: Requireallgranted #Furtherrelaxaccesstothedefaultdocumentroot: #更改为自定义的路径. [root@shiyan2~]#systemctlrestarthttp #测试网站是否正常运行 [root@yum~]#curlhttp://172.18.17.31:8080

SorryServer2

#测试成功 配置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#定义节点名称 } vrrp_instanceVI_1{ stateMASTER#定义节点为主节点模式 interfaceens33#定义使用ens33为VIP网卡 virtual_router_id51#定义节点编号 priority150#定义优先级 advert_int1 authentication{ auth_typePASS auth_pass1111 } virtual_ipaddress{ 172.18.17.30#定义VIP } } ~配置Nginx服务 [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部分的内容需要全部注释掉 [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

#默认使用rr算法依次轮询访问后端httpd服务器
[root@yum~]#curlhttp://172.18.17.30
ApacheServer1
[root@yum~]#curlhttp://172.18.17.30
ApacheServer2

#关闭后端http1服务,这样只能访问httpd2的服务
[root@yum~]#curlhttp://172.18.17.30
ApacheServer2
[root@yum~]#curlhttp://172.18.17.30
ApacheServer2

#关闭两台后端主机的httpd服务,这样因为没有后端服务器所以Master的sorry-server提供服务
[root@yum~]#curlhttp://172.18.17.30

SorryServer1

#关闭Master测试 [root@yum~]#curlhttp://172.18.17.30

SorryServer2


名称栏目:Keepaliev+Nginx+http
URL标题:http://cdweb.net/article/chshog.html