1.配置yum仓库,列出仓库
2.安装ldirectord-3.9.5-3.1.x86_64.rpm软件
[root@server1 ~]# yum install ldirectord-3.9.5-3.1.x86_64.rpm -y
提示:此安装包在官网已经下载好
3.查看配置文件
[root@server1 ~]# rpm -qpl ldirectord-3.9.5-3.1.x86_64.rpm
4.把配置文件模版复制到/etc/ha.d/下,切换到/etc/ha.d/下
[root@server1 ~]# cp /usr/share/doc/ldirectord-3.9.5/ldirectord.cf /etc/ha.d/
[root@server1 ~]# cd /etc/ha.d/
[root@server1 ha.d]# ls
5.编辑配置文件
[root@server1 ha.d]# vim ldirectord.cf
6.开启服务
[root@server1 ha.d]# /etc/init.d/ldirectord start
7.测试:
- 当后台服务器都正常时,进行轮询调度
[root@foundation63 ~]# curl 172.25.63.100
<h1>server3 - www.westos.org</h1>
[root@foundation63 ~]# curl 172.25.63.100
<h1>server2.example.com</h1>
[root@foundation63 ~]# curl 172.25.63.100
<h1>server3 - www.westos.org</h1>
[root@foundation63 ~]# curl 172.25.63.100
<h1>server2.example.com</h1>
- 将server3的httpd关闭,只调度server2服务器
[root@foundation63 ~]# curl 172.25.63.100
<h1>server2.example.com</h1>
[root@foundation63 ~]# curl 172.25.63.100
<h1>server2.example.com</h1>
[root@foundation63 ~]# curl 172.25.63.100
<h1>server2.example.com</h1>
[root@foundation63 ~]# curl 172.25.63.100
<h1>server2.example.com</h1>
- 将server2和server3的httpd都关闭
<1>切换到/var/www/html下,删除目录下之前的所有东西,编辑前端文件
[root@server1 ha.d]# cd /var/www/html
[root@server1 html]# ls
class_socket.php config.php index.php purge_action.php static
[root@server1 html]# rm -fr *
[root@server1 html]# vim index.html
[root@server1 html]# cat index.html
<h1>哎呀,页面不见了,稍等正在维修</h1>
<2>修改http服务端口为80
[root@server1 html]# vim /etc/httpd/conf/httpd.conf
[root@server1 html]# /etc/init.d/httpd restart
<3>重启http服务
<4>curl 172.25.63.100 出现刚刚测试页写的内容
[root@foundation63 ~]# curl 172.25.63.100
<h1>哎呀,页面不见了,稍等正在维修</h1>
[root@foundation63 ~]# curl 172.25.63.100
<h1>哎呀,页面不见了,稍等正在维修</h1>
[root@foundation63 ~]# curl 172.25.63.100
<h1>哎呀,页面不见了,稍等正在维修</h1>
[root@foundation63 ~]# curl 172.25.63.100
<h1>哎呀,页面不见了,稍等正在维修</h1>