Become a Vi Master by Learning These 30+ Key Bindings

Posted by Unknown Rabu, 06 Juni 2012 0 komentar
http://www.howtogeek.com/115051/become-a-vi-master-by-learning-these-30-key-bindings


Vi is a powerful text editor included on most Linux systems. Many people swear by vi and find it faster than any other editor once they’ve learned its key bindings. You can even use vi key bindings in Bash.
We’ve already covered getting started with vi for beginners. If you haven’t used vi in a while, you might want to give that post a look to get a refresher on the basics.

Mode Switching

As a short recap, vi is a modal editor – there’s an insert mode and a standard command mode. In insert mode, vi functions similar to a normal text editor. In command mode, you take advantage of these key bindings.
  • i – Enter insert mode.
  • Escape – Leave insert mode. If you’re already in command mode, Escape does nothing, so you can press Escape to ensure you’re in command mode.

Moving the Cursor

Vi uses the hjkl keys to move the cursor in command mode. Early computer systems didn’t always have arrow keys, so these keys were used instead. One advantage of these keyboard shortcuts is that you don’t have to move your fingers from the home row to use them.
  • h – Move cursor left.
  • j – Move cursor down.
  • k – Move cursor up.
  • l – Move cursor right.
You can also use search commands to quickly move the cursor.
  • / – Type a / followed by some text you want to find and press Enter to quickly move your cursor to the location of the text in the file. For example, if you have the word iguana in your file, type /iguana and press Enter to quickly move the cursor there.
  • ? – Like /, but searches backwards.
  • f – Type an f followed by any character to quickly move the cursor to the next occurrence of the character on the current line. For example, if you have the line “Hello world” on a line and your cursor is at the beginning of the line, type fo to move to the o in Hello. Type fo again to move to the o in world.
  • F – Like f, but searches backwards.
  • % – Jump between the nearest (), [], or {} characters on the line.
Use these commands to quickly move to locations in the file:
  • H – Move cursor to highest (top) line in file.
  • M – Move cursor to middle line in file.
  • L – Move cursor to lowest (bottom) line in file.
  • #G – Type a number and then type G to go to that line in the file. For example, type 4G and press Enter to move to the fourth line in the file.
Moving between words:
  • w – Move forward a word.
  • #w – Move forward a number of words. For example, 2w moves forward two words.
  • b – Move back a word.
  • #b – Move back a number of words. For example, 3b moves back three words.
  • e – Move to end of the current word.

Copying & Pasting

Vi refers to the act of copying as “yanking.”
  • v – Press v and move the cursor to select a section of text.
  • y – Copy (yank) the selected text.
  • p – Paste at cursor.
  • x – Cuts the selected text. Cuts the character under the cursor if no text is selected
  • r – Type r and then type another character to replace the character under the cursor.

Combining Commands

Some commands – including the y and v commands above and the d (delete) command accept cursor motion commands.
For example, when you press d to delete some text, nothing will happen until you enter a cursor motion command. For example:
  • dw – Deletes the next word.
  • db – Deletes the previous word
  • de – Deletes to the end of the current word.
  • dL – Deletes all text below the cursor in the file.
  • d/unicorn – After pressing Enter, deletes all text between the cursor and the word “unicorn” in the current file.
  • dd – Deletes an entire line.
As you can see, the combination of combining a command with a cursor movement command is very powerful.

Repeat & Undo

Vi’s repeat command is very powerful, as it can repeat complex, combined commands.
  • u – Undo.
  • . – The . repeats the last full command.  The insert command also functions as a command here. For example, type iunicorn and press Escape. You can then use the . key to insert the word unicorn at the cursor.

Bonus: Using Vi Key Bindings in Bash

Once you’ve mastered the vi key bindings, you may want to use them elsewhere on your system. No problem – you can set the Bash shell to use vi-style key bindings.
Try this out in the current session by running the following command in a Bash terminal:
set -o vi
Bash will start in insert mode – press Escape to enter command mode and use these key bindings.
If you like this, you can add the command to your ~/.bashrc file and it will be automatically run each time you log in. Use the vi .bashrc command to open and edit the file in vi.


This isn’t a complete list of key bindings for vi, but it should help you flex your vi wings and learn to fly. This list of key bindings at Harvard’s website is more complete and has more information, although it’s less organized and harder to digest all at once.

Baca Selengkapnya ....

Five Best Android ROMs

Posted by Unknown 0 komentar
http://www.lifehacker.com.au/2012/06/five-best-android-roms



Whether you’re looking to upgrade an Android device forsaken by its manufacturer or you just want more control over the phone or tablet you own, a new ROM is often the way to go. Rooting your phone is the first step, but a new ROM will give you a completely new mobile OS. This week we’re going to look at five of the best Android ROMs.
Photo by Peter Kirn.

It’s important to note that not every ROM is available for every device, and different ROMs are aimed at different audiences — some of them are designed to upgrade the OS, and others are lean and mean installs to speed up your phone. Whichever you choose, you’ll have to make sure your device is supported by the developers behind the ROM before installing.

CyanogenMod

CyanogenMod is arguably one of the most installed Android ROMs in the world. It offers lots of great features, it’s available for more devices than most other ROMs of its type, and it has a level of polish and support that makes it easy to fall in love with.
There are builds of CyanogenMod for Android phones and tablets, and slowly but surely the developers behind CyanogenMod are rolling out Ice Cream Sandwich versions for devices whose manufacturers have given up on upgrading the device entirely. As well, CyanogenMod includes features you won’t find in stock Android, like support for OpenVPN and downloadable themes, plus more privacy tools. You can find a list of supported devices here.

Android Open Kang Project (AOKP)

The Android Open Kang Project (AOKP) is a relative newcomer compared to many of the other popular ROMs already available, but it’s rapidly growing in popularity. It offers many of the features that CyanogenMod does, and at first blush you may mistake one for the other. But as soon as you start looking at the options and add-ons, you’ll see the differences. AOKP has earned high marks for add-ons and tools that you can’t get in CM, centralised control over ROM options and more overall customisation options than CM. At the same time, its development community is smaller, and it may not have the same polish and device support that CyanogenMod has. Still, it’s super-fast, it’s stable and definitely worth a look. You can find a list of all supported devices here.

MIUI

MIUI struck us with how beautiful the user interface was and how elegant it made Android look and feel. It’s not the most feature-packed or hackable ROM, but it’s definitely one of the most customisable and elegant, and it’s seriously fast. MIUI started life as a modded version of Android localised in China, but fans of the mod have since localised it for dozens of languages and countries. It offers strong theme support, beautiful stock apps, customisable lockscreens, support for GApps and complete root access. You’re not going to get a wealth of niche features here, but you will get a device that’s much easier and more fun to use once you install MIUI. You can find a list of supported devices here.

Slim ICS

If you have a Galaxy Nexus, Nexus S, Samsung Galaxy S or Galaxy S II, Slim ICS may be the ROM for you. Not only will Slim ICS bring your device up to Ice Cream Sandwich, it’s also a super-thin, lightweight installation that’s remarkably easy to install, even though it’s clearly aimed at advanced users. Slim ICS already has GApps rolled in, so you don’t need to install those later. Where other ROMs try to add lots of new features and tweaking options, Slim ICS is designed to trim the fat down to the bare essentials and give you a fast and clean ICS installation. It’s only available for a handful of Samsung devices, and there’s pretty much one developer and a few beta testers behind the scenes, so don’t expect too many feature additions or new devices. However, it is updated weekly and sports a good number of third-party mods.

Liquid Smooth ROMS

Liquid Smooth ROMS are available for multiple devices. While the project started off with the Motorola Droid, Droid 2, Droid X, Droid Incredible and HTC Thunderbolt, it’s also available for the Galaxy Nexus and a few other devices, although you’ll have to poke around the forums a bit to find them. The banner feature of Liquid is that it’s probably one of the fastest ICS ROMs available — faster even than the stock install that comes on the Galaxy Nexus. You don’t sacrifice features for the speed, but the overall size of the ROM is still nice and small, leaving more space for the apps and features you choose to use as opposed to ones forced on you. GApps are baked right in, and the ROM offers theme support so you can customise it to your liking. All in all, if you have a supported device, it’s probably the leanest, meanest ICS ROM you can download.
No honourable mentions this week, but there are well over 60 different ROMs out there, so whatever ROM you settle on, make sure it’s a good match for the features you’re looking for, the device you own and the version of Android you want to run. These may be our top five, but they may not be the best for your specific device, so do your homework!
Have something to add? Did your favourite not get included? Share your thoughts in the comments below.

Baca Selengkapnya ....

Fedora 17 – Install Codecs, Drivers and Fonts in under 5 minutes!

Posted by Unknown 0 komentar
http://www.unixmen.com/fedora-17-install-codecs-drivers-and-fonts-in-under-5-minutes


Fedora 17 is a great GNU/Linux distribution, that initially needs some special configuration to fully cover the everyday needs of a desktop user with success. For legal and ideological reasons, people behind Fedora decide that their creation should not support the out of the box playback of mp3, movies etc. Moreover, Fedora doesn’t officially offer an easy to use tool for the user to download the needed packages like other distributions like Ubuntu and Linux Mint do. In this article we will see how to download and install all the “extras”, easily and fast.

Applications and Codecs

What you will need first of all, is to download an application called Autoplus. You won’t find it in the official repositories, but you can download and install Autoplus by using the following command:
su -c 'yum -y --nogpgcheck install http://dnmouse.org/autoplus-1.4-5.noarch.rpm'
This should install Autoplus in your system. If not, you can build it from source.
Now run Autoplus (Activities/Applications/System Tools) and you will see that everything you need is just two clicks away!
Autoplus offers to automatically download and install the codecs needed to playback multimedia files like mp3, plugins needed for optimum internet experience like Adobe Flash, applications that are not present on the default repos like Google Earth and even configure sudo usage for current user.

Graphics Driver

After you successfully installed everything using Autoplus, you can proceed with installing the proprietary closed source driver for your graphics card.  Autoplus has already added rpm-fusion repositories in your system, so to install the graphics driver run Fedora’s “Add/Remove Software” and search for “nvidia” if you use an Nvidia card, or Catalyst if you’re using an AMD card. Choose the driver and press “apply”.
After the procedure finishes, you must open a terminal and run:
 sudo nvidia-xconfig

Fonts

Now from the same application (Add/Remove Software) search and install “gnome-tweak-tool”. You will need this tool to configure the system font options. The default Cantarell font is very improved, but still not as good as the Ubuntu font. Download the Ubuntu font family,  and extract the zip on a folder you will create under your home directory and name “.fonts”. Be aware that this folder will be hidden so make sure you will setup nautilus to show hidden files (view/show hidden files) before you create the folder.
Now open the “Advanced Settings” application (that is the gnome-tweak-tool), and choose Ubuntu fonts, slight Hinting and Rgba antialiasing
This should make your fonts look clearer and generally much better. Have a great time tweaking your new Fedora system!
PS: If you want to start theming your desktop after all this, I suggest you install the gnome user themes extension using yum and NOT the extensions website because in that case, a python bug renders the Advanced System Settings unable to start.
For questions please refer to our Q/A forum at : http://ask.unixmen.com 

Baca Selengkapnya ....

Developing Weather Application using Dojo Mobile

Posted by Unknown 0 komentar
http://www.technicaladvices.com/2012/05/31/developing-weather-application-using-dojo-mobile


Abstract

Dojo mobile (dojox/mobile) is one of the most powerful JavaScript frameworks that enable you to build cross mobiles web applications. It does not only contain mobile components but also it mimics the interface of the different mobile devices. Adding to this it responds to the mobile orientations. In this article, I will illustrate how to use the framework for building a weather application on the iPhone mobile.

Application Story

The application story is simple. In the weather mobile application, the user can get the current weather forecasting of a specific location. The user can do this by selecting one city from a list of available cities in the drop down and then click the “Get Information” button to get the weather information as shown in the screenshot below.

Building the weather application

In order to create the weather forecasting page, we need to know the main parts of the Dojo mobile page:
  • The Doc Type and META tags.
  • The mobile script and style includes.
  • The application pages.

The Doc Type and META Tags

The Doc type that is recommended to be used is the HTML5 doctype as shown below:
For the META tags, it is important to use the "viewport" META tag to setup cross-device layout as shown below:
 name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"/>
The other important META tag is an iPhone specific one which is the “apple-mobile-web-app-capable”. It is recommend to be set to “yes” to make the web application runs in full-screen mode as shown below:
 name="apple-mobile-web-app-capable" content="yes"/>

The script and style includes

Now, we come to the script and style includes. I’m using Dojo 1.7.1 for this application; in order to include the script and the style files; this can be done as shown below:
 rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojox/mobile/themes/iphone/iphone.css" rel="stylesheet">

src="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/dojo.js" data-dojo-config="async: true">
I only included the iPhone CSS file, and the dojo.js file which is loaded asynchronously for including only the resources we need to keep the application optimized.
After including the script and the style, we need to use the require statements for including the Dojo modules. I use the new Asynchronous Modules (AMD) convention for making asynchronous loading of the modules as shown below:
require(["dojox/mobile/parser", "dojo/_base/xhr", "dojox/mobile", "dojox/mobile/deviceTheme",
"dojox/mobile/TextBox", "dojox/mobile/Button", "dojox/mobile/compat",
"dijit/form/DataList", "dojox/mobile/ComboBox",
"dojo/domReady!"], function(parser) {

//...
parser
.parse();
});
The following modules are loaded:
  • The Dojo mobile parser "dojox/mobile/parser" for converting the HTML elements to Dojo mobile components.
  • The Dojo XHR module "dojo/_base/xhr" for allowing performing Ajax requests.
  • The Dojo mobile device theme "dojox/mobile/deviceTheme", for allowing detecting the mobile type and loading the proper theme correctly.
  • "dojox/mobile/TextBox", "dojox/mobile/Button", "dijit/form/DataList", "dojox/mobile/ComboBox", for loading the mentioned components.
  • The "dojox/mobile/compat" module is required for allowing having cross mobiles CSS3 animations.
  • "dojo/domReady!" module is a replacement for the old dojo.ready API. The exclamation mark is required to tell Dojo not to execute the callback until the DOM is ready.
Finally in the callback, I’m using only the first parameter which is the parser object. The parser.parse statement is called for allowing the Dojo mobile parser to convert the HTML elements to Dojo mobile components.

The Application Pages

In our weather application, we have mainly two pages; the weather forecasting page and the about page. In order to make the pages scroll to the left and the right while navigation, we need to use the Dojo mobile views. The Dojo mobile views are normal HTML elements with the dojo type "dojox.mobile.View". To define the two views, we can do this as shown below:
 id="weather" dojoType="dojox.mobile.View" selected="true">
...
id="about" dojoType="dojox.mobile.View"> ... The main view should be marked as selected by setting the selected attribute to "true".
In the weather forecasting page, there are three main elements:
  • Heading element.
  • Combo Box of the available cities.
  • The “Get Information” button.
In order to create the heading element, you can mark an HTML element h1 with the “dojox.mobile.Heading” dojo type as follows:
 dojoType="dojox.mobile.Heading">Weather
dojoType="dojox.mobile.ToolBarButton" moveTo="about">About
I included a toolbar button for moving to the other view. The moveTo attribute can have the id of the view to switch to, in our case it is the about view id.
In order to create the combo box element, we need to use two tags, one for the data which is the dijit.form.DataList, and the other for the widget itself which is the dojox.mobile.ComboBox as follows:
 data-dojo-type="dijit.form.DataList" data-dojo-props="id:'locationList'" >
selected>Cairo, Egypt
Stockholm, Sweden
Vienna, Austria
Madrid, Spain
Paris, France
New York, USA
Lima, Peru


id="location" class="ninety" type="text" data-dojo-type="dojox.mobile.ComboBox" data-dojo-props="list:'locationList'" />
The “location” combo box is referring to the “locationList” using the list attribute.
The “Get Information” button calls the getWeatherInformation function to get the weather information as follows:
 class="mblBlueButton full" dojoType="dojox.mobile.Button" onClick="getWeatherInformation();">Get Information
The getWeatherInformation JavaScript function is calling a proxy Java Servlet that interacts with the Yahoo weather service API using dojo xhrGet.
function getWeatherInformation() {
var selectedCode = cityMap[dijit.byId("location").value];

dojo
.xhrGet({
url
: "/mobileSamples/weatherProxyServlet?w=" + selectedCode,
handleAs
: "text",
load
: function(data) {
document
.getElementById("weatherResult").innerHTML = data;
}
});
}
The location value is read from the “location” combo box and the code of the location is retrieved from a custom JavaScript Map that I created for mapping the WOEID (Where on earth identification) to the locations.
When the HTML response is returned from the server, it is displayed directly in the "weatherResult" span.
Finally in the weather forecasting view, I embed the combo box and the button in the "dojox.mobile.RoundRect" div as follows:
 dojoType="dojox.mobile.RoundRect" shadow="true">
for="txtLocation">Select location


data-dojo-type="dijit.form.DataList" data-dojo-props="id:'locationList'" >
selected>Cairo, Egypt
Stockholm, Sweden
Vienna, Austria
Madrid, Spain
Paris, France
New York, USA
Lima, Peru


id="location" class="ninety" type="text" data-dojo-type="dojox.mobile.ComboBox" data-dojo-props="list:'locationList'" />


class="mblBlueButton full" dojoType="dojox.mobile.Button" onClick="getWeatherInformation();">Get Information


id="weatherResult"/>
The other “about” view element is a simple one that contains description for the sample as follows:
 id="about" dojoType="dojox.mobile.View">
dojoType="dojox.mobile.Heading" back="back" moveTo="weather">About
dojoType="dojox.mobile.RoundRect">This sample is developed by TechnicalAdvices.COM. It is powered by Dojo Mobile.
It contains a heading that includes a back button using the back attribute. The back attribute should be set to id of the view element that the application navigates to when the back button is clicked.
The next code listing shows the complete code of the weather forecasting page:




name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"/>
name="apple-mobile-web-app-capable" content="yes"/>
</span><span class="pln">Welcome to the weather application</span><span class="tag">

rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojox/mobile/themes/iphone/iphone.css" rel="stylesheet">
src="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/dojo.js" data-dojo-config="async: true">

type="text/javascript">
var cityMap = {};

require
(["dojox/mobile/parser", "dojo/_base/xhr", "dojox/mobile", "dojox/mobile/deviceTheme",
"dojox/mobile/TextBox", "dojox/mobile/Button", "dojox/mobile/compat",
"dijit/form/DataList", "dojox/mobile/ComboBox",
"dojo/domReady!"], function(parser) {

// initialize WOIDs ...
cityMap
["Cairo, Egypt"] = "1521894";
cityMap
["Stockholm, Sweden"] = "906057";
cityMap
["Vienna, Austria"] = "551801"
cityMap
["Madrid, Spain"] = "766273";
cityMap
["Paris, France"] = "615702";
cityMap
["New York, USA"] = "2459115";
cityMap
["Lima, Peru"] = "418440";

parser
.parse();
});

function getWeatherInformation() {
var selectedCode = cityMap[dijit.byId("location").value];

dojo
.xhrGet({
url
: "/mobileSamples/weatherProxyServlet?w=" + selectedCode,
handleAs
: "text",
load
: function(data) {
document
.getElementById("weatherResult").innerHTML = data;
}
});
}






id="weather" dojoType="dojox.mobile.View" selected="true">
dojoType="dojox.mobile.Heading">Weather
dojoType="dojox.mobile.ToolBarButton" moveTo="about">About


dojoType="dojox.mobile.RoundRect" shadow="true">
for="txtLocation">Select location


data-dojo-type="dijit.form.DataList" data-dojo-props="id:'locationList'" >
selected>Cairo, Egypt
Stockholm, Sweden
Vienna, Austria
Madrid, Spain
Paris, France
New York, USA
Lima, Peru


id="location" class="ninety" type="text" data-dojo-type="dojox.mobile.ComboBox" data-dojo-props="list:'locationList'" />


class="mblBlueButton full" dojoType="dojox.mobile.Button" onClick="getWeatherInformation();">Get Information


id="weatherResult"/>



id="about" dojoType="dojox.mobile.View">
dojoType="dojox.mobile.Heading" back="back" moveTo="weather">About
dojoType="dojox.mobile.RoundRect">This sample is developed by TechnicalAdvices.COM. It is powered by Dojo Mobile.



The Backend Java Servlet

Finally, the backend Java Servlet reads the WOEID parameter and opens a URL connection to the yahoo API weather forecasting URL for getting the weather forecasting of the location as shown in the code listing below.
package servlets;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.URL;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;

/**
* WeatherProxyServlet is a proxy servlet that wraps Yahoo weather REST service.
* @author hazems
*
*/

public class WeatherProxyServlet extends HttpServlet {
private static final long serialVersionUID = 8732370454506907957L;

protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

String WOEID = request.getParameter("w");
HttpURLConnection connection = null;

response
.setContentType("text/html");

PrintWriter writer = null;

try {
URL url
= new URL("http://weather.yahooapis.com/forecastrss?u=c&w=" + WOEID);

connection
= createHTTPConnection(url);

String output = getHTTPOutputResponse(connection);

SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new InputStreamReader(new ByteArrayInputStream(output.getBytes("UTF-8"))));

if (feed.getEntries() != null && feed.getEntries().size() > 0) {
SyndEntry entry = ((SyndEntry) feed.getEntries().get(0));

String title = entry.getTitle();
String description = entry.getDescription().getValue();

if (description.contains("Invalid")) {
throw new Exception(description);
}

writer
= response.getWriter();
writer
.print(title + "
"
+ description);
}
} catch (Exception exception) {
throw new ServletException(exception.getMessage());
} finally {
if (connection != null) {
connection
.disconnect();
}

if (writer != null) {
writer
.flush();
writer
.close();
}
}
}

private static HttpURLConnection createHTTPConnection(URL url) throws IOException, ProtocolException {
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn
.setDoOutput(true);
conn
.setDoInput(true);
conn
.setRequestMethod("GET");
conn
.setRequestProperty("Accept", "text/html");
conn
.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

return conn;
}

private static String getHTTPOutputResponse(HttpURLConnection conn) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));

String httpOutputResponse = "";
String outputLine;

while ((outputLine = br.readLine()) != null) {
httpOutputResponse
+= outputLine;
}

return httpOutputResponse;
}
}
You can try the application from your iPhone by going to the following URL:
http://www.mashups4jsf.com/mobileSamples/weather.jsp
You can download the complete Eclipse project from the following URL:
https://www.ibm.com/developerworks/mydeveloperworks/blogs/hazem/resource/29052012/mobileSamples.zip

Conclusion

In this article, you learned how to build a mobile application using the Dojo mobile APIs. You know how to use the framework views, headings, and components for building the weather forecasting application.

Baca Selengkapnya ....

High-Availability Storage With GlusterFS 3.0.x On Debian Squeeze - Automatic File Replication Across Two Storage Servers

Posted by Unknown 0 komentar
http://www.howtoforge.com/high-availability-storage-with-glusterfs-3.0.x-on-debian-squeeze-automatic-file-replication-across-two-storage-servers


This tutorial shows how to set up a high-availability storage with two storage servers (Debian Squeeze) that use GlusterFS. Each storage server will be a mirror of the other storage server, and files will be replicated automatically across both storage servers. The client system (Debian Squeeze as well) will be able to access the storage as if it was a local filesystem. GlusterFS is a clustered file-system capable of scaling to several peta-bytes. It aggregates various storage bricks over Infiniband RDMA or TCP/IP interconnect into one large parallel network file system. Storage bricks can be made of any commodity hardware such as x86_64 servers with SATA-II RAID and Infiniband HBA.
I do not issue any guarantee that this will work for you!

1 Preliminary Note

In this tutorial I use three systems, two servers and a client:
  • server1.example.com: IP address 192.168.0.100 (server)
  • server2.example.com: IP address 192.168.0.101 (server)
  • client1.example.com: IP address 192.168.0.102 (client)
All three systems should be able to resolve the other systems' hostnames. If this cannot be done through DNS, you should edit the /etc/hosts file so that it looks as follows on all three systems:
vi /etc/hosts
127.0.0.1       localhost.localdomain   localhost
192.168.0.100 server1.example.com server1
192.168.0.101 server2.example.com server2
192.168.0.102 client1.example.com client1

# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
(It is also possible to use IP addresses instead of hostnames in the following setup. If you prefer to use IP addresses, you don't have to care about whether the hostnames can be resolved or not.)

2 Setting Up The GlusterFS Servers

server1.example.com/server2.example.com:
GlusterFS is available as a package for Debian Squeeze, therefore we can install it as follows:
apt-get install glusterfs-server
The command
glusterfs --version
should now show the GlusterFS version that you've just installed (3.0.5 in this case):
root@server1:~# glusterfs --version
glusterfs 3.0.5 built on Jul 13 2010 16:44:21
Repository revision: v3.0.5
Copyright (c) 2006-2009 Gluster Inc.
GlusterFS comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GlusterFS under the terms of the GNU General Public License.
root@server1:~#
Next we create a few directories:
mkdir /data/
mkdir /data/export
mkdir /data/export-ns
Now we create the GlusterFS server configuration file /etc/glusterfs/glusterfsd.vol (we make a backup of the original /etc/glusterfs/glusterfsd.vol file first) which defines which directory will be exported (/data/export) and what client is allowed to connect (192.168.0.102 = client1.example.com):
cp /etc/glusterfs/glusterfsd.vol /etc/glusterfs/glusterfsd.vol_orig
cat /dev/null > /etc/glusterfs/glusterfsd.vol
vi /etc/glusterfs/glusterfsd.vol
volume posix
type storage/posix
option directory /data/export
end-volume

volume locks
type features/locks
subvolumes posix
end-volume

volume brick
type performance/io-threads
option thread-count 8
subvolumes locks
end-volume

volume server
type protocol/server
option transport-type tcp
option auth.addr.brick.allow 192.168.0.102
subvolumes brick
end-volume
Please note that it is possible to use wildcards for the IP addresses (like 192.168.*) and that you can specify multiple IP addresses separated by comma (e.g. 192.168.0.102,192.168.0.103).
Afterwards we start the GlusterFS server:
/etc/init.d/glusterfs-server start

3 Setting Up The GlusterFS Client

client1.example.com:
On the client, we can install the GlusterFS client as follows:
apt-get install glusterfs-client
Then we create the following directory:
mkdir /mnt/glusterfs
Next we create the file /etc/glusterfs/glusterfs.vol (we make a backup of the original /etc/glusterfs/glusterfs.vol file first):
cp /etc/glusterfs/glusterfs.vol /etc/glusterfs/glusterfs.vol_orig
cat /dev/null > /etc/glusterfs/glusterfs.vol
vi /etc/glusterfs/glusterfs.vol
volume remote1
type protocol/client
option transport-type tcp
option remote-host server1.example.com
option remote-subvolume brick
end-volume

volume remote2
type protocol/client
option transport-type tcp
option remote-host server2.example.com
option remote-subvolume brick
end-volume

volume replicate
type cluster/replicate
subvolumes remote1 remote2
end-volume

volume writebehind
type performance/write-behind
option window-size 1MB
subvolumes replicate
end-volume

volume cache
type performance/io-cache
option cache-size 512MB
subvolumes writebehind
end-volume
Make sure you use the correct server hostnames or IP addresses in the option remote-host lines!
That's it! Now we can mount the GlusterFS filesystem to /mnt/glusterfs with one of the following two commands:
glusterfs -f /etc/glusterfs/glusterfs.vol /mnt/glusterfs
or
mount -t glusterfs /etc/glusterfs/glusterfs.vol /mnt/glusterfs
You should now see the new share in the outputs of...
mount
root@client1:~# mount
/dev/sda1 on / type ext3 (rw,errors=remount-ro)
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
udev on /dev type tmpfs (rw,mode=0755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)
fusectl on /sys/fs/fuse/connections type fusectl (rw)
/etc/glusterfs/glusterfs.vol on /mnt/glusterfs type fuse.glusterfs (rw,allow_other,default_permissions,max_read=131072)
root@client1:~#
... and...
df -h
root@client1:~# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              29G  778M   27G   3% /
tmpfs                 249M     0  249M   0% /lib/init/rw
udev                  244M  100K  244M   1% /dev
tmpfs                 249M     0  249M   0% /dev/shm
/etc/glusterfs/glusterfs.vol
                       18G  848M   16G   5% /mnt/glusterfs
root@client1:~#
(server1.example.com and server2.example.com each have 18GB of space for the GlusterFS filesystem, but because the data is mirrored, the client doesn't see 36GB (2 x 18GB), but only 18GB.)
Instead of mounting the GlusterFS share manually on the client, you could modify /etc/fstab so that the share gets mounted automatically when the client boots.
Open /etc/fstab and append the following line:
vi /etc/fstab
[...]
/etc/glusterfs/glusterfs.vol /mnt/glusterfs glusterfs defaults,_netdev 0 0
To test if your modified /etc/fstab is working, reboot the client:
reboot
After the reboot, you should find the share in the outputs of...
df -h
... and...
mount
If modifying /etc/fstab doesn't help, undo your change to /etc/fstab and add this line to /etc/rc.local instead (before the exit 0 line):
vi /etc/rc.local
[...]
/bin/mount -t glusterfs /etc/glusterfs/glusterfs.vol /mnt/glusterfs
[...]
This makes sure the share gets mounted after the network is up.

4 Testing

Now let's create some test files on the GlusterFS share:
client1.example.com:
touch /mnt/glusterfs/test1
touch /mnt/glusterfs/test2
Now let's check the /data/export directory on server1.example.com and server2.example.com. The test1 and test2 files should be present on each node:
server1.example.com/server2.example.com:
ls -l /data/export
root@server1:~# ls -l /data/export
total 0
-rw-r--r-- 1 root root 0 2012-03-29 14:51 test1
-rw-r--r-- 1 root root 0 2012-03-29 14:51 test2
root@server1:~#
Now we shut down server1.example.com and add/delete some files on the GlusterFS share on client1.example.com.
server1.example.com:
shutdown -h now
client1.example.com:
touch /mnt/glusterfs/test3
touch /mnt/glusterfs/test4
rm -f /mnt/glusterfs/test2
The changes should be visible in the /data/export directory on server2.example.com:
server2.example.com:
ls -l /data/export
root@server2:~# ls -l /data/export
total 0
-rw-r--r-- 1 root root 0 2012-03-29 14:51 test1
-rw-r--r-- 1 root root 0 2012-03-29 14:52 test3
-rw-r--r-- 1 root root 0 2012-03-29 14:52 test4
root@server2:~#
Let's boot server1.example.com again and take a look at the /data/export directory:
server1.example.com:
ls -l /data/export
root@server1:~# ls -l /data/export
total 0
-rw-r--r-- 1 root root 0 2012-03-29 14:51 test1
-rw-r--r-- 1 root root 0 2012-03-29 14:51 test2
root@server1:~#
As you see, server1.example.com hasn't noticed the changes that happened while it was down. This is easy to fix, all we need to do is invoke a read command on the GlusterFS share on client1.example.com, e.g.:
client1.example.com:
ls -l /mnt/glusterfs/
root@client1:~# ls -l /mnt/glusterfs/
total 8
-rw-r--r-- 1 root root 0 2012-03-29 14:51 test1
-rw-r--r-- 1 root root 0 2012-03-29 14:52 test3
-rw-r--r-- 1 root root 0 2012-03-29 14:52 test4
root@client1:~#
Now take a look at the /data/export directory on server1.example.com again, and you should see that the changes have been replicated to that node:
server1.example.com:
ls -l /data/export
root@server1:~# ls -l /data/export
total 8
-rw-r--r-- 1 root root 0 2012-03-29 14:51 test1
-rw-r--r-- 1 root root 0 2012-03-29 14:52 test3
-rw-r--r-- 1 root root 0 2012-03-29 14:52 test4
root@server1:~#

5 Links


Baca Selengkapnya ....

Add These Modules to Enhance Apache Web Server

Posted by Unknown 0 komentar
http://olex.openlogic.com/wazi/2012/add-these-modules-to-enhance-apache-web-server


Apache remains the world’s most popular web server, thanks in part to the abundance of powerful modules that work in synergy to extend the web server’s core functionality. Here are some useful Apache modules that can improve your web server’s performance, content delivery, and overall security.

Modules for Performance Improvement

While the latest version of Apache performs well on its own, you can optimize the web server to consume fewer resources and improve content delivery by deploying modules that compress the output, remove unnecessary payload, and optimize the HTML and CSS code.
In CentOS, by default, Apache runs its Multi-Processing Module (MPM) in prefork mode, in which one parent process is responsible for forking enough child processes to serve all the remote clients that are trying to access the server. However, managing processes dynamically in accordance with clients’ needs is not very efficient, because each start and stop operation takes time and resources. ModPrefork addresses this drawback by allowing you to configure a minimum (and maximum) number of spare Apache children instances waiting for clients’ requests. Still, this feature is not flexible and agile enough for busy sites with sporadic peaks in requests.
ModWorker addresses ModPrefork’s performance problem by using threads to serve large numbers or requests with fewer system resources. To enable ModWorker in CentOS, edit the file /etc/sysconfig/httpd and uncomment the line HTTPD=/usr/sbin/httpd.worker. Then restart Apache with service httpd restart. To verify in what mode Apache is running use the command apachectl -l to list all of Apache’s loaded modules and look for worker.c.
Unfortunately, ModWorker is not fully compatible with all Apache modules, including such common ones as ModPHP. Prior to enabling it you should check for compatibility and find alternatives where needed. If you need both ModWorker and PHP, for instance, you can use Mod_FastCGI in place of ModPHP.

Content Optimization with ModPagespeed

Once you have optimized Apache’s server side, it’s time to improve the content delivery. ModPagespeed, a third-party, all-in-one optimization module developed by Google, rewrites and compresses output using ModDeflate to provide a faster client experience. It automatically applies the best practices from PageSpeed, a toolset for optimizing the performance of web pages. Though ModPagespeed is still officially in beta, it is a mature project. By using ModPagespeed you can avoid forcing your developers and designers to manually optimize HTML, CSS, JavaScript code, and images. Check the module’s features page for more information and useful comparisons.
You can install ModPagespeed either from source or via binary package. For CentOS, you can use the official installation package available from ModPagespeed’s download page. Once you download the package corresponding to your CentOS architecture (32-bit or 64-bit) run the command rpm -ivh mod-pagespeed*.rpm to install it. Restart Apache and ensure that ModPagespeed is installed and loaded by running the command apachectl -t -D DUMP_MODULES. In the output of the command you should be able to find pagespeed_module among the listed modules.
Next, open the configuration file /etc/httpd/conf.d/pagespeed.conf and examine all the available options. Allow your local client IP address in the directive by adding a new row after Allow from 127.0.0.1; for example, if your IP address is 192.168.0.2, add Allow from 192.168.0.2. Once you reload Apache you will be able to see the statistics of ModPagespeed at http://yourserverip/mod_pagespeed_statistics. This allows you to learn it faster and see the results of your optimizations.

Absolute Security with ModSecurity

ModSecurity is the most popular security module for Apache. We’ve already covered it in the article Protect and Audit Your Web Server with ModSecurity, so we’ll just say that it provides full web traffic inspection, blocking, and auditing, allowing you to protect your web server from known and unknown vulnerabilities, including DDOS attacks.

Detect Visitors’ Countries with ModGeoIP

ModGeoIP, based on MaxMind’s GeoIP data and technology, allows you to determine a visitor’s country using a locally saved GeoIP database. Once you know a visitor’s country, you can do things like redirecting him to a specific page or denying him access.
To install ModGeoIP you first need its C library and the package zlib-devel, which is a prerequisite. Download GeoIP C library’s latest version, extract it, and go through the usual installation steps, executing ./configure && make && make install.
APache eXtenSion tool
Not all Apache modules are available as precompiled packages. When you run into one that’s not, you can install it from source with APache eXtenSion tool (apxs), provided by the CentOS package httpd-devel. Apxs creates Apache modules as dynamic shared objects (DSO) from three types of files – C language source files (.c), object files (.o), and library archives (.a). DSO files are loaded during runtime in Apache through the mod_so module. Check whether your Apache has mod_so installed by running apachectl -l and look for mod_so.c in the output.
Next, install ModGeoIP itself. Download the latest version, extract it, and execute apxs -i -a -L/usr/local/lib -I/usr/local/include -lGeoIP -c mod_geoip.c. The arguments to the apxs command mean install the module in the default modules directory /usr/lib/httpd/modules/, activate it by loading it into Apache with the LoadModule directive, use the libraries inside /usr/local/lib, include the /usr/local/include directory, search for the library GeoIP, compile it from the C source file.
Once you restart Apache, the ModGeoIP module should be listed in the output of the command apachectl -t -D DUMP_MODULES. To enable it, create a file /etc/httpd/conf.d/geoip.conf and place inside of it the command to enable the module server-wide and the path to the binary file that contains the GeoIP database:
GeoIPEnable On
GeoIPDBFile /usr/local/share/GeoIP/GeoIP.dat
You can then start using ModGeoIP on a per Apache directory or vhost configuration basis, or with local .htaccess files. The configuration options are the same. As an example, if you wanted to deny access to any visitors from outside the United States:
SetEnvIf GEOIP_COUNTRY_CODE US AllowCountry
Deny from all
Allow from env=AllowCountry
For more examples and information check ModGeoIP’s home page.

Monitoring with ModStatus

You should always monitor Apache, or any service, to ensure optimal performance. Apache’s ModStatus module gives you information about the current server’s health and business.
ModStatus is installed by default in CentOS, but it’s not enabled. To enable it, open Apache’s main configuration file /etc/httpd/conf/httpd.conf, uncomment the following, and substitute your IP for your_ip with:

SetHandler server-status
Order deny,allow
Deny from all
Allow from your_ip

Also, uncomment ExtendedStatus On so that you can see more information, such as URLs accessed by current requests. Reload Apache and try to access http://yourserver/server-status to verify ModStatus is working. On the newly opened page you should be able to see all the statistics related to Apache, its processes (forks or threads), and CPU usage.
ModStatus can also produce machine-readable output if you append ?auto at the end of its URL: http://yourserver/server-status?auto. Other programs can then read and analyze the output. Auto mode data is used by Cacti, to draw graphs with useful trends, and by Nagios, to monitor for anomalies.

Protection with ModSpamhaus

Certain IP addresses are known to be compromised, and known to send spam or be used for DDOS attacks and other malicious activities. The Spamhaus project
is the best publicly available source for checking the reputation of an IP address. People usually think of Spamhaus as a project associated with mail servers, but the demand for similar web server protection led to the creation of ModSpamhaus for Apache, an extension that allows system administrators to block visitors from IP addresses with bad reputations.
To install ModSpamhaus, download the latest installation package and extract it. Find the file mod_spamhaus.c in the src directory and execute the command apxs -i -a -c mod_spamhaus.c to build the Apache module manually. The arguments tell apxs to install the module in the default modules directory /usr/lib/httpd/modules/, activate it by loading it into Apache with the LoadModule directive, and compile it from the C source file.
Next, create ModSpamhaus’s configuration file /etc/httpd/conf.d/spamhaus.conf. Place inside the following configuration options:

MS_METHODS POST,PUT,OPTIONS,CONNECT
MS_WhiteList /etc/spamhaus_whitelisted
MS_CacheSize 1000

This generic configuration is acceptable for most setups. The MS_METHODS option defines which HTTP methods should be inspected – POST, PUT, OPTIONS, and CONNECT. If you are defending against a DDOS attack or your web forms use GET methods, add GET too. The option MS_WhiteList allows you to specify a file with whitelisted IP addresses; that is, addresses that will be allowed regardless of their reputation. MS_CacheSize specifies information about how many IP addresses should be cached. Under heavier DDOS attacks you can increase this number to block larger numbers of repeating malicious IP addresses.
Using ModSpamhaus may slow down your site, especially if you enable it for more frequently used HTTP methods such as GET. To address this problem, you can install your own rbldnsd (DNS daemon suitable for running DNS-based blocklists) and use the ModSpamhaus option MS_DNS to specify its address. Having your own rbldnsd allows you to use a local database and to copy remote ones periodically, thus optimizing performance.
All of the above are only a few of the hundreds of Apache extensions, and represent modules designed to enhance Apache web server functions.

Baca Selengkapnya ....
Trik SEO Terbaru support Online Shop Baju Wanita - Original design by Bamz | Copyright of android japan.