建站服务器
ngxin作为一个强大的开源软件是可以先做为高可用集群服务的,这篇博文就介绍一下nginx keepalived是如何实现高性能 高可用集群服务的
环境介绍:
硬件: 4台虚拟服务器
系统:centos 7.3
软件:keepalived、apache、nginx
ip及主机名
master
主机名:shiyan1
ip地址:172.18.17.31
backup
主机名:shiyan2
ip地址:172.18.17.32
httpd1
主机名:shiyan3
ip地址:172.18.17.33
httpd2
主机名:shiyan4
ip地址:172.18.17.34
四台服务器初始化配置(四台服务器相同的配置)
关闭防火墙
[root@shiyan~]#systemctldisablefirewalld[root@shiyan~]#systemctlstopfirewalld[root@shiyan~]#iptables–f
关闭selinux
[root@shiyan~]#vim/etc/selinux/configselinux=disabled#保存重启系统生效
安装软件
master/backup
[root@shiyan~]#yuminstallkeepalivedhttpdnginx#(nginx需要单独配置epel源) httpd1/httpd2
[root@shiyan~]#yuminstallhttpd
httpd1配置
[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.#<directory/app/apache>#更改为自定义的路径allowoverridenone#allowopenaccess:requireallgranted</directory>#furtherrelaxaccesstothedefaultdocumentroot:<directory/app/apache/html>#更改为自定义的路径.[root@shiyan3~]#systemctlrestarthttpd#测试网站是否正常运行[root@yum~]#curlhttp://172.18.17.33apacheserver1#测试成功
httpd2配置
[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.#<directory/app/apache>#更改为自定义的路径allowoverridenone#allowopenaccess:requireallgranted</directory>#furtherrelaxaccesstothedefaultdocumentroot:<directory/app/apache/html>#更改为自定义的路径.[root@shiyan4~]#systemctlrestarthttpd#测试网站是否正常运行[root@yum~]#curlhttp://172.18.17.34apacheserver2#测试成功
master配置
配置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中的内容,并非添加内容listen8080documentroot/app/apache/html#更改为自定义的路径##relaxaccesstocontentwithin/var/www.#<directory/app/apache>#更改为自定义的路径allowoverridenone#allowopenaccess:requireallgranted</directory>#furtherrelaxaccesstothedefaultdocumentroot:<directory/app/apache/html>#更改为自定义的路径.[root@shiyan1~]#systemctlrestarthttp#测试网站是否正常运行[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.confglobal_defs{notification_email{root#定义收邮件的用户}notification_email_fromalexandre.cassen@firewall.locsmtp_server172.18.17.31#定义邮件地址smtp_connect_timeout30router_idnode1#定义节点名称}vrrp_instancevi_1{statemaster#定义节点为主节点模式interfaceens33#定义使用ens33为vip网卡virtual_router_id51#定义节点编号priority150#定义优先级advert_int1authentication{auth_typepassauth_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.confserver{listen80;location/{roothtml;proxy_passhttp://websrvs;indexindex.htmlindex.htm;}}[root@shiyan1~]#systemctlrestartnginx[root@shiyan1~]#systemctlrestartkeepalived[root@shiyan1~]#systemctlrestarthttpd
backup配置
配置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中的内容,并非添加内容listen8080documentroot/app/apache/html#更改为自定义的路径##relaxaccesstocontentwithin/var/www.#<directory/app/apache>#更改为自定义的路径allowoverridenone#a
学生租用阿里云服务器多少钱营销型企业网站建设哪家好新买的云服务器远程无法联网信息网络安全保护方案容器云怎么省钱腾讯云服务器建站域名腾讯云服务器怎么按天续费知网研学如何下载文献 知网研学下载文献的方法