Sunday, February 23, 2014

MySQL Related Set up Step such like Xtrabackup

On CentOS 5, we need libaio for MySQL server installation.
$ sudo yum install libaio

$ sudo rpm -ivh MySQL-server-5.5.31-2.rhel5.x86_64.rpm
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]
$ sudo rpm -ivh MySQL-shared-compact-5.5.31-2.rhel5.x86_64.rpm
Preparing...                ########################################### [100%]
   1:MySQL-shared-compat    ########################################### [100%]
$ sudo rpm -ivh MySQL-client-5.5.31-2.rhel5.x86_64.rpm
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]
We have to let MySQL use "Table Per File" mode. For example, the my.cnf mysql section setting is like:
[mysqld]
......
......
innodb_data_file_path = ibdata1:10M:autoextend
innodb_file_per_table = 1
datadir = /var/lib/mysql/datadir
innodb_data_home_dir = /var/lib/mysql/ibdatadir
innodb_log_group_home_dir = /var/lib/mysql/log
tmpdir = /var/lib/mysql/tmp
Then we should use the shell script to make the folder ready:
$cd /var/lib/mysql
$sudo mkdir datadir
$sudo mkdir ibdatadir
$sudo mkdir log
$sudo mkdir tmp
$sudo chown -R mysql:mysql /var/lib/mysql
The fresh New MySQL instance could be create by the following command.
$ sudo mysql_install_db
Alternatively you can run:
$/usr/bin/mysql_secure_installation
which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. The XtraBackup has different build based on Linux Kernel ang glic version. percona-xtrabackup-2.1.5-680.rhel6.x86_64.rpm is suitable to CentOS 6 percona-xtrabackup-2.1.5-680.rhel5.x86_64.rpm is suitable to CentOS 5 Don't try to upgrade the GLIBC's version in Linux Kernel otherwise the Kernel would be instable by change the Glibc. your can use the Linux command below to check the OS Release edition and MySQL's version:
rpm -qa | grep MySQL
rpm -qa | grep percona
cat /etc/*release
uname -a
  MySQL 5.1 is only supported by XtraBackup 2.0.8. Therefore, for older MySQL we need use previous version's XtraBackup. For MySQL 5.5+, XtraBackup 2.1.5 is OK. Here is the Installation Process:
$ rpm -ivh percona-xtrabackup-2.1.5-680.rhel6.x86_64.rpm
warning: percona-xtrabackup-2.1.5-680.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID cd2efd2a: NOKEY
error: Failed dependencies:
        perl(DBD::mysql) is needed by percona-xtrabackup-2.1.5-680.rhel6.x86_64
        perl(Time::HiRes) is needed by percona-xtrabackup-2.1.5-680.rhel6.x86_64
You can see the innobackupex.pm perl script require some package for running. Hence we should install the perl packages first:
sudo yum install perl-DBD-MySQL
sudo yum install perl-Time-HiRes
Then the installation of XtraBackup would be successful.
$ sudo rpm -ivh percona-xtrabackup-2.1.5-680.rhel6.x86_64.rpm
warning: percona-xtrabackup-2.1.5-680.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID cd2efd2a: NOKEY
Preparing...                ########################################### [100%]
   1:percona-xtrabackup     ########################################### [100%]
Just in case that list down the error message for CentOS5.
#CentOS 5 is too old and require more dependency for XtraBackup
$ rpm -ivh percona-xtrabackup-2.1.5-680.rhel6.x86_64.rpm
warning: percona-xtrabackup-2.1.5-680.rhel6.x86_64.rpm: Header V4 DSA signature: NOKEY, key ID cd2efd2a
error: Failed dependencies:
        libc.so.6(GLIBC_2.7)(64bit) is needed by percona-xtrabackup-2.1.5-680.rhel6.x86_64
        libc.so.6(GLIBC_2.8)(64bit) is needed by percona-xtrabackup-2.1.5-680.rhel6.x86_64
        perl(DBD::mysql) is needed by percona-xtrabackup-2.1.5-680.rhel6.x86_64
        rpmlib(FileDigests) <= 4.6.0-1 is needed by percona-xtrabackup-2.1.5-680.rhel6.x86_64
        rpmlib(PayloadIsXz) <= 5.2-1 is needed by percona-xtrabackup-2.1.5-680.rhel6.x86_64

Linux Hardware Information Collection Command

Recently, my most job context is related to Linux CentOS and MySQL with perl and python programming. However, when I install the MySQL server, there are some command could help me get more base information from the remote server that I am dealing with:
Show kernel version and system architecture
uname -a
Show name and version of distribution
head -n1 /etc/issue
Show all partitions registered on the system
cat /proc/partitions
Show RAM total seen by the system
grep MemTotal /proc/meminfo
Show CPU(s) info
grep "model name" /proc/cpuinfo
Show info about disk sda
hdparm -i /dev/sda

And after the hardware information, we use RPM command to review the package list on this machine:
rpm -qa | grep MySQL*
rpm -qa | grep percona*

If the some RPM package is missing from your wonder list, you could use yum command (with internet connection) or download the RPM package (be careful the Kernel version and OS distribution version) and use RPM command to install those dependencies:
rpm -ivh [wonder package]
For example, we need the crontab package for doing some schedule task on specific server. However, the crontabs require the cronie as dependency and cronie require sendmail as dependency and the dependent chaining is going further to procmail. Hence, below is the demonstration for installation of procmail, sendmain and final step with install crontabs related package at once (must have, because they seem to related in a cyclic check, you could not install single one of them without two others)

[root@ServerA ~]# rpm -ivh cronie-1.4.4-7.el6.x86_64.rpm
error: Failed dependencies:
        /usr/sbin/sendmail is needed by cronie-1.4.4-7.el6.x86_64
        dailyjobs is needed by cronie-1.4.4-7.el6.x86_64
[root@ServerA ~]# rpm -ivh sendmail-8.14.4-8.el6.x86_64.rpm
error: Failed dependencies:
        procmail is needed by sendmail-8.14.4-8.el6.x86_64

[root@ServerA ~]# rpm -ivh procmail-3.22-25.1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:procmail               ########################################### [100%]
[root@ServerA ~]# rpm -ivh sendmail-8.14.4-8.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:sendmail               ########################################### [100%]
[root@ServerA ~]# rpm -ivh cronie-anacron-1.4.4-7.el6.x86_64.rpm crontabs-1.10-33.el6.noarch.rpm cronie-1.4.4-7.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:crontabs               ########################################### [ 33%]
   2:cronie                 ########################################### [ 67%]
   3:cronie-anacron         ########################################### [100%]