Skip to main content

Posts

Showing posts from October, 2014

MYSQL TO MARIA DB SWITCH

What is MariaDB ? MariaDB is a binary drop in replacement of the same MySQL version (for example MySQL 5.1 -> MariaDB 5.1, MariaDB 5.2 & MariaDB 5.3 are compatible. MySQL 5.5 will be compatible with MariaDB 5.5). What this means is that: * Data and table definition files (.frm) files are binary compatible. * All client APIs, protocols and structs are identical. * All filenames, binaries, paths, ports, sockets, and etc… should be the same. * All MySQL connectors (PHP, Perl, Python, Java, .NET, MyODBC, Ruby, MySQL C connector etc) work unchanged with MariaDB. * The mysql-client package also works with MariaDB server. * The shared client library is binary compatible with MySQL’s client library. *There are some installation issues with PHP5 that you should be aware of ( REF:https://mariadb.com/kb/en/installation-issues-with-php5 ). #mysqldump --all-databases --routines --triggers > /home/db_dump/alldb.sql # service mysql stop # cp -r /var/lib/mysql/my

MOUNT AND UMOUNT

To mount all file system mentioned in the /etc/fstab use mount -a The mountpoint can be binded to a new directory. So that you would be able to access the contents of a filesystem via more than one mountpoints at the same time. mount -B /mydir /mnt Mount allows you to access the contents of a mount point from a new mount point. Its nothing but move a mounted tree to another place. mount -M /mydir /mnt mount -n this wont update the data in /etc/mtab Lazy umount  umount -l  /mydir Forcefully umount -f /mydir to see the process holding the directory fuser -cu /mydir Mount an ISO image to a directory # mount -t iso9660 -o loop pdf_collections.iso /mnt # cd /mnt # ls perl/ php/ mysql/

FSCK file system check commands

How to perform fsck  It is simple. Umount the partition and issue the below command e2fsck -y /dev/hda1 Run fsck on all file system e2fsck -A -y Exclude the root with option R e2fsck -AR -y Specify the file system type using t fsck -AR -t ext2 -y Donot execute fsck on mounted partitions e2fsck -M /dev/hda1

INODE,METADATA,SUPERBLOCK

INODE A data structure that stores the below information about a file ---------------------------------- Size of file Device ID User ID of the file Group ID of the file The file mode information and access privileges for owner, group and others File protection flags The timestamps for file creation, modification etc link counter to determine the number of hard links Pointers to the blocks storing file’s contents ------------------------------------------------ Inode doesnot store the file name and it is stored seperately, greatest advantage is hardlink can be created for different file name sharing same inode. Meta data =========== Its data about a data. Suppose you own a vehicle there are registration and other details of the vehicle that is not the part of it. Metadata gives info like File name Owner Creation date Location on storage medium SUPER BLOCK ============ Metadata describes the structure of the file system. Most comm

Modsecurity block rule for XMLRPC and wp-login attack

SecAction phase:1,nolog,pass,initcol:ip=%{REMOTE_ADDR},initcol:user=%{REMOTE_ADDR},id:5000134  <Locationmatch "/wp-login.php">  SecRule user:bf_block "@gt 0" "deny,status:401,log,id:5000135,msg:'ip address blocked for 5 minutes, more than 10 login attempts in 3 minutes.'"  SecRule RESPONSE_STATUS "^302" "phase:5,t:none,nolog,pass,setvar:ip.bf_counter=0,id:5000136"  SecRule RESPONSE_STATUS "^200" "phase:5,chain,t:none,nolog,pass,setvar:ip.bf_counter=+1,deprecatevar:ip.bf_counter=1/180,id:5000137"  SecRule ip:bf_counter "@gt 10" "t:none,setvar:user.bf_block=1,expirevar:user.bf_block=300,setvar:ip.bf_counter=0"  </Locationmatch>  SecAction phase:1,nolog,pass,initcol:ip=%{REMOTE_ADDR},initcol:user=%{REMOTE_ADDR},id:5000234  <Locationmatch "/xmlrpc.php">  SecRule user:bf_block "@gt 0" "deny,status:401,log,id:5000235,msg:'ip address blocked for 5 m

CLOUDLINUX INSTALLATION

1) Download the cloud linux auto installer from  http://www.cloudlinux.com/downloads/index.php For cpanel servers, use the following steps a) For IP-based CloudLinux license # /usr/local/cpanel/cpkeyclt # /usr/local/cpanel/bin/cloudlinux_system_install -k b) For license key based CloudLinux ( for getting key go to  https://cln.cloudlinux.com/clweb/register.html  and register ) wget http://repo.cloudlinux.com/cloudlinux/sources/cln/cpanel2cl sh cpanel2cl -k $key 2) Now reboot your server into the Cloud linux kernel root@kate ~]# uname -r 2.6.18-374.12.1.el5.lve0.8.54 It have few issues with the RAM memory so we need to install PAE kernel for the Cloud linux yum install kernel-PAE-2.6.18-374.12.1.el5.lve0.8.54 after installing the Cloud linux kernel we will get the kernel as And reboot the server. root@kate ~]# uname -r 2.6.18-374.12.1.el5.lve0.8.54PAE Then Recompile apache using /scripts/easyapache 3) Install the lve cPanel modules and Plugin as follows, yum -y

MYSQL MARIADB CONVERSION

Here are some steps for MYSQL to MARIADB conversion   MariaDB is a binary drop in replacement of the same MySQL version. MySQL 5.1 -> MariaDB 5.1 MariaDB 5.2 & MariaDB 5.3 are compatible. MySQL 5.5 >> MariaDB 5.5 Which means: Data and table definition files (.frm) files are binary compatible. All client APIs, protocols and structs are identical. All file names, binaries, paths, ports, sockets, and etc… should be the same. All MySQL connectors (PHP, Perl, Python, Java, .NET, MyODBC, Ruby, MySQL C connector etc) work unchanged with MariaDB. The mysql-client package also works with MariaDB server. The shared client library is binary compatible with MySQL’s client library. We can just uninstall MySQL and install MariaDB easly. (No need to convert any data files if you use same main version, like 5.1). We will have to [perform mysql_upgrade after conversion. This is to ensure that the mysql privilege and event tables are updated with the new fields MariaDB

Whitelist against Mod security block

Add below line in /usr/local/apache/conf/whitelist.conf SecRule SERVER_NAME "contestant.theiifymchallenge.com.au" phase:1,nolog,allow,id:445023,ctl:ruleEngine=off Give alternate "id " Check in /usr/local/apache/conf/modsec2.conf whether below include line is added : Include "/usr/local/apache/conf/whitelist.conf" httpd -t  check for any syntax error, if not proceed with apache restart restart httpd

Backup before UPCP

cp /etc/exim.conf /etc/exim.conf-`date +%F` cp /etc/exim.conf.dist /etc/exim.conf.dist.`date +%h-%d-%y-%s` cp /etc/exim.conf.local /etc/exim.conf.local-`date +%F` cp /etc/exim.conf.localopts /etc/exim.conf.localopts-`date +%F` cp -arf /etc/exim /etc/exim-`date +%F` cp /etc/exim.pl /etc/exim.pl-`date +%F` cp -arf /etc/mail/spamassassin /etc/mail/spamassassin-`date +%F` cp -arf /usr/local/cpanel/etc/exim /usr/local/cpanel/etc/exim-`date +%F` Take the backup of MYSQL version and library also.  

Backup Before Easy apache

All we know the cPanel will revert the changes, if easyapache fails. So this step is not mandatory, but a good sys admin always keep a backup before he does anything. =========================================== 1. Take a backup of apache and php configuration files. mkdir /root/back cp -a /usr/local/apache/conf /root/back cp -a /usr/local/lib/php.ini /root/back 2. Keep a list if the Apache and php modules enabled in the server. touch /root/back/modules_list php -v >> /root/back/modules_list php -m >> /root/back/modules_list httpd -v >> /root/back/modules_list httpd -M >> /root/back/modules_list ============================================

Migrate cPanel accounts using command line

Here I am gonna shed some light on the cPanel account Migration. Its simple, issue some scripts and let the server do it. Suppose we need to move the cPanel accounts between servers. All we need to list the account usernames in the file test.txt. It would be like user1 user2 user3 Okay. Add sshkey in the Destination server, so that it makes the secure copy and ssh easier. Run this in a screen =================================================== for i in `cat test.txt`; do /scripts/pkgacct $i; scp /home/cpmove-$i.tar.gz root@destinationIP:/home/; ssh root@destinationIP "/scripts/restorepkg /home/cpmove-$i.tar.gz"; done | tee transferresult.txt =================================================== tee command can show up the result in a file. You can also set cpuwatch if required. This will keep the CPU load on the server =================================================== for i in `cat test.txt`; do  /usr/local/cpanel/bin/cpuwatch N   /scripts/pkgacct