January 31, 2013

Setting Up Percona-xtrabackup


Percona XtraBackup is the world's only open-source, free MySQL hot backup software that performs non-blocking backups for InnoDB and XtraDB databases. With Percona XtraBackup, you can achieve the following benefits:
  • Backups that complete quickly and reliably
  • Uninterrupted transaction processing during backups
  • Savings on disk space and network bandwidth
  • Automatic backup verification
  • Higher uptime due to faster restore time
Ref: 

 Installation:

wget http://www.percona.com/redir/downloads/XtraBackup/XtraBackup-2.0.3/binary/Linux/x86_64/percona-xtrabackup-2.0.3-470.tar.gz

tar -zxvf percona-xtrabackup-2.0.3-470.tar.gz

cd percona-xtrabackup-2.0.3/bin

sudo cp * /usr/bin

Setting Up Percona-mysql-server

Percona apt Repository is not included in Base Ubuntu. So need to install it

sudo gpg --keyserver  hkp://keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A
sudo gpg -a --export CD2EFD2A | sudo apt-key add -

Add this to /etc/apt/sources.list, replacing VERSION with the name of your distribution:

deb http://repo.percona.com/apt precise main
deb-src http://repo.percona.com/apt precise main
apt-get update
apt-get install percona-server-server-5.5 percona-server-client-5.5

Ref:http://www.percona.com/doc/percona-server/5.5/installation/apt_repo.html
Ref:http://www.percona.com/doc/percona-server/5.5/installation.html

We can generate initial mysql configuration file (my.cnf) through the following link
https://tools.percona.com/wizard

VirtualBox Clone Root HD / Ubuntu / Network issue



When you clone a root Ubuntu disk in VirtualBox, one thing that gets messed up is the network card definition.  This is because Ubuntu (as it should) uses UDEV IDs for the network device.  When you boot your new disk, the network device ID has changed, so it creates a new eth1 device.  Unfortunately, this conflicts with the VirtualBox network setup.  What to do?

Boot the box (no network)

Edit the /etc/udev/rules.d/70-persistent-net.rules

Delete the eth0 line and modify the eth1 line to be eth0

--------- Example OLD -----------

# This file was automatically generated by the /lib/udev/write_net_rules# program, run by the persistent-net-generator.rules rules file.## You can modify it, as long as you keep each rule on a single# line, and change only the value of the NAME= key.

# PCI device 0x8086:0x100e (e1000)    <-------------------- br="" delete="" lines="" these="" two="">SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:d8:8d:15", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:0x100e (e1000)     ---Modify the next line and change eth1 to be eth0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:89:84:98", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

----------------------------------------

--------- Example NEW -----------

# This file was automatically generated by the /lib/udev/write_net_rules# program, run by the persistent-net-generator.rules rules file.## You can modify it, as long as you keep each rule on a single# line, and change only the value of the NAME= key.

# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:89:84:98", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

----------------------------------------
Reference:

Image cache issue in drupal with nginx


Resolved it by adding the following in nginx virtual host file:
       
    location ^~ /sites/default/files/imagecache/ {
            index  index.php index.html;

            if (!-e $request_filename) {
                rewrite  ^/(.*)$  /index.php?q=$1  last;
                break;
            }
        }

The above assumes that your imagecache files are to be stored in sites/default/files/imagecache
Instead of nginx serving the static content (the jpeg or png or whatever) to the browser it will instead rewrite the path to (invisibly): index.php?q=sites/default/files...
This allows imagecache to run its manipulations on the file.
Just make sure you alter the location directive to match whatever path your imagecache files are in (relative to site root) and you should be fine.

Reference:

August 16, 2012

How To Delete/Remove Blocked IP From DenyHosts

1. First you need to stop Denyhosts service, by following command.
[root@geopc ~]# /etc/init.d/denyhosts stop
2. Next open file /etc/hosts.deny with below command.
[root@geopc ~]# vi /etc/hosts.deny
3. Delete blocked IP address, then save and close above file.
4. Now go to directory called /usr/share/denyhosts/data or /var/lib/denyhosts/
[root@geopc ~]# cd /usr/share/denyhosts/data
5. Next you need to delete blocked IP from all below following files with help of vi editor.
[root@geopc ~]# vi hosts
[root@geopc ~]# vi hosts-restricted
[root@geopc ~]# vi hosts-root
[root@geopc ~]# vi hosts-valid
[root@geopc ~]# vi users-hosts
6. Once you removed your blocked IP from all above files, then start Denyhosts service.
[root@geopc data]# /etc/init.d/denyhosts start

July 26, 2012

Connecting to a MySQL server from a different server

Connecting to a MySQL server from a different domain

 

Step # 1: Login Using SSH (if server is outside your data center)

First, login over ssh to remote MySQL database server:

Step # 2: Edit my.cnf File

Once connected you need to edit the MySQL server configuration file my.cnf using a text editor such as vi.
  • If you are using Debian Linux file is located at /etc/mysql/my.cnf location
  • If you are using Red Hat Linux/Fedora/Centos Linux file is located at /etc/my.cnf location
  • If you are using FreeBSD you need to create a file /var/db/mysql/my.cnf
Edit /etc/my.cnf, run:
# vi /etc/my.cnf

Step # 3: Once file opened, locate line that read as follows

[mysqld] 
Make sure line skip-networking is commented (or remove line) and add following line
bind-address=YOUR-SERVER-IP
For example, if your MySQL server IP is 65.55.55.2 then entire block should be look like as follows:
[mysqld]
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
language        = /usr/share/mysql/English
bind-address    = 65.55.55.2
# skip-networking
....
..
....
Where,
  • bind-address : IP address to bind to.
  • skip-networking : Don’t listen for TCP/IP connections at all. All interaction with mysqld must be made via Unix sockets. This option is highly recommended for systems where only local requests are allowed. Since you need to allow remote connection this line should be removed from my.cnf or put it in comment state.

Step# 4 Save and Close the file

If you are using Debian / Ubuntu Linux, type the following command to restart the mysql server:
# /etc/init.d/mysql restart
If you are using RHEL / CentOS / Fedora / Scientific Linux, type the following command to restart the mysql server:
# /etc/init.d/mysqld restart
If you are using FreeBSD, type the following command to restart the mysql server:
# /usr/local/etc/rc.d/mysql-server stop
# /usr/local/etc/rc.d/mysql-server start

OR
# /usr/local/etc/rc.d/mysql-server restart

Step # 5 Grant access to remote IP address

Connect to mysql server:
$ mysql -u root -p mysql

Grant access to a new database

If you want to add a new database called foo for user bar and remote IP 202.54.10.20 then you need to type the following commands at mysql> prompt:mysql> CREATE DATABASE foo;
mysql> GRANT ALL ON foo.* TO bar@'202.51.10.20' IDENTIFIED BY 'PASSWORD';

How Do I Grant Access To An Existing Database?

Let us assume that you are always making connection from remote IP called 202.54.10.20 for database called webdb for user webadmin, To grant access to this IP address type the following command At mysql> prompt for existing database, enter:
mysql> update db set Host='202.54.10.20' where Db='webdb';
mysql> update user set Host='202.54.10.20' where user='webadmin';

Step # 6: Logout of MySQL

Type exit command to logout mysql:mysql> exit

Step # 7: Open port 3306

You need to open TCP port 3306 using iptables or BSD pf firewall.

A sample iptables rule to open Linux iptables firewall

/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT
OR only allow remote connection from your web server located at 10.5.1.3:
/sbin/iptables -A INPUT -i eth0 -s 10.5.1.3 -p tcp --destination-port 3306 -j ACCEPT
OR only allow remote connection from your lan subnet 192.168.1.0/24:
/sbin/iptables -A INPUT -i eth0 -s 192.168.1.0/24 -p tcp --destination-port 3306 -j ACCEPT
Finally save all rules (RHEL / CentOS specific command):
# service iptables save

A sample FreeBSD / OpenBSD pf rule ( /etc/pf.conf)

pass in on $ext_if proto tcp from any to any port 3306
OR allow only access from your web server located at 10.5.1.3:
pass in on $ext_if proto tcp from 10.5.1.3 to any port 3306  flags S/SA synproxy state

Step # 8: Test it

From your remote system or your desktop type the following command:
$ mysql -u webadmin –h 65.55.55.2 –p
Where,
  • -u webadmin: webadmin is MySQL username
  • -h IP or hostname: 65.55.55.2 is MySQL server IP address or hostname (FQDN)
  • -p : Prompt for password
You can also use the telnet or nc command to connect to port 3306 for testing purpose:
$ echo X | telnet -e X 65.55.55.2 3306
OR
$ nc -z -w1 65.55.55.2 3306
Sample outputs:
Connection to 65.55.55.2 3306 port [tcp/mysql] succeeded!

 

 

 

April 18, 2012

Access Your MySQL Server Remotely Over SSH

Access Your MySQL Server Remotely Over SSH

So you’ve got MySQL on your web server, but it’s only opened to local ports by default for security reasons. If you want to access your database from a client tool like the MySQL Query Browser, normally you’d have to open up access from your local IP address… but that’s not nearly as secure.

So instead, we’ll just use port-forwarding through an SSH tunnel, so your MySQL client thinks it’s connecting to your localhost machine, but it’s really connecting to the other server through the tunnel.

You will need the following software:

Putty:
You can download putty from the url: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

Run the downloaded putty.exe file. You will get a window like this and enter the Hostname or IP Address.

For eg:
Hostname or IP Address: 10.5.7.51

Now click open

You will get a session and for saving that session right click on windows and take Change Settings as shown below:

Below Saved Sessions enter any name for eg: mysql-ssh and click on save.

Now again take putty and click on whichever connection name you wish to use for the secure tunnel.

Click "Load"
Go to Connection > SSH > Tunnels

Enter MySQL connection information

The "Source port" is the local port your MySQL Administrator will connect to instead of the remote (server) port it normally would. This can be any port and we can use .
The "Desitination" is the address and port of your actual MySQL Server. But since your SSH connection will be considered "local" to your MySQL Server, you should use either "127.0.0.1" or "localhost" depending on what works best. Then specify your mysql port so that Destination will be as follows:

127.0.0.1:3306

Make sure the information in "Source port" and "Destination" are correct, that the "Local" radio button is selected and click "Add".

You should now see the new tunnel information displayed as shown.

Go back to the main Putty screen and save the connection.

Now you can open ssh session by entering the user name and password.

Once you’ve got the ssh tunnel going, you can open up any mysql client and enter in the details for your remote server.

Since your connection will now be through the secure tunnel created by Putty, your "Server Host" will now be local so use "127.0.0.1".

The "Port" should be set to the same port you set for Source port earlier.

Once the connection settings are correct, click "OK" and you should then be able to succesfully connect to your MySQL server except now, through a secure tunnel!