症状:通过虚拟IP能访问到监控页面:http://192.168.253.110/ipvsadm.php,但是却无法读出LVS任务分发及集群负载信息。
打开ipvsadm.php页面,源码如下:
<html> <meta http-equiv="refresh" content="1"> <?php $cmd = '/home/geohpc/zmq/lvsstatus.sh';//页面每间隔2s会自动刷新,执行该脚本读取LVS负载信息 $result=shell_exec($cmd); echo "<hr>"; $i = 0; $table_begin = 0; while ($result) { $i++; $len = strpos ($result, " "); $line = substr ($result, 0, $len); $result = substr ($result, $len + 1); if ($i <= 3) continue; $result = trim ($result, " "); $isReal = strpos ($line, ">"); if ($isReal == 1) { // list($jiantou, $ip, $route, $weight, $act, $inact) = split(" ",$line); $con = preg_split("[ ]",$line,-1,PREG_SPLIT_NO_EMPTY); $content = "<tr>"; $content = $content."<td>$con[1]</td>"; $content = $content."<td>$con[3]</td>"; $content = $content."<td>$con[4]</td>"; $content = $content."<td>$con[5]</td>"; $content .= "<tr>"; echo $content; } else { if ($table_begin == 1) { echo "</table><div>"; echo "<hr>"; } $head = "<div align="middle">"; $head .= "<h1>".$line."</h1>"; $head .= "<table border="1" width="50%"><tr>"; $head .="<th width="10">server:port</th>"; $head .="<th>Weight</th>"; $head .="<th>Active</th>"; $head .="<th>Inactive</th>"; $head .="</tr>"; echo $head; $table_begin = 1; } } echo "</table>" ?> <script> sleep(2); window.location.reload(); </script> </html>
脚本文件lvsstatus.sh如下:
#!/bin/bash echo "geohpc" | /usr/bin/sudo -S ipvsadm -L
问题:上述脚本文件的含义为以超级用户的权限请求ipvsadm服务,查看其转发状态,而echo后引号内为su用户的密码,这样每次刷新页面执行上述脚本时将自动为sudo填入密码。
可是,此处输入的密码确是错误的,因为为安全起见,2013年初集群演示完毕后更改过一次密码,修改为正确密码后,集群LVS的监控页面马上显示出来了,如下: