Cacti插件详解——Weathermap
Weathermap是cacti中大家最用的一个插件之一,用它可以画出漂亮的网络拓扑图!同时Weathermap也是一个独立工具,可以独立部署,不需要cacti的支持,也可以部署.下面首先来看一看用Weathermap画出来的拓扑图.
一.weathermap 作为 cacti 插件的用法
1.安装 weathermap 插件
wget http://www.network-weathermap.com/files/php-weathermap-0.97a.zip
unzip php-weathermap-0.97a.zip
mv weathermap/ /var/www/html/plugins/
chown -R apache:apache /var/www/html/plugins/weathermap/configs/
chown -R apache:apache /var/www/html/plugins/weathermap/output/
点击安装 weathermap 后
至此,weathermap 已经安装成功。
2.配置使用 weathermap
安装好 weathermap 后,看到点 Console 在左边的列表里会看到 weathermap 的菜单,我们点击,会看到设置,因为我们还没有定义一个 weathermap 配置文件,所以我们点右上角的 Add 按钮,添加一个 weathermap 配置文件
点击 Add 之后,我们看到有二个文件,其实这个时候调用的就是 weathermap 的 configs 目录下的文件,simple.conf 就是自带的一个配置文件,我们可以点击它前面的 Add 按钮,把他添加到默认配置文件里
至此我们添加了一个 weathermap 的配置文件,下面就是对 weathermap 进行配置了,点击 weathermap,然后点击 Editor 对默认图形配置文件进行配置。
点击 editor 后我们会看到如下提示
The editor has not been enabled yet. You need to set ENABLED=true at the top of editor.php
Before you do that, you should consider using FilesMatch (in Apache) or similar to limit who can access the editor. There is more information in the install guide section of the manual.
我们按照他提示的编辑 editor.php
vi /var/www/html/plugins/weathermap/editor.php
<php
require_once 'editor.inc.php';
require_once 'Weathermap.class.php';
// so that you can't have the editor active, and not know about it.
$ENABLED=true;
if(! $ENABLED)
{
print "
The editor has not been enabled yet. You need to set ENABLED=true at the top of editor.php
";
print "
Before you do that, you should consider using FilesMatch (in Apache) or similar to limit who can access the editor. There is more information in the install guide section of the manual.
";
exit();
}
注意问题:
vi /var/www/html/plugins/weathermap/configs/simple.conf
FONTDEFINE 100 /var/www/html/plugins/weathermap/msyh.ttf 10
<div>
<div>
<span style="font-size: 18px;">2.每次对图形进行调整后,都是自动保存的,不用保存(也没有那个选项!嘿嘿),要在weathermap里看到修改后的效果要等到下次cacti采集器采集后才会绘图。</div> <div
<div>
<span style="font-size: 18px;">>3.cacti的日志里可能会显示</div>
<div>
<span style="color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;">WEATHERMAP: Poller[0] [Map 1] simple.conf: About to write image file. If this is the last message in your log, increase memory_limit in php.ini [WMPOLL01]</span>
</div>
<div>
<span style="color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;">等信息,不过我修改php.ini里的设置也不起作用,不用管它!</span>
</div>
<div>
<div>
<span style="font-size: 18px;">4.可以在cacti的里进行设置,如图,一般默认就成</div>
<div>
<a href="https://img.cactifans.com/wp-content/uploads/2011/04/weathermap11.png"><img class="alignnone size-large wp-image-495" title="weathermap11" src="https://img.cactifans.com/wp-content/uploads/2011/04/weathermap11-1024x467.png" alt="" width="1024" height="467" srcset="https://img.cactifans.com/wp-content/uploads/2011/04/weathermap11-1024x467.png 1024w, https://img.cactifans.com/wp-content/uploads/2011/04/weathermap11-300x136.png 300w, https://img.cactifans.com/wp-content/uploads/2011/04/weathermap11.png 1280w" sizes="(max-width: 1024px) 100vw, 1024px" /></a>
</div>
<div>
</div>
<h1>
二.weathermap独立的使用。
</h1>
<div>
<div>
<span style="font-size: 18px;">通过在catci里的设置,大家会weathermap已经有了一个认识了,其实它就是用过一个配置文件,绘图,引用cacti或者mrtg的流量和图形就成了</span>
</div>
<div>
</div>
<h2>
1.安装基本环境
</h2>
<pre lang="bash" line="1" escaped="true">
yum install httpd php php-gd php-pear rrdtool -y servie http start chkconfig http on service crond start chkconfig crond on wget http://www.network-weathermap.com/files/php-weathermap-0.97a.zip unzip php-weathermap-0.97a.zip mv weathermap/ /var/www/html/ chown -R apache:apache /var/www/html/weathermap/configs/
<h2>
2.配置weathermap
</h2>
<p>
</p>
<div>
<span style="font-size: 18px;">我们要配置我们的图形配置文件</span>
</div>
<div>
</div>
<div>
<span style="font-size: 18px;">先编辑editor.php</span>
</div>
<pre lang="bash" line="1" escaped="true">vi /var/www/html/weathermap/editor.php</pre>
<div>
<span style="font-size: 18px;">把里面的$ENABLED=false;改为$ENABLED=true;$ignore_cacti=False;改为$ignore_cacti=True;然后保存。</span>
</div>
<div>
<span style="font-size: 18px;">之后我们打开http://xxx.xxx.xxx.xxx/weathermap/editor.php</span>
</div>
<div>
<span style="font-size: 18px;">就可以像在cacti里一样设计自己的weathermap图形了,</span>
</div>
<p>
</p>
<h1>
<span style="color: #ff0000;">特别注意:</span>
</h1>
<p>
</p>
<div>
<span style="font-size: 18px;">1.在这里ICO的路径要选择绝对路径,不让路径会有错误,导致不能出图。</span>
</div>
<div>
<span style="font-size: 18px;">2.eidtor.php里可以设置拓扑图输出的路径Image的路径直接写名称,不用写路径,Html的路径路径要写绝对路径。</span>
</div>
<div>
<span style="font-size: 18px;">3.在weathermap目录里有个weathermap文件要设置rrdtools的路径。$rrdtool="/usr/bin/rrdtool";</span>
</div>
<div>
<span style="font-size: 18px;">关于配置文件的我们可以weathermap官网找到</span>
</div>
<div>
<span style="font-size: 18px;">weathermap官网的设置:http://www.network-weathermap.com/manual/latest/pages/config-reference.html 具体的参数这里都有</span>
</div>
<div>
<span style="font-size: 18px;">这里还有一个配置文件的范本http://www.network-weathermap.com/manual/latest/pages/main.html#example</span>
</div>
<div>
<span style="font-size: 18px;">这个是做好的图形;http://www.network-weathermap.com/manual/latest/example/example.html</span>
</div>
<p>
</p>
<h2>
3.生成图形
</h2>
<p>
</p>
<div>
<span style="font-size: 18px;">设置好图形配置文件后我们就要生成图形了,在cacti里这个是通过cacti的采集器实现的,在单独安装weathermap的后,需要利用系统的计划任务来实现</span>
</div>
<div>
<span style="font-size: 18px;">我们先执行一次</span>
</div>
<pre lang="bash" line="1" escaped="true">/usr/bin/php /var/www/html/weathermap/weathermap --config /var/www/html/weathermap/configs/simple.conf --image-uri ../weathermap/test.png</pre>
<div>
<span style="font-size: 18px;">就可以在/下生成一个test.png图片,然后我们编辑</span>
</div>
<pre lang="bash" line="1" escaped="true">vi /etc/crontab</pre>
<div>
<span style="font-size: 18px;">添加如下</span>
</div>
<pre lang="bash" line="1" escaped="true">*/5 * * * * root /usr/bin/php /var/www/html/weathermap/weathermap --config /var/www/html/weathermap/configs/simple.conf --image-uri ../weathermap/test.png</pre>
<div>
<span style="font-size: 18px;">然后我们要做个硬链接不让png图片的路径会有错误</span>
</div>
<pre lang="bash" line="1" escaped="true">ln /test.png /var/www/html/weathermap/test.png</pre>
<div>
<span style="font-size: 18px;">至此我们的weathermap已经做好我们可以打开http://xxx.xxx.xxx.xxx/weathermap/index.html查看拓扑图。</span>
</div>
<div>
<span style="font-size: 18px;">我最终的拓扑图</span>
</div>
<p>
</p>
<p>
<a href="https://img.cactifans.com/wp-content/uploads/2011/04/weathermap12.png"><img class="alignnone size-large wp-image-498" title="weathermap12" src="https://img.cactifans.com/wp-content/uploads/2011/04/weathermap12-1024x725.png" alt="" width="1024" height="725" srcset="https://img.cactifans.com/wp-content/uploads/2011/04/weathermap12-1024x725.png 1024w, https://img.cactifans.com/wp-content/uploads/2011/04/weathermap12-300x212.png 300w, https://img.cactifans.com/wp-content/uploads/2011/04/weathermap12.png 1277w" sizes="(max-width: 1024px) 100vw, 1024px" /></a>
</p>
<h1>
总结:
</h1>
<p>
</p>
<div>
<span style="font-size: 18px;">1.weathermap的用法就说到这里,基本就是这二种了,还有的是自己做一个html,再嵌套一个weathermap的页面就像刚开始给大家说的那个中国科大的,就是通过网页的嵌套做到的,嵌套了mrtg,weathermap的页面。</span>
</div>
<div>
<span style="font-size: 18px;">2.在单独使用weathermap时要特别注意路径问题,不出图形很有可能是路径问题,这个问题我也纠结了很久。</span>
</div>
<h1>
<span style="color: #ff0000;">3.最重要的一点,就是关于weathermap的安全性问题,其实在它的官网也说明了。</span>
</h1>
<div>
地址:http://www.network-weathermap.com/manual/latest/pages/install-cacti-editor.html
</div>
<p>
</p>
<p>
<span style="color: #000000; font-family: 'Lucida Grande', 'Trebuchet MS', Verdana, Lucida, Geneva, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px;">When you are happy that the world can't edit your maps, then enable the editor. This is done by editing the top of editor.php and changing </span><code style="color: #000000; font-size: 12px; line-height: 18px;">$ENABLED=false;</code><span style="color: #000000; font-family: 'Lucida Grande', 'Trebuchet MS', Verdana, Lucida, Geneva, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px;"> to </span><code style="color: #000000; font-size: 12px; line-height: 18px;">$ENABLED=true;</code>
</p>
<p style="color: #000000; font-family: 'Lucida Grande', 'Trebuchet MS', Verdana, Lucida, Geneva, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px;">
You should now be able to go to http://your.server/cacti/plugins/weathermap/editor.php in a browser, and get a welcome page that offers to load or create a config file. That's it. All done. Please see the <a href="http://www.network-weathermap.com/manual/latest/pages/editor.html">editor manual page</a> for more about <em>using</em> the editor!
</p>
<p style="color: #000000; font-family: 'Lucida Grande', 'Trebuchet MS', Verdana, Lucida, Geneva, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px;">
You can also edit an existing map from the Cacti web interface, by choosing Manage..Weathermaps and then clicking on the name of a config file in the list of active maps. The editor will open with that map loaded.
</p>
<p style="color: #000000; font-family: 'Lucida Grande', 'Trebuchet MS', Verdana, Lucida, Geneva, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px;">
<strong>Important Security Note:</strong> The editor allows <em>anyone</em> who can access editor.php to change the configuration files for your network weathermaps. There is no authentication built-in for editing, even with the Cacti Plugin. This is why the configuration file doesn't exist by default - the editor won't work until you choose to make it work. It's recommended that you either:
</p>
<ul style="color: #000000; font-family: 'Lucida Grande', 'Trebuchet MS', Verdana, Lucida, Geneva, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px;">
<li>
change the ownership of configuration files so that the editor can't write to them once they are complete, or
</li>
<li>
use your webserver's authentication and access control facilities to limit who can access the editor.php URL. On apache, this can be done using the FilesMatch directive and mod_access.
</li>
</ul>
</div>
<div>
<span style="font-size: 18px;">可以看到在默认情况下editor.php这个是没有做验证的,就是意味<span style="color: #ff0000;">每个人都可以编辑你的weathermap图形配置文件!!!!</span>发现很多使用weathermap都没做限制,有些还是直接到公网的,再次特别提醒,一定要做一个验证!</span>
</div>
<div>
<span style="font-size: 18px;">下面我提供一种方法。</span>
</div>
<div>
<div>
<span style="font-size: 18px;">修改httpd.conf配置文件</span>
</div>
<pre lang="bash" line="1" escaped="true">vi /etc/httpd/conf/httpd.conf</pre>
<div>
<span style="font-size: 18px;">在文件最后添加</span>
</div>
<pre lang="bash" line="1" escaped="true">
<Directory /var/www/html/weathermap> <Files editor.php> Order Deny,Allow Deny from all Allow from 127.0.0.1 </Files> </Directory>
<div>
<span style="font-size: 18px;"> 然后保存,这个路劲是weathermap的路径.这样就可以限制别人访问editor.php的访问.设置好后重启apache,再访问那个页面就会出现这个页面</span>
</div>
<div>
<a href="https://img.cactifans.com/wp-content/uploads/2011/04/weathermap13.png"><img class="alignnone size-full wp-image-501" title="weathermap13" src="https://img.cactifans.com/wp-content/uploads/2011/04/weathermap13.png" alt="" width="663" height="272" srcset="https://img.cactifans.com/wp-content/uploads/2011/04/weathermap13.png 663w, https://img.cactifans.com/wp-content/uploads/2011/04/weathermap13-300x123.png 300w" sizes="(max-width: 663px) 100vw, 663px" /></a>
</div>
<div>
<span style="font-size: 18px;">当然也可以做一个基于.htaccess的验证。</span>
</div>
</div>
<div>
</div>
<div>
<span style="font-size: 18px;">本文内容都是本人自己理解,如有错误之处,请大牛指正啊,不胜感谢啊!</span>
</div>