Simple tool for load-testing HTTP server

Today I came across a very simple tool for load-testing. It’s called AB and come with Apache HTTP Server. The command line arguments are very simple:

ab -n 10000 -c 10 http://your_web_site/url.html

Where -n is the number of successful requests and -c is the number of concurrence connections.

If you want to have more control over the URL you want to test, and much more, I recommend JMeter (also from Apache)

Source: http://serverfault.com/questions/2107/tools-for-load-testing-http-servers

Quick and dirty way to prevent XML-RPC Pingback Attacks

XML-RPC Pingback Attacks are really annoying. You often see lots of POST /xmlrpc.php requests from different IP address from time to time. Sometimes, the number of requests is big enough to crash a server (yes, my server is a tiny angel). But I can’t disable WordPress XML-RPC because I need that for Jetpack to work (post by email, how cool!). Therefore, I figure out a quick and dirty way to prevent this by only allow Jetpack IP address to call XML-RPC.

These IP are not public by WordPress (I don’t know why) as they stated that:

“We aren’t able to provide any IP addresses for Jetpack as they fluctuate. You could try whitelisting *.wordpress.com for both inbound and outbound traffic, as a workaround.”

However, by looking at my server log, I see 2 potential IP address ranges. Quick lookup confirms my suspicion. Here they are:

66.155.0.0/18
192.0.64.0/18

And here is sample configuration in nginx

server {
  location ~ xmlrpc\.php {
    deny all;
    allow 127.0.0.0/24;
    allow ::1/128;
    allow 66.155.0.0/18;
    allow 192.0.64.0/18;
  }
}

If you know any other IP ranges, let me know and I will update my post. Happy blogging!

Using Bitcoin is not eliminating fees — unless exchanges are no longer required

Disclaimer: I’m not expert/investor in Bitcoin. I see Bitcoin as a great opportunity and great replacement for traditional money. Want to know more about Bitcoin? Pay this a visit: http://www.reddit.com/r/bitcoin

Recently more and more people talk about Bitcoin: Very convenient, fast, low fees, etc. Sounds fun, and it’s true, if you only consider Bitcoin transactions alone. By design, it’s very fast, irreversible, secure, completely verifiable and very low fees. However, let’s consider several scenario to see if it’s really true:

1. Online Purchases

With credit/debit cards, you don’t have to pay any processing fee. Merchants are the ones who pay processing fee to payment network.

With Bitcoin, no matter small or large transactions, you will be the one who pay fees.

2. Money Transfer (Domestic)

Almost all banks in US (and probably EU) have zero money transfer fee. For example, you can pay anyone without fee using Chase QuickPay, Wells Fargo SurePay, …

With Bitcoin, as title said, unless exchanges are no longer required, for instance Coinbase, you have to pay 1% + 0.15 USD to convert money to Bitcoin, 0.1 mBTC for transfer, 1% + 0.15 USD to convert Bitcoin back into money. So total is 2% + 0.3 USD + 0.1 mBTC. Pretty much!

3. Money Transfer (International)

International Money Transfer is a picky case. Most banks, payment transfer service like MoneyGram or Western Union charge a huge amount of fee. Processing time is from instant to 2-3 business days.

Think Bitcoin transaction is free? You bet. I’ve seen many posts on Reddit with something like:

“I’ve seen half a million to my friends around the globe. With 0.1 mBTC fee. Instant.”

However, only 1/3 of this sentence is true, unless exchanges are no longer required.

Yes, with Bitcoin, you can send virtually unlimited amount of money to virtually anywhere on earth.

No, not with 0.1 mBTC fee. Have you consider the fee for converting money to Bitcoin and vice versa? Have you take into account the difference in exchange rate? Have you consider the availability of exchanges at the destination?

No, not instance at all. That’s what you think. If you have Bitcoin available, then your Bitcoin leaves you instantly. The receiver also receive Bitcoin almost instantly. However, in order to use it, unless exchanges are no longer required, is another story.

If you only have money, you first need to convert it to Bitcoin. It might take 3-4 days for Bitstamp or Coinbase. The receiver also have to wait the same amount of time to convert it back to money. So who says it’s instant?

So who will be the one taking advantage of Bitcoin?

1. Exchanges. Of course.
2. Merchants. They don’t have to pay processing fee.

Who else, unless exchanges are no longer required?

How to use Macports version of gcc

OSX Mavericks only support gcc version 4.2.1. Macports, however supports gcc from 4.2 to 4.9. However, when you install gcc through Macports, your new version will not be enabled automatically. Here is a little trick:

sudo port select --list gcc
Available versions for gcc:
	mp-gcc44
	none (active)

The following command will enable your desired version:

sudo port select --set gcc mp-gcc44

You will need to do an extra step: Open a new Terminal and type hash -r to register the change with your system.

Happy coding!

Source: StackOverflow

How to install Oracle Database 12c on RedHat Enterprise Linux 6

IMHO, installing Oracle Database is not straight forward. There are lots of prerequisites packages and configurations that need to be installed and configured before you can actually install Oracle Database. Especially if you have a headless server that does not have any physical display attached to it, because you cannot install Oracle Database on a headless server without a response file (a response file is basically a configuration file that automate the installation process – however in order to create a response file, you will need another machine with display). Oh yes, I don’t have any other machine, and for god sake, I only want to install a single instance of Oracle Database, so why so complicated?

By the way, here is the full instruction that will help you install a single instance Oracle Database, straight forward from the beginning to the end.

A. Install prerequisites packages and configuration

Oracle has a very handy package called oracle-rdbms-server-12cR1-preinstall however it’s only available for Oracle Linux (yes, Oracle Linux). However, we can easily add yum repository to RHEL and install that package:

sudo wget http://public-yum.oracle.com/public-yum-ol6.repo -O /etc/yum.repos.d/public-yum-ol6.repo
sudo wget http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6 -O /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle

After this, installing prerequisites packages is straight forward:

yum install oracle-rdbms-server-12cR1-preinstall

B. Install Oracle Database

Since our server does not have any physical display attached to it, we need to create a virtual display and use X11 forwarding to setup Oracle Database. First step is to create virtual display

xorg-x11-server-Xvfb

Login under “oracle” account (this account should be created when we install prerequisites packages) and create a virtual display:

Xvfb :1 -screen 0 1280x1024x24

Fire another SSH session with parameter -X (to enable X11 forwarding) and login under “oracle” account. Then, download and extract 2 installation files into the same directory and run the Oracle Universal Installer

unzip linux.x64_11gR2_database_1of2.zip
unzip linux.x64_11gR2_database_2of2.zip
cd database
./runInstaller -ignorePrereq

Note that you will have to use -ignorePrereq parameter to bypass prerequisites check (since we’ve already installed it by the way)

OUI will open up a Installation window and things will be pretty straight forward from now on.

How to solve “Too many authentication failures for…” problem

Recently I am having trouble connecting to my home server from my laptop. Every time I connect, it said:

Received disconnect from my_ip: 2: Too many authentication failures for my_username

The strange thing is, connect from any other machine did not give me this problem. Is there anything wrong with my laptop? Even with multiple failures, my home server should reset login count sometimes.

Turn out the problem belongs to my SSH keys. I recently added 2 keys to my newly deployed servers. Each time I connect to my home server, my laptop will offer public key one by one, and apparently I have more private keys than the maximum number of retries, which is 6 on my home server.

Solution:

1. Explicitly specify the correct private key in host entry in the ~/.ssh/config file by adding IdentitiesOnly:

Host my_home_server_ip
  IdentityFile ~/.ssh/some_rsa_key
  IdentitiesOnly yes
  Port 22

2. Specify the correct private key:

ssh -i some_id_rsa -o 'IdentitiesOnly yes' username@my_home_server_ip

3. The last resort, disable Public Key Authentication completely:

ssh -o PubkeyAuthentication=no username@my_home_server_ip

Happy connecting!

Extract pages from PDF in Linux

I am not usually have to extract pages from a pdf file, but when I do, I used Adobe(R) Acrobat 7.0 that resides on my old Windows XP machine (believe me, it’s still work at this time). Today one friend asked me to extract a page from his pdf file, and I only have my MAC and Linux workstation with me. Fortunately, I figured out I can just use a single command to do this. Kudos to pdftk. For example:

pdftk A=inputfile.pdf cat A1-10 output outputfile.pdf

This command will extract page 1 to 10 from inputfile.pdf to outputfile.pdf

Very handy. Happy extracting!

How to install rtorrent and rutorrent

In order for rutorrent to work, rtorrent must be compiled with xmlrpc-c support. Here is the full instruction.

1. First, check to make sure the following libraries are installed on your system. At any step below, if you cannot run ./configure script correctly, you might have to install -dev or -devel packages of these libraries

  • gcc
  • ncurses
  • libsigc++-2.0
  • libssl
  • xmlrpc-c
  • subversion

2. Download and install xmlrpc-c if your distro does not support it

svn co http://xmlrpc-c.svn.sourceforge.net/svnroot/xmlrpc-c/advanced xmlrpc-c
cd xmlrpc-c
./configure
make
make install

3. Download and install libtorrent and rtorrent

wget http://libtorrent.rakshasa.no/downloads/libtorrent-0.13.3.tar.gz
wget http://libtorrent.rakshasa.no/downloads/rtorrent-0.9.3.tar.gz
tar xzfv libtorrent-0.13.3.tar.gz
tar xzfv rtorrent-0.9.3.tar.gz
cd libtorrent-0.13.3
./configure
make
make install
cd ../rtorrent-0.9.3/
./configure --with-xmlrpc-c=/usr/local/bin/xmlrpc-c-config
make
make install

4. Execute this line to copy rtorrent config to your home directory

cp /usr/share/doc/rtorrent/examples/rtorrent.rc .rtorrent.rc

5. Add the following line to the end of your .rtorrent.rc

scgi_port = 127.0.0.1:5001

6. Create download and session directories as pointed out in .rtorrent.rc. You might also change these directory as desired.

7. Download, extract rutorrent and plugins and placed them anywhere under your web root so that you can access it via HTTP

wget http://rutorrent.googlecode.com/files/rutorrent-3.5.tar.gz
wget http://rutorrent.googlecode.com/files/plugins-3.5.tar.gz
tar -xf rutorrent-3.5.tar.gz
cd rutorrent
tar -xf ../plugins-3.5.tar.gz
cd ..
mv rutorrent /var/www/

8. Delete /var/www/ruttorrent/.htaccess to disable htaccess authentication (you can always enable it in the future)

9. Fire up your web browser and open http://yourdomain.com/rutorrent. You will see the GUI very similar to uTorrent.

Happy torrenting. Download responsibly.