MySQL db replication

November 12th, 2011 No comments

This is a step by step guide to setup database replication for MySQL. In this replication setup, there are primarily two (or more) database servers – master and slave. The two databases are exact copies i.e. they have exactly same data. Any operation done on the master is immediately executed on the  slave as well and hence the two are synced.

Steps 1 : We need to configure the master and prepare it for replication

Edit my.cnf file and enable networking for master. Also, allow MySQL to communicate with other machines. Depending on your flavour of linux, you can locate my.cnf file in /etc/my.cnf or /etc/mysql/my.cnf. Comment out the following two lines.

#skip-networking
#bind-address            = 127.0.0.1

Next, we restart mysql to bring the aforementioned changes into effect.

Step 2 : Log into the MySQL database as root and create a user with replication privileges.

GRANT REPLICATION SLAVE ON *.* TO ‘repl’@'%’ IDENTIFIED BY ‘<my_password>’;
FLUSH PRIVILEGES;

Step 3 : Now, we need to lock down the MySQL

USE mydatabase;

FLUSH TABLES WITH READ LOCK;

SHOW MASTER STATUS;

You will get the following information back

mysql> SHOW MASTER STATUS;
+———————-+————–+——————-+———————–+
| File                             | Position        | Binlog_Do_DB  | Binlog_Ignore_DB |
+———————-+————–+——————-+———————–+
| mysql-bin.000004 | 466435744  |                                 |                                       |
+———————-+————–+——————-+———————–+
1 row in set (0.00 sec)

Save this information as it is going to be used while configuring the slave.

Take a dump of the master.

mysql -u root -p<my_password> –opt mydatabase > mydatabase.sql

Once, the aforementioned information has been noted down, we can unlock MySQL.

UNLOCK TABLES;

Step 4 : Coming on to the slave, first we need to create the database.

CREATE DATABASE mydatabase;

Now, copy the sql dump from master server to the slave server. You can use scp to transfer the sql dump file

scp mydatabase.sql slave_user@slave_machine:/tmp/mydatabase.sql

mysql -u root -p<my_password> mydatabase < /tmp/mydatabase.sql

Step 5 : Now we need to configure the slave

Open my.cnf file and append the following lines

server-id=2
master-host=master_server_ip
master-user=repl
master-password=mypassword
master-connect-retry=60
replicate-do-db=mydatabase

Now, restart mysql

sudo /etc/init.d/mysql restart

Step 6 : Next, log into mysql and execute the following commands

SLAVE STOP;

CHANGE MASTER TO MASTER_HOST=’master_host_address’, MASTER_USER=’repl’, MASTER_PASSWORD=’<my_password>’, MASTER_LOG_FILE=’mysql-bin.004′, MASTER_LOG_POS=466435744;

Finally, we need to stare the slave

SLAVE START;

Now the replication should be in effect. You can test if the replication has been successfully implemented by adding a row in any of the tables in the master, and the same will be added to the slave as well.

Categories: MySQL Tags: , , ,

How to host multiple domains on the same machine

October 27th, 2011 No comments

In the last article we saw how one can get himself a domain name and host his own website using Amazon Web Services (AWS). In this post we’ll see how to host multiple domains on the same machine. Why would you want to do this. The reason is simple and plenty: You may have just one machine but more than one sites that you want to host. If you’re using Apache/httpd web server, its pretty straight forward.

Locate your httpd.conf file, usually its sitting somewhere in

/etc/httpd/conf/httpd.conf

or

/etc/apache2/httpd.conf

 

Now, we need to add a couple lines to this file so that it can support multiple domains on the same machine.

NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin amitshanker@acm.org
    DocumentRoot /var/www/www.texens.in
    ServerName texens.in
    ServerAlias www.texens.in
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin amitshanker@acm.org
    DocumentRoot /var/www/www.blog.texens.in
    ServerName blog.texens.in
    ServerAlias www.blog.texens.in
</VirtualHost>

 

The aforementioned configuration allows for the following two domains to map to the same machine: texens.in as well as blog.texens.in . The DocumentRoot tells where exactly to look for the files corresponding to that domain. For example, texens.in will look at /var/www/www.texens.in for the corresponding web pages. We can add multiple domains using the <VirtualHost> tags.

Categories: Uncategorized Tags:

How to get yourself a website !

October 9th, 2011 No comments

When I was a student in college, I spend a couple days learning HTML. Given the ease with which you can write HTML, I very soon build myself a couple pages just for fun. Our college used to provide us free webspace to host our own website and I used it to host my personal homepage.

But there were many a limitations with the hosting provided by our Computer Science and Engineering Department (mostly due to security and disk space constraints), so I decided to host my website elsewhere.

To get yourself a website you need two very basic things:

  1. Domain name (example: http://texens.in)
  2. Hosting space (the location on a webserver where all your files live)
You can get both the aforementioned items for free (And obviously like most free things there will be limitations). But for a beginner, its more than enough.

I remember using http://freedomain.co.nr in my college days to get a free domain. Its not exactly a domain but a codomain. You’ll get something like texens.freedomain.co.nr. But its not bad when you’re getting it for free. If you can shell out a couple hundred rupees, you can buy yourself a domain from a reseller. There are tons of them out there – godaddy.com, netspaceindia.com, etc..

The cost of the domain name varies – you can get a .info for a 100 Rupees while a .com may cost you upwards of 500 Rupees. You can buy multiple domains and direct them to the same site.

As far as hosting space is concerned, a lot of website give free hosting space. They also provide one or more databases which you can use for your website. I remember using 5gigs.net back in the college days. They provide 5 GB free space along with two databases. These hosting providers have cPanel which one can use to manage various services such as mailers, databases, emails, etc.

These hosting providers run their own PHP servers in the backend and the only limitation is that you can’t get access to the servers. So, if you want to install a module to the apache server, you just can’t. To overcome this, you can use Amazon’s EC2 (http://aws.amazon.com/ec2/). They provide a micro instance for a year absolutely free. The beauty about Amazon’s EC2 is that you can install the operating system, and packages of your choice. They provide a virtual machine and a lot of addon services like storage, email etc.

Categories: web Tags:

Auto Complaints via SMS (Bangalore Traffic Police)

September 21st, 2011 7 comments

A couple days back, on my way to work I came across a traffic police constable who was distributing these mini booklets among the pedestrians passing by. Apparently the Bangalore Traffic Police has come up with some really cool IT enables services to help out the Bangaloreans. I’m not sure if these services have been in service for long, because this was the first time I came across it. But I’m guessing that 90 % of the Bangaloreans are unaware of these very helpful services and hence this blog post.

The content of the pamphlet goes like this:

 

Now you can avail information regarding Parking Situation, Pending Violation Notices and Vehicle Ownership details by SMS

4 WHEELER PARKING INFORMATION

To get latest information on 4 wheeler parking space availability by sending SMS

BITS<SPACE>PARK to 52225

Example: BITS PARK    (Send to 52225)

 

TRAFFIC VIOLATION PENDING NOTICE

You can get information on the pending challans of your vehicle by sending SMS

BITS<SPACE>FINE<SPACE>VEHICLE NO.

Example: BITS FINE KA01XY1234  (Send to 52225)

VEHICLE OWNERSHIP DETAILS

  1. Did you sell your vehicle?
  2. Is ownership transferred?

You can get current owner’s information of a vehicle by sending SMS.

BITS<SPACE>RTO<SPACE>VEHICLE NO.

Example: BITS RTO KA01XY1234  (Send to 52225)

If not transferred, visit RTO and get it done or you will continue to receive violation tickets

 

USEFUL CONTACT NUMBERS

Police Control Room : 100

Ambulance : 108

Easy Auto : 9844112233

Traffic Control Room : 103

 

24 hours helpline for all traffic related queries / suggestions / reporting of violation call :

080-25588444

080-25588555

Bangalore Traffic Police Website: www.bangaloretrafficpolice.gov.in

 

Auto Rickshaw Refusal or Overcharging

In case of refusal or overcharging by an auto, just send an SMS to 52225

For Refusal :

AUTO<SPACE>REF<SPACE>AUTO NO.<SPACE>LOCATION<SPACE>TIME OF REFUSAL

Example: AUTO REF KA01XY1234 MG ROAD TO KORMANGALA 5:30 PM

For Overcharging:

AUTO<SPACE>OVR<SPACE>AUTO NO.<SPACE>LOCATION<SPACE>TIME OF OVERCHARGING

Example: AUTO REF KA01XY1234 MG ROAD TO KORMANGALA 5:30 PM

Send to 52225

 

Traffic Alerts

For real time traffic alerts

Just send SMS to 567678

JOIN BTP

To unsubscribe, Send SMSto 567678

LEAVE BTP

 

I have a scanned copy of the images here because those were scanned copied and hence pretty heavy to fit. If you wish, you may download the pamphlets here and here.

 

Reset MySQL root password on linux

May 11th, 2011 No comments

While working on multiple projects, machines and environments it happens every once in a while that I forget the root password. But resetting your MySQL instance’s root password is very straight-forward job and doesn’t require much effort or skill.

Following is a quick step by step guide to reset your MySQL’s root password.

First of all, stop your MySQL server

root@texens:/home/texens# /etc/init.d/mysql stop
mysql stop/waiting

Now, run mysql in safe mode with the skip-grant-tables option:

root@texens:/home/texens# mysqld_safe --skip-grant-tables&
[1] 5259

Now log into mysql console, it’ll allow you to login without password

root@texens:/home/texens# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.54-1ubuntu4 (Ubuntu)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL contains an internal database that goes by the name “mysql”. This table contains all the information regarding the users, password, host etc.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

Now set new password from mysql commandline

mysql> update user set password=PASSWORD("admin") where User="root";
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

Finally, flush the privileges and quit.

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
root@texens:/home/texens#

Now restart the MySQL server and you’re good to go !

root@texens:/home/texens# /etc/init.d/mysql restart
mysql start/running, process 5653
root@texens:/home/texens#
Categories: linux Tags: , ,

Broadband Penetration and the vicious circle

November 8th, 2010 No comments

Broadband is a term normally considered to be synonymous with a high-speed connection to the internet. The term itself is technology neutral; broadband can be delivered by a range of technologies including DSL, LTE or next generation access. Broadband is often contrasted with dial-up access which uses 56 kbps modem.

Often a minimum limit is defined to differentiate between broadband and other means to access the web and this limit varies from country to country. It can be anything between 64 kbps to 4 Mbps. Interestingly, this limit keeps on rolling higher as the market gets flooded with connections with higher speed. Although ADSL and cable internet are the most common technologies in use for broadband, optical fiber and VSDL are now getting quite some popularity. And as cellular broadband are moving to third generation (3G) networks, they are getting the ability to support faster data speeds using technologies such as EVDO, HSPDA and UMTS.

Broadband penetration is now being treated as a key economic indicator.

One of the most important factors behind internet penetration is the broadband costs. For example, O2 - a broadband Internet access service offered by Telefónica O2 U.K., (a subsidiary of Telefónica Europe) provides unlimited downloads for just 30 USD. While a basic package costs just 25 USD a month. These packages often come with various premium services such as free technical help from experts 24/7 over phone, free email addresses, anti virus packages and lots of free web texts.

On the contrary, broadband in many developing countries like India and China cost about 60-80 USD per month and that explains the lower penetration rates.  A quick study into the statistics reveals a lot about the Internet penetration in a region. For example, UK has 19.5 million broadband connections (that makes it a 31% internet penetration) while Brazil has 14 million broadband connections (7.23%). Higher broadband connections offer not just HD video and games, but also include services such as tele-presence (providing flexible working patterns and cutting travel costs), e-healthcare and cloud services which help costs and drive innovation. According to the Next Generation Final Third Project, UK, the first generation broadband gave a boost of 0.5 to 1% to the GDP in a year.

Higher internet penetration drives economy, better economy means lower broadband costs, which in turn leads to larger user base and hence even higher internet penetration. In this way, it sets in a self-sustaining vicious circle leading to better economy. Many developing countries are subsidizing broadband to increase the internet penetration. With more and more governing agencies adopting e-governance, it makes all the more sense to empower the citizens with this powerful tool.

Categories: web Tags:

Selectively hide posts on Facebook using Greasemonkey

June 13th, 2010 No comments

Unlike a lot of people, I don’t happen to be a fan of Soccer. I know thats a bit difficult to believe, especially with this World cup season going on. Since the last few days, I’ve been waking up in the morning to a facebook full of soccer posts. I tried to tolerate it for a while, but then I realized that I couldn’t take it anymore, so I wrote this simple Greasemonkey script to hide all the posts on facebook containing the term soccer.

Named “I hate Soccer”, this script hides all the facebook posts that contain the word soccer.

In order to see it working, you need to install Greasemonkey addon for mozilla. from here. Once installed, just navigate to the URL: http://texens.5gigs.net/webpage/iHateSoccer.user.js

You’ll see a dialog box come up, select install and that’s all. You won’t see any posts that contain the term soccer from now onwards on facebook.

The source code for the script:

// ==UserScript==
// @name           I Hate Soccer
// @namespace      none
// @description    removes all posts containing the keyword soccer
// @date           2010-06-13
// @author         texens
// @include        http://www.facebook.com/*
// @require        http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// ==/UserScript==

$(document).ready(function() {
$(“h6:contains(‘soccer’)”).parent().parent().parent().hide();
});

Categories: software Tags: ,

Modem Configurations for BSNL Broadband

May 24th, 2010 54 comments

I just got a BSNL Broadband connection (UL 750 Plan) and spent all day trying to setup the connection on my laptop and desktop. The setup on Windows 7 via wired connection was a cake walk, but the wireless on the Windows gave me hell.

After a lot of googling and some hit & trial, I was finally able to get the wireless as well as wired connection on both my machines – laptop and the desktop, in both Windows and Ubuntu.

System Information

I’m using Type 2 ADSL modem Teracom T2-B-Gawv1.4U10Y-BI. The machines I’ve connected run Windows 7 Professional and Ubuntu 10.04.

Procedure

I’m assuming that you have been able to connect to the modem using the wired or wireless connection and we’re going to concentrate on connecting to Internet part.

  1. Fire up your browser and navigate to 192.168.1.1. This is your modem’s IP address. You’ll be prompted to give username and pasword. By default, BSNL uses admin and admin as the username and password. respectively.You’ll be directed to the Home >> Overview Page.
  2. Before we start playing around with the settings and configuration, lets create a backup of our current modem settings. Go to Admin >> Backup & Restore, and create a backup file and save it on your local hard drive.
  3. If you’re using Teracom T2-B-Gawv1.4U10Y-BI, then you just got lucky, because I have the configuration file that you can use straight away and save yourself the effort to manually change all the settings. You may download the configuration file off this link: http://texens.in/downloads/Conexant.icf.zip
  4. In order to save this configuration file to your modem, go to Admin >> Backup & Restore.Backup & Restore
  5. You still need to set your username and password in the new internet connection that has been created. Go to Configuration >> Internet Connection and edit the pppoe_0_35 connection. Keep on pressing the Next button until you arrive “Configure Broadband Username and Password” page. > Internet Connection Configuration” src=”http://blog.texens.in/wp-content/uploads/2010/05/2-edit-pppoe1.png” alt=”" width=”640″ height=”515″ />Use the username and password provided to you by your provider and click on Next. Finally on the last page, click on Apply to set everything up.
  6. The last step is to reboot the modem. Go to Admin >> Reboot and reboot the router therefrom. Wait for a minute and you’re all set with the modem.

Now that we have our modem properly configured, we can move to setting up the PC. For Windows, its pretty straight forward, but for Linux, it may not be all that easy. I had a hard time trying to configure linux to get the internet connection. And then I came across this totally awesome tool wicd. wicd worked like a charm and it was all very easily setup without any problem.

Categories: software Tags: ,

the bitch is here !

May 7th, 2010 No comments

Ever since I replaced my CPU and 17 inch monstrous CRT monitor with a 14 inch HP laptop, I’ve been missing the large screen badly. Getting a new monitor to connect with my laptop was on my cards since quite some time, but I was unable to materialize it due to one or the other reasons. But, finally I bought a new big black beautiful bitch from Kolkata. It was pretty difficult to find a 22 inch monitor with HDMI port. I checked in 4 shops – including the (in)famous E-Mall in Chandani Chowk, Kolkata and got a negative. 22 inches are very common in CC but HDMI port was the problem. Finally, I was able to lay my hands on one with HDMI port at good old Arihant’s. Thanks to his bias for kgpians, he not only arranged the monitor with HDMI support, but also gave it to me at the old (cheaper) price. Here’s a snap of the laptop with the monitor connected with the HDMI cable.

Big Black Beautiful Bitch

the Big Black Beautiful Bitch

Coming to the specifications:

It has a maximum resolution of 1920×1080 and a dynamic contrast ratio of 10000:1. It has a D-sub, DVI-D as well as HDMI input connector. I have tried the DVI-D input connector once, but most of the time I’ve been running with the HDMI connector. Note that, the HDMI connector doesn’t come along with the Monitor and you’ll have to buy it separately. The picture quality has been great ! It took me quite some time to grasp all the functionalities of its vast menu. It has a number of preconfigured settings which can be changed from the monitor’s panel manually. It also has inbuilt speakers and supports HDMI audio. The response time is 5 ms (gray to gray is 2 ms). Its user manual also boasts of a senseye+photo technology which gives 5 preset modes to support everyday needs. I haven’t been able to discover these modes fully yet. But, for sure this bitch is on for some real adventure for the coming few days.

There seems to be some problem with ubuntu 10.04 as it has failed to support the HD audio on my system. It works absolutely fine on windows 7 but ubuntu is creating quite some trouble. But I’m not surprized, 10.04 was launched jst a week back and its pretty much expected to have some bugs in the system for the next few days. I’m hoping that the problem will be fixed asap. I’ve been using the monitor for mostly 2 purposes – viz coding and watching movies in full HD. The experience is simply awesome ! Combined with a Creative 2.1 speakers, it acts pretty much like a Home Theatre system. Very soon I’ll be getting myself a 5.1 speakers and it’ll add some more fun to the experience.

Categories: Uncategorized Tags:

Hindi translations for limesurvey

April 30th, 2010 No comments

I had an interesting experience today. We needed to translate a news article posted on limesurvey website into hindi. I had never done any translations before and had absolutely no idea how to do it. In the absence of a Hindi keyboard, it bacame all the more difficult.

My first thought was to try Google translations. After a couple attempts, I realized that the google translations wasn’t good enough. Fortunately, while googling for translations I stumbled upon 2 very useful resources – Google Transliterations and shabdkosh.

Using Google Transliterations, one can type hindi words using english alphabets and the transliteration engine automatically convrerts the words from english alphabets to hindi alphabets. On the other hand, shabdkosh is an excellent English to Hindi dictionary. On querying english words, it returns the translated words in hindi alphabets and makes life easier :)

It would have been a herculian task to do all the translations in the absence of these two amazing resources. I’ll be getting myself a HIndi keyboard in a couple days to make it easier to type in the hindi alphabets physically.