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 小馬歌 閱讀(790) | 評論 (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 小馬歌 閱讀(373) | 評論 (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 小馬歌 閱讀(377) | 評論 (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 小馬歌 閱讀(200) | 評論 (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 小馬歌 閱讀(385) | 評論 (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 小馬歌 閱讀(468) | 評論 (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 小馬歌 閱讀(1457) | 評論 (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 小馬歌 閱讀(417) | 評論 (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 小馬歌 閱讀(434) | 評論 (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 小馬歌 閱讀(7524) | 評論 (0)編輯 收藏
          僅列出標題
          共95頁: First 上一頁 32 33 34 35 36 37 38 39 40 下一頁 Last 
           
          主站蜘蛛池模板: 吐鲁番市| 吉木乃县| 泊头市| 保亭| 叙永县| 繁昌县| 昭通市| 始兴县| 海城市| 夏邑县| 玉树县| 米泉市| 元氏县| 轮台县| 泾阳县| 河源市| 淅川县| 汉中市| 长武县| 社旗县| 翁牛特旗| 山阴县| 资中县| 桐城市| 达孜县| 黄山市| 佛坪县| 江西省| 银川市| 四平市| 洞口县| 高平市| 浦东新区| 理塘县| 黄陵县| 合作市| 长子县| 常州市| 方正县| 泊头市| 涿州市|