VPS就像一台服务器,我们需要了解它的运行状态。虽然Linode控制面板已经有了很强大的监控图标功能,但是还是不能满足大多 数人的需求。这里我给大家推荐一个名为监控宝的服务,Linode经过简单的配置可以支持SNMP监控,以图表的形式监控CPU、IO和进程,能够自动报 警,而且这一切都是免费的哦。

jiankongbao-logo

目前提供的监控项目

  1. CPU使用率,监控CPU的使用率比例,包括用户态(User)、内核态(System)、I/O等待(IOWait)、空闲(Idle)等
  2. 平均负载,监控Linux服务器的平均负载(load average),包括最近1分钟、5分钟、15分钟等
  3. 内存使用率,监控内存使用率,对于Linux服务器,包括空闲内存、Buffer Cache、Page Cache、应用程序内存等
  4. 磁盘I/O,监控所有磁盘分区的I/O流量,包括写入和读取
  5. 网络流量,监控所有网络设备的流量,包括流入和流出
  6. 磁盘空间使用率,监控所有磁盘分区的空间使用率,包括总空间和已用空间

有关更多的内容,请访问:http://blog.jiankongbao.com/?p=133

如何在Linode的VPS上配置监控宝SNMP监控

系统环境:Centos 5.6_32

我们可以使用yum命令下载软件省去代码编译烦恼。

1)首先请关闭Centos的Selinux服务,否则会和snmp服务有冲突。关闭方法自行百度,很easy的。

2)在shell环境下,输入以下命令:

1、下载必要的SNMP组件,以及配置管理工具,差不多10M

1yum install net-snmp net-snmp-devel net-snmp-utils

2、创建监控用户,例如我创建一个用户名为jiankongbao,密码为123456的监控只读账户

1net-snmp-config --create-snmpv3-user -ro -A 1234565 jiankongbao

3、启动SNMP服务并且加入开机启动(大约耗费5M内存)

1service snmpd start chkconfig snmpd on

4、检测SNMP是否正常开启

1snmpwalk -v 3 -u jiankongbao -a MD5 -A "123456" -l authNoPriv 127.0.0.1 sysDescr

如果返回类内容,就说明SNMP服务已经配置好了。

3)配置SNMP服务安全问题

默认情况下,任何机器可以通过SNMP服务的账号密码通过UDP161端口远程获取服务器的状态,所以会对服务器安全产生威胁,除了建立账户和给账 户分配密码之外,还可以配合iptables只让监控宝的服务器访问Linode 的VPS,彻底杜绝安全隐患(账户密码+指定IP访问SNMP绝对专业级的安全)。

配置监控宝的iptables,只对监控宝的服务器开放SNMP的161(UDP)端口

1iptables -I INPUT -p udp -s 60.195.252.107 --dport 161 -j ACCEPT
2iptables -I INPUT -p udp -s 60.195.252.110 --dport 161 -j ACCEPT
3service iptables save
4service iptables restart

这样在服务器端SNMP的配置就OK了。

配置监控宝网站配置连接Linode的VPS

1)在导航条上方,添加服务器监控,如图:

填写服务器信息

名称任意,IP填写您的Linode服务器IP,服务器类型选择Linux/UNnix/Mac那一项

2)接下来填写SNMP服务的身份验证信息

snmp设置

如果按照本文配置的话,SNMP传输协议版本选择3,Security Nmae是您刚才配置的用户名,Pass Phrase是您刚才配置的密码(上文配置的是123456),验证选择MD5.

然后点击提交,监控宝会验证您Linode VPS的SNMP设置,需要稍等片刻,之后提示成功:

服务器添加成功

如果不成功请检查是否填错了用户密码或者iptables生效了没有。

3)下面选择监控项目,默认全部勾选

选择监控项目

这样的话,监控宝部分就配置完成了,过一阵子就能看到监控信息了。是不是很简单啊?

本文固定链接: http://www.limutian.com/linode-vps-configure-the-monitor-snmp/ | LMT的那些事

posted @ 2012-11-09 11:10 小马歌 阅读(775) | 评论 (0)编辑 收藏
 

关于阿里云和linode的介绍,这里就不再赘述,不知道或者不了解可以百度一下,相关资料有很多,作为网站建设行业,服务器是不可缺少的一项基础设施,选择一款稳定的主机会给你省去很多不必要的麻烦,在这里将阿里云主机和linode的vps做以介绍。

阿里云主机和linode

1、linode vps使用体会

网站建设行业,必然少不了和备案打交道,而国内的备案手续和流程又是异常的繁琐,而且备案周期相对较长,因此,我们把企业这些网站都放在国外主机上。选择一款稳定的国外主机很重要,经过一番参考和对比,最终选择了linode的vps,在使用过程中,linode的表现也没有让我们失望,关键是稳定,服务器跑上大半年都不用重启,访问依然很流畅,也解决了需要备案的烦恼。

linode的管理后台是纯英文的,不过常用的英文单词我们都很熟悉,不会成为使用障碍,linode的管理后台是他们自己开发的,基本上在后台可以完成一切你需要的操作,开机、关机、重启、重装系统、备份、升级配置等等吧,一般我们也很少登陆后台,除了续费的时候,一般的操作就直接通过ssh管理。

2、阿里云主机使用体会

国内近两年也兴起了云主机的热潮,由于公司运营的另一个网站流量比较大,之前在国内是自己的服务器交由机房托管,但是由于读写次数非常频繁,几乎每隔一段时间就要更换硬盘,来回折腾倒数据甚是麻烦,最终决定选择试用一下阿里云的主机(主要是考虑阿里云和万网的特殊关系),试用后感觉速度和稳定性都还好,就转到了阿里云主机上。

阿里云主机的后台界面比较简单,使用起来很方便,但是通过后台重启服务器很慢,要等很久,所以需要重启的时候一般都用ssh重启,稳定性也比较好,但是感觉阿里云主机的磁盘性能不太乐观,还有就是阿里云主机的备案有限制,一台主机上最多只能绑定5个备案的域名,这样就不太适合网站建设行业,一台主机上只放5个企业网站太浪费了。

3、linode vps和阿里云主机对比

综合下来,究竟该选择使用阿里云还是linode呢?我个人的经验是:如果你是网站建设行业,并且有一定数量的企业客户,为了减少备案的麻烦,就选择放在linode上,稳定可靠,或者你的网站很难通过工信部的备案(比如博客、论坛等),那就也放在linode上;如果你是独立运营网站、流量较大,对国内访问速度要求较高,就选择阿里云主机,或者你的客户有具体需要,要求保证访问速度和稳定性、安全性,比如政府、学校、事业单位等,建议选择放在阿里云主机上。但是,无论选择那种主机,切记备份工作很重要,不要依赖官方的备份保证什么的,因为遇到一些不可抗力的因素时(如火山、地震、海啸等),数据一旦丢失,神仙也找不回来了,所以自己还是要定期备份数据并存储到相对安全的地方。

以上是我对两大主机运营商的使用体会,希望对网站建设行业相关人员带来一定的参考价值。

本文来自:http://www.sunfei.net

注:相关网站建设技巧阅读请移步到建站教程频道。

posted @ 2012-11-08 13:29 小马歌 阅读(357) | 评论 (0)编辑 收藏
 

1. Ninja : An Authoring Tool for HTMl5 Content & Apps

25 个最新的Web应用和工具
Ninja is a fully featured content authoring tool for creative professionals who need to deploy HTML5 web applications for desktop or mobile, and want to create content in a visual way.
 
Source 
 

2. jsPDF : Create PDF Files with JavaScript

25 个最新的Web应用和工具
jsPDF, a free JavaScript library, doesn’t need any server-side script and cancreate PDF files on the client-side. It has support for text (styling is possible), drawing shapes and images. Also, the document can be set as landscape and metadata like subject an title can be added as well. The library works with no requirements in modern browsers and has aFlash-fallback for the others.
 
Source 
 

3. This is Responsive

25 个最新的Web应用和工具

This Is Responsive is an impressive and must-bookmark resource for anyone working on such layouts. It features responsive patterns for the layout, tables, navigation, forms, images and more. Also, it has a very well categorized list of links to responsive-related resources where you can find articles, tutorials and libraries/plugins.
 
Source 
 

4. Infinity.js : Speeds Up Scrolling Through Long Lists

25 个最新的Web应用和工具
Infinity.js is a UITableView for the web: it speeds up scrolling through long lists and keeps your infinite feeds smooth and stable for your users. It is small, battle-tested, and highly performant. The code is hosted on Github, and distributed under the BSD License. The annotated source is available, as are demos both with Infinity turned off and on. Infinity.js was built by Airbnb alongside the development of the Popular Wishlists and Friends feeds, and sees daily production use there today. Its only dependency is on jQuery.
 
Source 
 

5. Reveal.js : HTML Presentation Framework

25 个最新的Web应用和工具
Reveal.js is a framework for easily creating beautiful presentations using HTML. It comes with a broad range of features including nested slides, markdown contents, PDF export, speaker notes and a JavaScript API.
It’s best viewed in a browser with support for CSS 3D transforms but fallbacks are available to make sure your presentation can still be viewed elsewhere. If you’re interested in using speaker notes, reveal.js comes with a Node server that allows you to deliver your presentation in one browser while viewing speaker notes in another.
 
Source 
 

6. OpenKeyval

25 个最新的Web应用和工具

OpenKeyval is a completely open key-value data store, exposed as a drop-dead simple web service. The goal is to make this a very easy way to persist data in web applications. We simply send a POST request to store any data (with a unique prefix of our preference), can request or delete it anytime and responses comes in a JSON format. Also, like mentioned, OpenKeyval is open source. It is built with PHP and anyone can host their own instance.
 
Source 
 

7. PHP The Right Way

25 个最新的Web应用和工具
“PHP: The Right Way” is a very detailed and free documentation of PHP’s best practices to help anyone write better code. There is no standard way of writing code and the website aims to show the generally accepted practices and alternatives. Also, there are lots of links to authoritative tutorials on the web. It has topics from the setup of PHP to the basics, security, caching and much more.
 
Source 
 

8. Big Screen

25 个最新的Web应用和工具
BigScreen is a simple library for using the JavaScript Full Screen API. BigScreen makes it easy to use full screen on your site or in your app. It smoothes out browser inconsistencies and bugs, especially if the element you’re working with is inside of an iframe. It will also intelligently fall back to the older video full screen API if the element contains a

9. Site Cake : Open Source CMS for Small Websites

25 个最新的Web应用和工具

SiteCake is an open source PHP CMS application which allows site admin toedit a website while browsing it. Once logged in, everything becomes editable and it displays a “content editing bar” with options for inserting HTML elements like headers, lists, images, videos and other stuff like Google Maps or a slideshow. It is possible to crop images, drag ‘n’ drop items, create new pages and delete anything with a click. SiteCake-enabling any website is easy by simply adding specific classes to the HTML elements and the its UI is multi-language (there are various languages files provided).
 
Source 
 

10. PDF Sketch Sheets for Creating Wireframes

25 个最新的Web应用和工具

Sneakpeekit is a website providing high-quality PDF sketch sheets for web designers. The sheets are compatible with the most popular grid systems like Less Framework 4, 978 grid system, 1140 css grid, The Semantic grid system, Bootstrap from Twitter, etc. And, they are not only for the desktop browsers but there are versions for tablets and mobile as well.
 
Source 
 

11. MobileCartly : Open Source Mobile E-Commerce App

25 个最新的Web应用和工具

MobileCartly is an open source shopping cart application that focuses on mobile. With a front-end that is compatible with all major mobile browsers and a powerful back-end, it makes selling via mobile pretty easy. It uses a CSV file as the data source and you can use Open Office, Google Docs or MS Excel to add/edit/remove your products. There are features like PayPal integration, order management, stats and invoicing. It also has a WordPress plugin that can integrate your blog with the mobile store.
 
Source 
 

12. Speakker

25 个最新的Web应用和工具

Speakker is a Crossbrowser Audio solution featuring HTML5. It comes out of the box in two variations and with incredible options of customization: Flexible dimensions, unlimited colors and two different button sets for light and dark themes. Easy to set up. Just a few lines of Javascript and a quantum CSS.
 
Source 
 

13. Derby MVC Framework

25 个最新的Web应用和工具

The Derby MVC framework makes it easy to write realtime, collaborative applications that run in both Node.js and browsers.Derby includes a powerful data synchronization engine called Racer that automatically syncs data among browsers, servers, and a database.

Models subscribe to changes on specific objects, enabling granular control of data propagation without defining channels. Racer supports offline usage and conflict resolution out of the box, which greatly simplifies writing multi-user applications.
 
Source 
 

14. Express : Robust Node.js Web Application Framework

25 个最新的Web应用和工具
Express is a minimal and flexible node.js web application framework, providing a robust set of features for building single and multi-page, and hybrid web applications. With a myriad of HTTP utility methods and Connect middleware at your disposal, creating a robust user-friendly API is quick and easy.
 
Source 
 

15. Stictches : A Handy HTML5 Sprite Sheet Generator

25 个最新的Web应用和工具

Stitches is an HTML5 sprite sheet generator. Simple drag and drop image files into the space below and click “Generate” to create a sprite sheet and stylesheet. Stitches uses a couple of HTML5 APIs, and it is only currently compatible with the latest versions of Chrome and Firefox. However, it does not work on IE9. It required jQuery 1.7.1+, Modernizr, Dropfile, Flashcanvas for older browser support. It is licensed under MIT License.
 
Source 
 

16. Cage : A Pretty Slick Online Collaboration Tool

25 个最新的Web应用和工具

Cage is a an online collaboration tool that makes it shockingly simple for designers and teams to share, organize, manage, and approve creative work. Using Cage, you can add simple, straightforward notes & conversations directly on the work, and then show your clients past revisions so they can see the progress you have made.

Cage provides your clients and team the ability to approve work faster. It is useful for any type of designer, artist or creative team without a lot of clutter. Leaving out vital features for the sake of simplicity leads to workarounds, and that doesn’t work for anyone. It makes it easy for creatives to present, manage and secure approvals on their work.
 
Source 
 

17. Jam : A JavaScript Package Manager for Front End Developers

25 个最新的Web应用和工具

Jam is a package manager for JavaScript. Unlike other repositories, they put the browser first. Using a stack of script tags isn’t the most maintainable way of managing dependencies, with Jam packages and loaders like RequireJS you get automatic dependency resolution.

You can achieve faster load times with asynchronous loading and the ability to optimize downloads. JavaScript modules and packages provide properly namespaced and more modular code. Every package work in the browser and play nicely with module loaders like RequireJS. They’re not hijacking an existing repository, they’re creating a 100% browser-focused community.
 
Source 
 

18. FileDrop : Cross-Browser Drag n Drop File Uploader

25 个最新的Web应用和工具
FileDrop is a JavaScript class for quickly creating drag ‘n’ drop file upload interfaces. The class doesn’t require any JavaScript frameworks and works cross-browser, including IE6 (with iFrame fallback).

It has support for multiple file uploads, there are callbacks on many events and any number of FileDrop uploaders can be used in the same page. Also, the size of the class is lightweight (3.5 gzipped) and its API is well-documented.
 
Source 
 

19. DbNinja

25 个最新的Web应用和工具

DbNinja is an advanced web-based application for MySQL database administration and development. It’s a must-have for those who wish to access their hosted servers remotely. DbNinja supports all the latest features including: triggers, events, views, stored routines and foreign keys; in addition it allows to import and backup data and MySQL object structures, manage users and much more. DbNinja has a highly functional and elegant user interface, and can be used securely in any modern browser on any OS.
 
Source 
 

20. CSSComb : Sort CSS Properties in a Given Order

25 个最新的Web应用和工具

CSScomb, a free service sorts CSS properties in any order you want (and, their default order is pretty good too -from the most to least important-). It works with both single + multi-line CSS code and besides the online version, there are add-ons provided for the most popular IDEs.
 
Source 
 

21. EpicEditor : An Embeddable JavaScript Editor

25 个最新的Web应用和工具

EpicEditor is an embeddable JavaScript Markdown editor with split fullscreen editing, live previewing, automatic draft saving, offline support, and more. For developers, it offers a robust API, can be easily themed, and allows you to swap out the bundled Markdown parser with anything you throw at it.

EpicEditor is set up to allow you to use any parser that accepts and returns a string. This means you can use any flavor of Markdown, process Textile, or even create a simple HTML editor/previewer. Theming is easy in EpicEditor as well.
 
Source 
 

22. Moqups

25 个最新的Web应用和工具

Moqups is a nifty HTML5 App used to create wireframes, mockups or UI concepts, prototypes depending on how you like to call them. They’ve tried to make things simple and fairly intuitive so you can unleash your creativity without any obstacles. Moqups is built on open standards, striving to provide the best experience within the browser, without compromise.
 
Source 
 

23. AuthManager : Open Source PHP User Authentication & Management App

25 个最新的Web应用和工具

It is an open source user management and authentication system built with PHP. AuthManager comes with a ready-to-use registration module where users can register with their e-mails or Facebook accounts, sign-in and get a new password if they forgot it. Besides the front-end, AuthManager has a powerful back-end which integrates with Google Analytics, shows the logs of user activities, displays members for editing/deleting and presents various settings for customization.
 
Source 
 

24. Foundation 3

25 个最新的Web应用和工具

Foundation 3 is built on ZURB’s 14 years of experience at building sites and apps for the Web. It is built with Sass, a powerful CSS preprocessor, which allows us to much more quickly develop Foundation itself, as well as sites built with it. You can use the Sass or straight CSS version of Foundation.
 
Source 
 

25. Prism : Light Weight Syntax Highlighter

25 个最新的Web应用和工具

Prism is lightweight (1.5KB minified & gzipped), can be integrated so easily (just insert a CSS and JS file) and works fast. It is already used to beautify lots of code in Dabblet (an interactive CSS playground) so its pretty stable. New languages can be added and the functionality can be improved with the plug-in architecture and the look/feel can be completely styled via CSS. 
  
Source 
posted @ 2012-11-07 11:03 小马歌 阅读(371) | 评论 (0)编辑 收藏
 

1. Ninja - HTML5 设计工具

  Ninja 是全功能的 HTML5 Web 设计工具。目前 Ninja 支持可视化地设计和制作HTML5动画,并完全支持CSS 3D效果。

2. jsPDF - 用 JS 生成 PDF

  jsPDF 是一个免费的 JavaScript 类库,可以用来创建 PDF 文件,不需要服务器端支持。它支持文本(含格式),画图和图片。

3. This is Responsive

  This Is Responsive 是一个令人惊叹的,必须收藏的资源。它提供了各种响应式的布局,表格,导航等等。它也提供了分好类的响应式相关的资源连接。

4. Infinity.js : 快速滚动长列表

  Infinity.js 是一个 Web 上的 UITableView。它可以快速在无限长的列表中平滑滚动。这个库很小并且经过充分的测试,性能很好。

5. Reveal.js - HTML 幻灯片工具

  这是一个基于CSS的3D幻灯片工具。它不依赖任何外部类库。

6. OpenKeyval - 在线 Key/Value 存储

  OpenKeyval 可以让你方便的存取数据。它通过 JSON 格式的 API 操作。

7. PHP The Right Way - 免费 PHP 文档

  “PHP: The Right Way”是一个非常详细的文档,描述了 PHP 的最佳实践,帮助任何人编写更好的代码。

8. Site Cake : 为中小网站而建的开源 CMS

  SiteCake 是一个开源的 PHP CMS,支持实时编辑功能。一旦登陆,所有的元素都成了可编辑状态。有一个编辑的工具条可以实时的编辑网页。

9. PDF Sketch Sheets for Creating Wireframes

  这是为网页设计师准备的高质量的草稿纸,PDF格式。兼容各种表格格式,包括 Less Framework 4, 978 grid system, 1140 css grid, The Semantic grid system, Bootstrap from Twitter 等等。

10. MobileCartly : 开源移动电商应用

  MobileCartly 是一个开源的购物车应用,专注移动设备。它的前端兼容绝大多数的移动浏览器。它拥有一个强大的后端,让销售变的容易。它支持 CSV 文件作为数据源,提供产品数据,支持 PayPal 集成,订单处理等等。它也有一个 WordPress 插件可以整合你的博客和移动商店。

英文来源:new-tools-and-applications-for-developers

 
QQ交流群 => WEB开发者总群:241336767 
验证消息:Admin10000
posted @ 2012-11-07 10:09 小马歌 阅读(191) | 评论 (0)编辑 收藏
 

动态应用,是相对于网站静态内容而言, 是指以c/c++、php、Java、perl、.net等 服务器端语言开发的网络应用软件,比如论坛、网络相册、交友、BLOG等常见应用。动态应用系统通 常与数据库系统、缓存系统、分布式存储系统等密不可分。

  大型动态应用系统平台主要是针对于大流 量、高并发网站建立的底层系统架构。大型网站的运行需要一个可靠、安全、可扩展、易维护的应用系统平台做为支撑,以保证网站应用的平稳运行。

  大型动态应用系统又可分为几个子系统:

  l Web前 端系统

  l 负 载均衡系统

  l 数 据库集群系统

  l 缓 存系统

  l 分 布式存储系统

  l 分 布式服务器管理系统

  l 代 码分发系统

  Web前端系统

  结构图:

  为了达到不同应用的服务器共享、避免单点故障、集中管理、统一配置等目的,不以应用划分服 务器,而是将所有服务器做统一使用,每台服务器都可以对多个应用提供服务,当某些应用访问量升高时,通过增加服务器节点达到整个服务器集群的性能提高,同 时使他应用也会受益。该Web前端系统基于Apache/Lighttpd/Eginx等 的虚拟主机平台,提供PHP程序运行环境。服务器对开发人员是透明的,不需要开发人员介入服务器管理

  负载均衡系统

  负载均衡系统分为硬件和软件两种。硬件负载均衡效率高,但是价格贵,比如F5等。软件负载均衡系统价格较低或者免费,效率较硬件负载均衡系统 低,不过对于流量一般或稍大些网站来讲也足够使用,比如lvs,nginx。大多数网站都是硬件、软件负载均衡系统并用。

  数据库集群系统

  结构图:

  由于Web前端采用了负载均衡集群结构提高了服务的有效性和扩展性,因此数据库必须也是高可靠的才能保证整个服务体系的高可靠性,如何构建一个高可靠的、可以提供大规模并发处理的数据库体系?

  我们可以采用如上图所示的方案:

  1) 使用 MySQL 数据库,考虑到Web应用的数据库读多写少的特点,我们主要对读数据库做了优化,提供专用的读数据库和写数据库,在应用程序中实现读操作和写操作分别访问不同的数据库。

  2) 使用 MySQL Replication 机制实现快速将主库(写库)的数据库复制到从库(读库)。一个主库对应多个从库,主库数据实时同步到从库。

  3) 写数据库有多台,每台都可以提供多个应用共同使用,这样可以解决写库的性能瓶颈问题和单点故障问题。

  4) 读数据库有多台,通过负载均衡设备实现负载均衡,从而达到读数据库的高性能、高可靠和高可扩展性。

  5) 数据库服务器和应用服务器分离。

  6) 从数据库使用BigIP做负载均衡。

  缓存系统

  缓存分为文件缓存、内存缓存、数据库缓存。在大型Web应用中使用最多且效率最高的是内存缓存。最常用的内存缓存工具是Memcachd。使用正确的缓存系统可以达到实现以下目标:

  1、 使用缓存系统可以提高访问效率,提高服务器吞吐能力,改善用户体验。

  2、 减轻对数据库及存储集服务器的访问压力

  3、Memcached服务器有多台,避免单点故障,提供高可靠性和可扩展性,提高性能。

  分布式存储系统

  结构图:

  WEB系统平台中的存储需求有下面两个特点:

  1) 存储量很大,经常会达到单台服务器无法提供的规模,比如相册、视频等应用。因此需要专业的大规模存储系统。

  2) 负载均衡cluster中的每个节点都有可能访问任何一个数据对象,每个节点对数据的处理也能被其他节点共享,因此这些节点要操作的数据从逻辑上看只能是一个整体,不是各自独立的数据资源。

  因此高性能的分布式存储系统对于大型网站应用来说是非常重要的一环。(这个地方需要加入对某个分布式存储系统的简单介绍。)

  分布式服务器管理系统

  结构图:

  随着网站访问流量的不断增加,大多的网络服务都是以负载均衡集群的方式对外提供服务,随之集群规模的扩大,原来基于单机的服务器管理模式已经不能够满足我们的需求,新的需求必须能够集中式的、分组的、批量的、自动化的对服务器进行管理,能够批量化的执行计划任务。

  在分布式服务器管理系统软件中有一些比较优秀的软件,其中比较理想的一个是 Cfengine。它可以对服务器进行分组,不同的分组可以分别定制系统配置文件、计划任务等配置。它是基于C/S 结构的,所有的服务器配置和管理脚本程序都保存在Cfengine Server上,而被管理的服务器运行着 Cfengine Client 程序,Cfengine Client通过SSL加密的连接定期的向服务器端发送请求以获取最新的配置文件和管理命令、脚本程序、补丁安装等任务。

  有了Cfengine 这种集中式的服务器管理工具,我们就可以高效的实现大规模的服务器集群管理,被管理服务器和 Cfengine Server 可以分布在任何位置,只要网络可以连通就能实现快速自动化的管理。

  代码发布系统

  结构图: 

  随着网站访问流量的不断增加,大多的网络服务都是以负载均衡集群的方式对外提供服务,随之集群规模的扩大,为了满足集群环境下程序代码的批量分发和更新,我们还需要一个程序代码发布系统。

  这个发布系统可以帮我们实现下面的目标:

  1) 生产环境的服务器以虚拟主机方式提供服务,不需要开发人员介入维护和直接操作,提供发布系统可以实现不需要登陆服务器就能把程序分发到目标服务器。

  2) 我们要实现内部开发、内部测试、生产环境测试、生产环境发布的4个开发阶段的管理,发布系统可以介入各个阶段的代码发布。

  3) 我们需要实现源代码管理和版本控制,SVN可以实现该需求。

  这里面可以使用常用的工具Rsync,通过开发相应的脚本工具实现服务器集群间代码同步分发。

posted @ 2012-11-05 15:25 小马歌 阅读(368) | 评论 (0)编辑 收藏
 
from:http://www.thegeekstuff.com/2011/11/valgrind-memcheck/


One major aspect of system programming is to handle memory related issues effectively. The more you work close to the system, the more memory related issues you need to face.

Sometimes these issues are very trivial while many times it becomes a nightmare to debug memory related issues. So, as a practice many tools are used for debugging memory related issues.

In this article, we will discuss the most popular open source memory management framework VALGRIND.

From Valgrind.org :

Valgrind is an instrumentation framework for building dynamic analysis tools. It comes with a set of tools each of which performs some kind of debugging, profiling, or similar task that helps you improve your programs. Valgrind’s architecture is modular, so new tools can be created easily and without disturbing the existing structure.

A number of useful tools are supplied as standard.

  1. Memcheck is a memory error detector. It helps you make your programs, particularly those written in C and C++, more correct.
  2. Cachegrind is a cache and branch-prediction profiler. It helps you make your programs run faster.
  3. Callgrind is a call-graph generating cache profiler. It has some overlap with Cachegrind, but also gathers some information that Cachegrind does not.
  4. Helgrind is a thread error detector. It helps you make your multi-threaded programs more correct.
  5. DRD is also a thread error detector. It is similar to Helgrind but uses different analysis techniques and so may find different problems.
  6. Massif is a heap profiler. It helps you make your programs use less memory.
  7. DHAT is a different kind of heap profiler. It helps you understand issues of block lifetimes, block utilisation, and layout inefficiencies.
  8. SGcheck is an experimental tool that can detect overruns of stack and global arrays. Its functionality is complementary to that of Memcheck: SGcheck finds problems that Memcheck can’t, and vice versa..
  9. BBV is an experimental SimPoint basic block vector generator. It is useful to people doing computer architecture research and development.

There are also a couple of minor tools that aren’t useful to most users: Lackey is an example tool that illustrates some instrumentation basics; and Nulgrind is the minimal Valgrind tool that does no analysis or instrumentation, and is only useful for testing purposes.

Here in this article we will focus on the tool ‘memcheck’.

Using Valgrind Memcheck

The memcheck tool is used as follows :

valgrind --tool=memcheck ./a.out

As clear from the command above, the main binary is ‘Valgrind’ and the tool which we want to use is specified by the option ‘–tool’. The ‘a.out’ above signifies the executable over which we want to run memcheck.

This tool can detect the following memory related problems :

  • Use of uninitialized memory
  • Reading/writing memory after it has been freed
  • Reading/writing off the end of malloc’d blocks
  • Memory leaks
  • Mismatched use of malloc/new/new[] vs free/delete/delete[]
  • Doubly freed memory

Note : The above list is not exhaustive but contains the popular problems detected by this tool.

Lets discuss the above scenarios one by one:

Note : All the test code described below should be compiled using gcc with -g option(to generate line numbers in memcheck output) enabled. As we discussed earlier for a C program to get compiled into an executable, it has to go through 4 different stages.

1. Use of uninitialized memory

Code :

#include <stdio.h> #include <stdlib.h>   int main(void) {     char *p;       char c = *p;       printf("\n [%c]\n",c);       return 0; }

In the above code, we try to use an uninitialized pointer ‘p’.

Lets run memcheck and see the result.

$ valgrind --tool=memcheck ./val ==2862== Memcheck, a memory error detector ==2862== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==2862== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info ==2862== Command: ./val ==2862== ==2862== Use of uninitialised value of size 8 ==2862==    at 0x400530: main (valgrind.c:8) ==2862==  [#] ==2862== ==2862== HEAP SUMMARY: ==2862==     in use at exit: 0 bytes in 0 blocks ==2862==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==2862== ==2862== All heap blocks were freed -- no leaks are possible ==2862== ==2862== For counts of detected and suppressed errors, rerun with: -v ==2862== Use --track-origins=yes to see where uninitialized values come from ==2862== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)

As seen from the output above, Valgrind detects the uninitialized variable and gives a warning(see the lines in bold above).

2. Reading/writing memory after it has been freed

Code :

#include <stdio.h> #include <stdlib.h>   int main(void) {     char *p = malloc(1);     *p = 'a';       char c = *p;       printf("\n [%c]\n",c);       free(p);     c = *p;     return 0; }

In the above piece of code, we have freed a pointer ‘p’ and then again we have tried to access the value help by the pointer.

Lets run memcheck and see what Valgrind has to offer for this scenario.

$ valgrind --tool=memcheck ./val ==2849== Memcheck, a memory error detector ==2849== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==2849== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info ==2849== Command: ./val ==2849==    [a] ==2849== Invalid read of size 1 ==2849==    at 0x400603: main (valgrind.c:30) ==2849==  Address 0x51b0040 is 0 bytes inside a block of size 1 free'd ==2849==    at 0x4C270BD: free (vg_replace_malloc.c:366) ==2849==    by 0x4005FE: main (valgrind.c:29) ==2849== ==2849== ==2849== HEAP SUMMARY: ==2849==     in use at exit: 0 bytes in 0 blocks ==2849==   total heap usage: 1 allocs, 1 frees, 1 bytes allocated ==2849== ==2849== All heap blocks were freed -- no leaks are possible ==2849== ==2849== For counts of detected and suppressed errors, rerun with: -v ==2849== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)

As seen in the output above, the tool detects the invalid read and prints the warning ‘Invalid read of size 1′.

On a side note, to debug a c program use gdb.

3. Reading/writing off the end of malloc’d blocks

Code :

#include <stdio.h> #include <stdlib.h>   int main(void) {     char *p = malloc(1);     *p = 'a';       char c = *(p+1);       printf("\n [%c]\n",c);       free(p);     return 0; }

In the above piece of code, we have allocated 1 byte for ‘p’ but we access the the address p+1 while reading the value into ‘c’.

Now we run Valgrind on this piece of code :

$ valgrind --tool=memcheck ./val ==2835== Memcheck, a memory error detector ==2835== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==2835== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info ==2835== Command: ./val ==2835== ==2835== Invalid read of size 1 ==2835==    at 0x4005D9: main (valgrind.c:25) ==2835==  Address 0x51b0041 is 0 bytes after a block of size 1 alloc'd ==2835==    at 0x4C274A8: malloc (vg_replace_malloc.c:236) ==2835==    by 0x4005C5: main (valgrind.c:22) ==2835==    [] ==2835== ==2835== HEAP SUMMARY: ==2835==     in use at exit: 0 bytes in 0 blocks ==2835==   total heap usage: 1 allocs, 1 frees, 1 bytes allocated ==2835== ==2835== All heap blocks were freed -- no leaks are possible ==2835== ==2835== For counts of detected and suppressed errors, rerun with: -v ==2835== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)

Again, this tool detects the invalid read done in this case.

4. Memory leaks

Code:

#include <stdio.h> #include <stdlib.h>   int main(void) {     char *p = malloc(1);     *p = 'a';       char c = *p;       printf("\n [%c]\n",c);       return 0; }

In this code, we have malloced one byte but haven’t freed it. Now lets run Valgrind and see what happens :

$ valgrind --tool=memcheck --leak-check=full ./val ==2888== Memcheck, a memory error detector ==2888== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==2888== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info ==2888== Command: ./val ==2888==    [a] ==2888== ==2888== HEAP SUMMARY: ==2888==     in use at exit: 1 bytes in 1 blocks ==2888==   total heap usage: 1 allocs, 0 frees, 1 bytes allocated ==2888== ==2888== 1 bytes in 1 blocks are definitely lost in loss record 1 of 1 ==2888==    at 0x4C274A8: malloc (vg_replace_malloc.c:236) ==2888==    by 0x400575: main (valgrind.c:6) ==2888== ==2888== LEAK SUMMARY: ==2888==    definitely lost: 1 bytes in 1 blocks ==2888==    indirectly lost: 0 bytes in 0 blocks ==2888==      possibly lost: 0 bytes in 0 blocks ==2888==    still reachable: 0 bytes in 0 blocks ==2888==         suppressed: 0 bytes in 0 blocks ==2888== ==2888== For counts of detected and suppressed errors, rerun with: -v ==2888== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)

The lines (in bold above) shows that this tool was able to detect the leaked memory.

Note: In this case we added an extra option ‘–leak-check=full’ to get verbose details of the memory leak.

5. Mismatched use of malloc/new/new[] vs free/delete/delete[]

Code:

#include <stdio.h> #include <stdlib.h> #include<iostream>   int main(void) {     char *p = (char*)malloc(1);     *p = 'a';       char c = *p;       printf("\n [%c]\n",c);     delete p;     return 0; }

In the above code, we have used malloc() to allocate memory but used delete operator to delete the memory.

Note : Use g++ to compile the above code as delete operator was introduced in C++ and to compile c++ code, g++ tool is used.

Lets run this tool and see :

$ valgrind --tool=memcheck --leak-check=full ./val ==2972== Memcheck, a memory error detector ==2972== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==2972== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info ==2972== Command: ./val ==2972==    [a] ==2972== Mismatched free() / delete / delete [] ==2972==    at 0x4C26DCF: operator delete(void*) (vg_replace_malloc.c:387) ==2972==    by 0x40080B: main (valgrind.c:13) ==2972==  Address 0x595e040 is 0 bytes inside a block of size 1 alloc'd ==2972==    at 0x4C274A8: malloc (vg_replace_malloc.c:236) ==2972==    by 0x4007D5: main (valgrind.c:7) ==2972== ==2972== ==2972== HEAP SUMMARY: ==2972==     in use at exit: 0 bytes in 0 blocks ==2972==   total heap usage: 1 allocs, 1 frees, 1 bytes allocated ==2972== ==2972== All heap blocks were freed -- no leaks are possible ==2972== ==2972== For counts of detected and suppressed errors, rerun with: -v ==2972== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)

We see from the output above (see lines in bold), the tool clearly states ‘Mismatched free() / delete / delete []‘

You can try and use the combination ‘new’ and ‘free’ in a test code and see what result this tool gives.

6. Doubly freed memory

Code :

#include <stdio.h> #include <stdlib.h>   int main(void) {     char *p = (char*)malloc(1);     *p = 'a';       char c = *p;     printf("\n [%c]\n",c);     free(p);     free(p);     return 0; }

In the above peice of code, we have freed the memory pointed by ‘p’ twice. Now, lets run the tool memcheck :

$ valgrind --tool=memcheck --leak-check=full ./val ==3167== Memcheck, a memory error detector ==3167== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==3167== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info ==3167== Command: ./val ==3167==    [a] ==3167== Invalid free() / delete / delete[] ==3167==    at 0x4C270BD: free (vg_replace_malloc.c:366) ==3167==    by 0x40060A: main (valgrind.c:12) ==3167==  Address 0x51b0040 is 0 bytes inside a block of size 1 free'd ==3167==    at 0x4C270BD: free (vg_replace_malloc.c:366) ==3167==    by 0x4005FE: main (valgrind.c:11) ==3167== ==3167== ==3167== HEAP SUMMARY: ==3167==     in use at exit: 0 bytes in 0 blocks ==3167==   total heap usage: 1 allocs, 2 frees, 1 bytes allocated ==3167== ==3167== All heap blocks were freed -- no leaks are possible ==3167== ==3167== For counts of detected and suppressed errors, rerun with: -v ==3167== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)

As seen from the output above(lines in bold), the tool detects that we have called free twice on the same pointer.

In this article, we concentrated on memory management framework Valgrind and used the tool memcheck (provided by this framework) to describe how it makes life easy for a developer working close to memory. This tool can detect many memory related problems that are very hard to find manually.

posted @ 2012-11-05 11:22 小马歌 阅读(458) | 评论 (0)编辑 收藏
 
首先确定,在mysql的'plugin_dir'下有ha_innodb_plugin.so和ha_innodb.so两个文件
查询'plugin_dir'的路径可以用以下命令
mysql> show variables like 'plugin_dir';
+---------------+-----------------------------------+
| Variable_name | Value                             |
+---------------+-----------------------------------+
| plugin_dir    | /usr/local/mysql/lib/mysql/plugin |
+---------------+-----------------------------------+
1 row in set (0.01 sec)
如果没有找到,在您的mysql编译目录里有下面的目录文件(内置的innodb和innodb_plugin)
storage/innobase/.libs/ha_innodb.so
storage/innodb_plugin/.libs/ha_innodb_plugin.so
您需要把它们(ha_innodb_plugin.so和ha_innodb.so)拷贝到mysql的plugin目录中(/usr/local/mysql/lib/mysql/plugin)
接下来就是在mysql命令行安装一下
# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 5.1.36-log Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show engines;
+------------+---------+-----------------------------------------------------------+--------------+------+------------+
| Engine     | Support | Comment                                                   | Transactions | XA   | Savepoints |
+------------+---------+-----------------------------------------------------------+--------------+------+------------+
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                     | NO           | NO   | NO         |
| CSV        | YES     | CSV storage engine                                        | NO           | NO   | NO         |
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables | NO           | NO   | NO         |
| MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance    | NO           | NO   | NO         |
+------------+---------+-----------------------------------------------------------+--------------+------+------------+
4 rows in set (0.00 sec)
mysql> INSTALL PLUGIN InnoDB SONAME 'ha_innodb.so';
Query OK, 0 rows affected (0.69 sec)
mysql> show engines;
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine     | Support | Comment                                                    | Transactions | XA   | Savepoints |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| InnoDB     | YES     | Supports transactions, row-level locking, and foreign keys | YES          | YES  | YES        |
| CSV        | YES     | CSV storage engine                                         | NO           | NO   | NO         |
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                      | NO           | NO   | NO         |
| MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance     | NO           | NO   | NO         |
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables  | NO           | NO   | NO         |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
5 rows in set (0.00 sec)

OK,大功告成
posted @ 2012-10-29 12:28 小马歌 阅读(1450) | 评论 (0)编辑 收藏
 

12306 订票助手 – 火车票自动订票 Chrome 扩展

54
8 votes
 on 2012.01.10标签: .

12306 订票助手 是款 Chrome 扩展,用来对 12306.cn 网址进行自动登录,自动查询,自动重试订单。@Appinn

12306 订票助手   火车票自动订票 Chrome 扩展[图] | 小众软件

火车票四连发么,好久没发现程序员如此热情了…

这款工具就比较适合彻底的技术宅了,希望今天介绍还不算太晚,根据订票 12 天来看,目前(1月10日)已经可以订到1月21日的票了,距离春节仅一天,基本上是放假的开始的最后日子了。

12306 订票助手 使用前提:须使用 Chrome 浏览器,以及安装 UserScript,然后打开 https://dynamic.12306.cn/otsweb/ 开始订票。

上图尝试登陆78次后成功,而下图则开始刷票…

12306 订票助手   火车票自动订票 Chrome 扩展[图] | 小众软件

刷票成功会蓝色通知以及声音提示,此时点击预订按钮,就可以进入自动提交订单页面,请注意正确填写实名制火车票坐车人信息,自动提及后就直接到付款阶段,无确认选项。作者提供了详尽的步骤说明可以参考。

12306 订票助手   火车票自动订票 Chrome 扩展[图] | 小众软件 https://github.com/zzdhidden/12306 
posted @ 2012-09-18 18:42 小马歌 阅读(405) | 评论 (0)编辑 收藏
 

 使用Chrome浏览器的同学应该会经常看到一些网站的搜索框右边有一个麦克风的标志,点击图标后即可连接麦克风进行语音识别搜索,那么这是如何实现的呢?

淘宝网上的语音搜索功能

其实非常简单,这是html5下一个新的属性,通过调用google的语音服务api,用于支持网页内的语音识别输入功能。

只需要在输入框的input上添加一个x-webkit-speech 属性就可以了。

如本博客的搜索框:

<input type="text"  name="edtSearch" x-webkit-speech id="edtSearch" value="Search...." onfocus="if (this.value == 'Search....') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search....';}" />

另外它还可以添加以下属性:

语言种类: lang="zh-CN"

发声改变时触发相关语音识别:onwebkitspeechchange="foo()"

让语音输入的内容更加精确尽量接近搜索内容:x-webkit-grammar="bUIltin:search"

通过平时的使用感觉如果发音清晰的话,识别率还算不错。这是google应用于Chrome浏览器上的一项实验性功能,以上属性同样也对webkit内核浏览器生效。

相关W3C标准参考文档:http://lists.w3.org/Archives/Public/public-xg-htmlspeech/2011Feb/att-0020/api-draft.html

posted @ 2012-09-03 10:24 小马歌 阅读(406) | 评论 (0)编辑 收藏
 

在寻找插件开发资料的过程中找到了一个开发浏览器插件的开源项目——firebreath。参考:firebreath主页。根据其介绍可以实现各种浏览器插件的开发。于是我进行了尝试,并试图搜索利用firebreath开发插件的中文资料。搜索到的相关中文资料有一个:徐凡的博客。其中有使用firebreath开发浏览器插件(一、二、三)三篇关于firebreath开发插件的文章。看完了,但是还是不怎么会。

经过两周的摸索,基本上掌握了用firebreath开发插件的初步流程,但是没法熟练运用。主要根据firebreath上的getting started进行,这里记录一下用firebreath开发插件的基本流程(开发环境我用的是VS2010中文旗舰版)。

准备工作

要使用firebreath来开发插件,需要下载以下东西:firebreath的源代码、python、CMake。安装python(可以是2.5 2.6 2.7版本,我下载的是2.7版本),注意python最好安装在firebreath的工程目录中。安装CMake(我下载的最新版本),注意安装过程中请选择添加到环境变量。Firebreath源代码可以在github上签出(需要安装git bash),也可以直接下载压缩包文件,我直接下载zip程序包,firebreath 1.6 zip包下载地址
下面是详细步骤,将源代码下载下来之后解压到:D:\Users\zcf\Documents\My Program\2012\FireBreath\中。我将python安装在D:\Users\zcf\Documents\My Program\2012\FireBreath\Python27\注意即使不安装在firebreath目录也 不要安装在目录路径有特殊字符(特别是空格)的路径下,与firebreath文件夹的相对路径没有空格也行。

创建新的plugin

运行cmd(win7请以管理员身份运行)。
转到firebreath的根目录下:
cd /d D:\Users\zcf\Documents\My Program\2012\FireBreath
运行fbgen.py
Python27\python.exe fbgen.py
运行到此截图:

输入需要输入的东西
 

完成之后在firebreath根目录下会产生一个projects文件夹,里面就是刚刚建立的工程的源文件了。这些文件在firebreath的网站上有详细介绍,看得很模糊,我就不罗嗦了,需要看的自己去看原文说明吧。

创建工程

还是在刚才那个cmd窗口中运行prep2010.cmd,如下图:

我使用VS2010来开发,因此运行prep2010.cmd、如果你使用其他版本请使用相应的prep文件。另外,如果需要创建给出的两个例子,则可以运行prep2010.cmd examples。

运行完毕就创建好工程了,在firebreath根目录下的build文件夹下面会生成很多文件,其中有一个FireBreath.sln就是我们熟悉的VS解决方案文件了。双击这个文件就可以用VS打开这个解决方案了。如下图:

最后一个项目就是我们建立的项目,其他的是自己生成的。当我们新建第二个plugin时就会在这个之后再添加一个项目吧!(不过我还没试过)。
 
接下来就在VS中生成解决方案。整个过程完成之后就会在~FireBreath\build\bin\demo\Debug\下面找到npdemo.dll,这就是我们生成的plugin了。在~FireBreath\build\projects\demo\gen\目录下可以找到FBControl.htm文件,这个文件就是我们这个plugin的测试页面了,当然你也可以自己编写测试页面。
将产生的npdemo.dll复制到用来测试的Firefox profile文件中plugins目录(没有的话自己新建吧)下,然后用这个profile运行Firefox,打开FBControl.htm文件。如下图:(也可以采用其他方式注册plugin,请参考相关资料)

点击确定之后:
 

这样这个plugin就创建完毕了,还没看明白呢,就结束了?太快了吧。。。
 
我刚开始建立完就是这个感觉:我可以创建plugin了,可是我感觉我又什么都不会。一般的有关创建plugin的说明都是到这个地方就结束了,给我的感觉就是还没开始就结束了。。。

实现一个简单的功能

其实上面这个例子已经实现了很多比较实用的功能了,可是我比较菜,只能看懂一小部分。我想实现一个用鼠标在plugin窗口上画线的功能。经过摸索,终于可以实现我想实现的这个功能了。下面是我的步骤:
看程序的过程中我发现已经实现了鼠标按下,抬起,移动等事件的函数,但是函数体只有一个return语句,下图是所有已经实现的函数:

看到这些函数,我想画线的函数就可以利用这三个鼠标事件来来完成吧。于是我做了如下工作。
 
1,定义几个私有成员变量(demo.h文件中):

2,在构造函数中初始化一下(demo.cpp文件中):
 

3,先写onMouseDown和onMouseUp两个函数中的代码(作用:修改鼠标是否按下的状态)。如下图,框住的是添加的内容:
 

4,再来写鼠标移动时实现的功能,首先获取鼠标指针所在的点,与前面一样:m_mousePosXnew=evt->m_x; m_mousePosYnew=evt->m_y;就搞定了;然后就是画线的功能了(如果你对windows编程很熟悉就直接看后面的程序截图吧,因为我不熟悉,所以我将这个过程描述得详细一点,请理解),从old 的点画到new这个点。我虽然对windows程序开发不是很熟练,但是还是知道有个LineTo的函数,因此先就假设是LineTo(old,new)吧。于是就接下来写:

if (b_isDown)
{
LineTo(old, new);
}
最后,将new这一点保存为old的点: 
m_mousePosXold= m_mousePosXnew; m_mousePosYold= m_mousePosYnew;
所以这里就剩下搞清楚 LineTo这个函数了,要实现从一个点画线到另一个点在windows中其实是这样实现的:
HDC hDC;
hDC=GetDC(hWnd);
MoveToEx(hDC,m_mousePosXold,m_mousePosYold,NULL);
LineTo(hDC,m_mousePosXnew,m_mousePosYnew);
ReleaseDC(hWnd,hDC);
上面这样实现了,要使用HDC以及MoveToEx和LineTo需要包含头文件PluginWindowWin.h。还差个HWND,如何得到这个HWND,我也说不清楚,我是看到例子FBTestPlugin中的代码才知道可以这样获取的:FB::PluginWindowWin *wnd = dynamic_cast<FB::PluginWindowWin*>(win); HWND hWnd=wnd->getHWND();下面是FBTestPlugin 的FBTestPlugin.cpp文件中的代码片段截图:

经过尝试,终于完成了我想要实现的这个简单功能,再次感慨一下开发plugin对windows编程的基础能力还是有相当需求的。下面是完整的onMouseMove函数代码截图,框住的是添加的内容(注意在文件最前面添加头文件的引用#include "PluginWindowWin.h"):


做完这些修改之后,在demo这个项目上选择仅用于项目->仅重新生成demo。等生成完毕之后,去前面的位置找到npdemo.dll复制到Firefox相应profile下的plugins目录,重新启动Firefox,打开那个测试页面。

下面是运行效果,请忍受我的涂鸦,\(^o^)/~

差不多了吧,这个简单的功能就这样了。或许再添加一个鼠标移出区域的事件,在其中将鼠标按下状态设为false会更好。
 
我做插件的目的是要播放浏览器不支持的媒体文件,我会继续慢慢研究,希望研究插件开发的能一起共同交流,交流群:81424441。
 

http://www.firebreath.org/display/documentation/FireBreath+Home 

posted @ 2012-08-28 13:11 小马歌 阅读(7498) | 评论 (0)编辑 收藏
仅列出标题
共95页: First 上一页 32 33 34 35 36 37 38 39 40 下一页 Last