实验要求:
1。一台Haproxy调度服务器,两台Nginx服务器,一台windows7多作为客户端;
2。三台服务器为CentOS 7.3的64位系统;
3。所有主机网卡都设置成仅主机模式,绑定静态地址;
4。客户端可以通过访问调度服务器,访问到两台节点服务器,不需要访问真实服务器地址
引用> 主机 角色 IP地址 centos7-1 Haproxy服务器 192.168.1.10 centos7-2 Nginx服务器1 192.168.1.20 centos7-3 Nginx服务器2 192.168.1.30 赢得7 windows7多客户端 192.168.1.40实验步骤:
1,搭建两台Nginx服务器
<>强安装环境包及nginx 强>
<代码类="语言java ">安装\ [root@nginx1 mnt] # yum - y gcc \ gcc-c + + \ zlib-devel \ pcre pcre-devel \ expat-devel [root@nginx1 mnt] # useradd - m - s/sbin/nologin nginx #建立管理用户 [root@nginx1 mnt] #焦油zxvf nginx-1.12.0.tar。广州- c/opt/# ./configure \ [root@nginx1 nginx-1.12.0) ——prefix=/usr/地方/nginx \ ——用户=nginx \ ——组=nginx [root@nginx1 nginx-1.12.0] #做,,使安装#编译安装 [root@nginx1 nginx-1.12.0] # ln - s/usr/local/nginx/sbin/nginx/usr/local/sbin/[root@nginx1 nginx-1.12.0] # vim/usr/local/nginx/html/test.html #编写首页 & lt; h2> ACCP web ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! & lt;/h2> 代码><强>编写启动脚本强>
<代码类=" language-shell "> [root@nginx1 nginx-1.12.0] # vim/etc/init.d/nginx #方便服务调取 # !/bin/bash 文剑="/usr/地方/nginx/sbin/nginx” pid="/usr/地方/nginx/日志/nginx.pid” 案例1美元 开始) 文剑美元;; 停止) 杀- s辞职(猫pid)美元美元;; 重启) 0美元停止 $ 0开始 ;; 重新加载) 杀- s玫瑰(猫pid)美元美元;; *) 回声“请再试一次” 退出1;; esac 退出0 [root@nginx1 nginx-1.12.0] # chmod + x/etc/init.d/nginx #开服务 [root@nginx1 nginx-1.12.0] #服务nginx的开始 [root@nginx1 nginx-1.12.0] # systemctl firewalld.service停止 [root@nginx1 nginx-1.12.0] # setenforce 0 #改静态 [root@nginx1 nginx-1.12.0] # vim/etc/sysconfig/network-scripts/ifcfg-ens33 [root@nginx1 nginx-1.12.0] # systemctl重启nework 代码>2,搭建Haproxy调度服务器
<>强安装环境包及haproxy 强>
<代码类="语言java "> #改静态 [root@nginx1 nginx-1.12.0] # vim/etc/sysconfig/network-scripts/ifcfg-ens33 [root@nginx1 nginx-1.12.0] # systemctl nework重启 # #安装环境包 [root@haproxy mnt] # yum - y安装gcc gcc-c + + bzip2-devel pcre pcre-devel haproxy #安装 root@nginx1 ~ #山。cifs//192.168.10.71/rpm/mnt/[root@localhost mnt] #焦油zxvf haproxy-1.5.19.tar。广州- c/opt/[root@localhost mnt] # cd/opt/haproxy-1.5.19/#源码编译,安装 [root@localhost haproxy-1.5.19] #让目标=linux26 # #编版本为Linux内核版本(使用uname -查看) [root@localhost haproxy-1.5.19] # make install 代码><>强修改配置文件强>
<代码类="语言java "> root@localhost haproxy-1.5.19] # mkdir/etc/haproxy #创建配置文件站点 [root@localhost haproxy-1.5.19] # cp/haproxy例子。cfg/etc/haproxy/#复制模板 [root@localhost haproxy-1.5.19] # vim/etc/haproxy/haproxy.cfg #修改配置文件 chroot/usr/share/haproxy #(默认家目录)删除该行,文件实际并不存在 redispatch #将请求发给故障节点(没啥用关掉) - - - - - - - - - - - - - - - - - - - - - - - -着段全部删除- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # #添加 听webcluster 0.0.0.0:80 选择httpchk/测试。html #开启对后端服务器的健康检测(这里是提交测试测试页面) #后使用加密方式提交参数,得到使用明文方式直接提交参数,参数显示在url上 此平衡循环#负载均衡采用轮询算法 服务器inst1 192.168.1.20:80检查国米2000年秋季3 #定义在线节点1 服务器inst2和192.168.1.30:80检查国米2000年秋季3 #定义在线节点2 代码><强>定义启动脚本强>
<代码类="语言java "> #定义启动脚本 [root@localhost haproxy-1.5.19] # cp/opt/haproxy-1.5.19//haproxy例子。init/etc/init.d/haproxy [root@localhost haproxy-1.5.19] # chmod + x/etc/init.d/haproxy [root@localhost haproxy-1.5.19] # chkconfig——添加/etc/init.haproxy d/# #添加进启动列表 [root@localhost haproxy-1.5.19] # ln - s/usr/local/sbin/haproxy/usr/sbin/#启服务 haproxy [root@localhost haproxy-1.5.19] #服务开始 [root@localhost haproxy-1.5.19] # systemctl firewalld.service停止 [root@localhost haproxy-1.5.19] # setenforce 0Haproxy搭建网站群集——实战篇