Kloxo migration(Backup and restore)

Backup/Restore is a core part of Kloxo. You can take backup of your entire hosting and you can trivially restore it exactly on another server. In a cluster setup, you can take backup in one cluster configuration, and when restoring, you can tell Kloxo to re-arrange the resources on different servers.

Backup/Restore is also an extremely important aspect of web-hosting, and delivers peace of mind, and in fact, one of the main advantages of having a control Panel on your server.

This forum is dedicated to problems you experience vis-a-vis backup/restore, and we are committed to saving your data whatever be your configuration.

It is recommended, though not necessary, that both the source and destination Kloxo be the latest version, but Kloxo should be transparently able to handle older versions.

To take backup of your entire system:

 

 /script/backup --class=client --name=admin 

Kloxo is 100% hierarchical. So if you take the backup of a top level client, automatically every resource under him is included, including his clients, domains, ssl certificates, or whatever resources he has. In the above case, you are taking the backup for admin, which actually includes your entire hosting.

To restore:

 

 /script/restore --restore --accounts=all <backup-file-path>

To list the contents of a backup file.

 

 /script/restore --list <backup-file-path>

To restore only certain domains/clients

 cd /usr/local/lxlabs/kloxo/httpdocs/

 lphp.exe ../bin/common/restore.php --restore --accounts=domain:domain.com,client:clientname <backup-file-path>

If you have taken the backup under a specific client, and want to restore under the same client, you can provide the client’s class and name via –class and –name respectively. You have to first make sure that this client exists in the system. That is, you have to first add a client with the clientname, and then you can restore the backup under him.

 cd /usr/local/lxlabs/kloxo/httpdocs/

 lphp.exe ../bin/common/restore.php --class=client --name=clientname --restore <backup-file-path>

 

 

Installing Apache2 , Mysql server and PHP on Centos 6

How to install Apache , mysql and PHP on centos 6 

 

Update yum repositories and packages by typing the below command

[root@localhost ~]# yum update
After updating repositories , we can start installing packages one by one.
1. Apache2 installation and configuration
2. Mysql installation 
3. PHP installation 
4. Testing all together

Apache2 installation :

Apache2 package installation and configuration is very simple .

Step 1 » just type the command

[root@localhost ~]# yum install httpd

This command will install httpd package along with dependencies

After installing the package .

Step 2 » Open the file /etc/httpd/conf/httpd.conf .
Find “#ServerName http://www.example.com:80″ (line no : 276 ) .
#
#ServerName http://www.example.com:80

and add this line below  .  “ServerName youripaddress:80″

#
#ServerName http://www.example.com:80
ServerName 192.168.141.22:80

Step 3 » Now start apache service

[root@localhost ~]# service httpd start

and type this below command to start apache service automatically while booting.

[root@localhost ~]# chkconfig --levels 235 httpd on

Step 4 » Now you have successfully configured apache web server . open your browser and type the ip address in the address bar and hit enter . you can see the test page of your web server .

Install apache2 centos6

 

Testing your page:

Goto the default apache root path /var/www/html . create a new file index.html  and paste the below code and save it.

Welcome to my webserver

Again open the webserver ip address in the browser . you can see the index page created by you.

Installing apache2 centos

Mysql installation :

Step 1 » just type the command to install mysql server and client packages along with dependencies .

[root@localhost ~]# yum install mysql-server

After installation packages and  dependencies .

Step 2 » Start mysql service

[root@localhost ~]# service mysqld start

and type this below command to start mysql server automatically while booting.

[root@localhost ~]# chkconfig --levels 235 mysqld on

Step 3 » Create a new root password for mysqlserver

[root@localhost ~]# mysqladmin -u root password '********'

Step 4 » Test your mysql server by login as root

[root@localhost ~]# mysql -u root -p ( press enter )
Enter password:(Type your mysql root password and press enter)

Now you can see the mysql prompt.
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.61 Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

PHP installation :

Step 1 » Install php package along with php-mysql .
[root@localhost ~]# yum install php php-mysql
After installing php , create a php info file to test your php configuration .

Step 2 » Goto the default apache root path /var/www/html . create a new filephpinfo.php  and paste the below code and save it.

 
 
1
2
3
<?php
phpinfo();
?>  

Step 3 » Restart apache service

[root@localhost ~]# service httpd restart

Step 4 » open the filepath in the browser ( http://192.168.141.22/phpinfo.php ). you can see the php information page as below.

Installing php centos6

and make sure you can see the mysql details in the php information page .

Installing mysql php centos6

Finally apache2 , php and mysql has been configured perfectly . few more steps need to be performed to check the database connectivity.

Testing All together :

We need to test mysql database connectivity in php .

Step 1 » create a new file dbtest.php in the apache root path (/var/www/html) and paste the below code .Replace “password” with your mysql root password.

 
 
1
2
3
4
5
6
7
8
9
10
11
12
<?php
$con = mysql_connect(“localhost”,”root”,”password”);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
else
{
echo “Congrats! connection established successfully”;
}
mysql_close($con);
?>

Step 2 » open the filepath in the browser ( http://192.168.141.22/dbtest.php ). you can see the page as below.

testing apache2 mysql php

Congrats , you just made it

If you are getting some errors like

» Could not connect: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

( This means your mysql server service is stopped , you must start the service  “service mysql start”)

» Could not connect: Access denied for user ‘root’@’localhost’ (using password: YES)

(Something wrong with username and password )

if you are getting a blank page , then must be a problem with the code .

CloudFlare Plugin installation on cpanel

The CloudFlare cPanel plugin makes it easy to integrate into your hosting control panel. It takes less than 5 minutes to install on a test server and then the service is available to your end customers with two clicks.

 

Installation

Using an SSH client such as Terminal or Putty:

Step 1. Access cPanel for the server using root user by:

ssh root@SERVER IP ADDRESS or SERVER NAME

Step 2.

cd /usr/local/cpanel

Step 3.

curl -k -L https://github.com/cloudflare/CloudFlare-CPanel/tarball/master > cloudflare.tar.gz

Step 4.

tar -zxvf cloudflare.tar.gz

This extracts a directory that includes a UNIQUE ID. For example, the directory will be in this format:
cloudflare-CloudFlare-CPanel-d03f3b8
The UNIQUE ID is only: d03f3b8
The UNIQUE ID is not cloudflare-CloudFlare-CPanel-d03f3b8

Step 5.

cd cloudflare-CloudFlare-CPanel-UNIQUE ID/cloudflare/

Step 6.

./install_cf API HOST KEY mod_cf “YOUR COMPANY NAME”

example for Awesome Hosting Company: ./install_cf 56yt8x9s987dfy4324bnv mod_cf “Awesome Hosting”

Step 7. This will start the installation. cPanel is installed first, followed by mod_cloudflare. Depending on your server, it will take between 15 seconds and 4 minutes. You know it will be done when you see:
CloudFlare module installed successfully

Step 8. CloudFlare is now successfully added to this server. You need to repeat the process for each additional server (unless you have an automatic update script).

Best SysAdmin practices

Now that CloudFlare is installed, you can remove some of the unnecessary remnant files:

Step 9.

cd ../ ../

This takes you back two levels.

Step 10.

rm -rf cloudflare-CloudFlare-CPanel-UNIQUE ID*
To check if it is installed:
cat /etc/cloudflare.json

You should see an output with the following:

root@server1 [/usr/local/cpanel]# cat etc/cloudflare.json
{
 “host_key”:”32yt5a7b436tuy8974tre -”, (For security purposes, this will not be your host key.)
 “host_formal_name”:”Awesome Hosting”,
 “host_name”:”api.cloudflare.com”,
 “host_uri”:”/host-­gw.html”,
 “user_name”:”www.cloudflare.com”,
 “user_uri”:”/api_json.html”,
 “host_port”:”443”,
 “host_prefix”:”cloudflare-­resolve-­to”,
 “cp_version”:”1.3.0”
}

 

Disk Space Commands on Linux

Linux console is the best place for a system admin, some useful commands to check disk space on a linux system are:

Show files by size, biggest last:

ls -lSr

Show top disk users in current dir.

du -s * | sort -k1,1rn | head

Show free space on mounted filesystems

df -h

Show free inodes on mounted filesystems

df -i

Show disks partitions sizes and types

fdisk -l

List all packages by installed size (Bytes) on rpm distros

rpm -q -a –qf ‘%10{SIZE}\t%{NAME}\n’ | sort -k1,1n

Use Full tips to find out load issues on the Linux Server(Server with Cpanel as well)

Finding Load causing connections and users

Below are certail scripts the user that is causing the load and for finding the procees,ip which has high cpu usage.

To check number of IPs connected to port 80
# netstat -tn 2>/dev/null | grep ‘:80 ‘ | awk ‘{print $5}’ |sed -e ‘s/::ffff://’ | cut -f1 -d: | sort | uniq -c | sort -rn | head

To list number of connections to domains in the server
# /usr/bin/lynx -dump -width 500 http://127.0.0.1/whm-server-status | awk  ‘BEGIN { FS = ” ” } ; { print $12 }’ | sed ‘/^$/d’ | sort | uniq -c | sort -n

To list the Busiest Site in the server
# /usr/bin/lynx -dump -width 500 http://127.0.0.1/whm-server-status | grep GET | awk ‘{print $12}’ | sort | uniq -c | sort -rn | head

To list the Busiest Script running on the server
# /usr/bin/lynx -dump -width 500 http://127.0.0.1/whm-server-status | grep GET | awk ‘{print $14}’ | sort | uniq -c | sort -rn | head

To list the most running process in the server
# ps aux | awk ‘{print $1}’ | sort | uniq -c | sort -nk1 | tail -n5

To list the total process running by the users
# ps aux | awk ‘{print $1}’ | sort | uniq -c | sort -nk1

When we see the process in the top result with “php” or “/usr/bin/php”, we can find the directory it is working with. You can use,
# for i in `ps -ef | awk ‘/php/{print $2}’`; do ls -l /proc/${i}/cwd; done

We can even check this dynamically with in a particular time limit, say 5 sec. We can use it as below.
# while true; do clear; for i in `ps -ef | awk ‘/php/{print $2}’`;do ls -l /proc/${i}/cwd; done; sleep 5; done

How to monitor Linux Server

General Commands,
To check server load and which users are logged on the server with IP address you can fire this command
w
To check for the server load and watch for process
top
top –d2
top –c d2
Memory status
free –m
To see all processes running on the server
ps –aufx
With above commands you can which process is causing load on the server after that you can go with next steps.
If you see many processes of exim then you can check exim in more detail. shows the total no of email in qmail
exim –bpc
Print a listing of the messages in the queue
exim -bp
Following command will show path to the script being utilized to send mail
ps -C exim -fH eww
ps -C exim -fH eww | grep home
cd /var/spool/exim/input/
egrep “X-PHP-Script” * -R
Shows no of frozen emails
exim -bpr | grep frozen | wc -l
To remove FROZEN mails from the server
exim -bp | exiqgrep -i | xargs exim -Mrm
exiqgrep -z -i | xargs exim –Mrm
Check for spamming if anybody is using php script for sending mail through home
tail -f /var/log/exim_mainlog | grep home
If anyone is spamming from /tmp
tail -f /var/log/exim_mainlog | grep /tmp
To display the IP and no of tries done bu the IP to send mail but rejected by the server.
tail -3000 /var/log/exim_mainlog |grep ‘rejected RCPT’ |awk ‘{print$4}’|awk -F\[ '{print $2} '|awk -F\] ‘{print $1} ‘|sort | uniq -c | sort -k 1 -nr | head -n 5
Shows the connections from a certain ip to the SMTP server
netstat -plan|grep :25|awk {‘print $5′}|cut -d: -f 1|sort|uniq -c|sort -nk 1
To shows the domain name and the no of emails sent by that domain
exim -bp | exiqsumm | more
If spamming from outside domain then you can block that domain or email id on the server
pico /etc/antivirus.exim
Add the following lines:
if $header_from: contains “name@domain.com”
then
seen finish
endif
Catching spammer
Check mail stats
exim -bp | exiqsumm | more
Following command will show you the maximum no of email currently in the mail queue have from or to the email address in the mail queue with exact figure.
exim -bpr | grep “<*@*>” | awk ‘{print $4}’|grep -v “<>” | sort | uniq -c | sort -n
That will show you the maximum no of email currently in the mail queue have for the domain or from the domain with number.
exim -bpr | grep “<*@*>” | awk ‘{print $4}’|grep -v “<>” |awk -F “@” ‘{ print $2}’ | sort | uniq -c | sort -n
Check if any php script is causing the mass mailing with
cd /var/spool/exim/input
egrep “X-PHP-Script” * -R
Just cat the ID that you get and you will be able to check which script is here causing problem for you.
To Remove particular email account email
exim -bpr |grep “ragnarockradio.org”|awk {‘print $3′}|xargs exim -Mrm
If Mysql causing the load so you can use following commands to check it.
mysqladmin pr
mysqladmin -u root processlist
mysqladmin version
watch mysqladmin proc
If Apache causing the load so check using following commands.
netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort –n
netstat -an |grep :80 |wc –l
netstat -n | grep :80 | wc -l;uptime ; netstat -n | wc –l
netstat –tupl
pidof httpd
history | netstat
lsof -p pid
If mysql is causing load so you can check it using following commands.

mysqladmin -u root processlist
mysqladmin version
watch mysqladmin proc
mysqladmin -u root processlist

Other Useful Commands

To check ipd of php
pidof php
lsof -p pid
netstat -an |grep :80 |wc –l
netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n
netstat -na |grep :80 |sort
Use below mentioned command to get top memory consuming processes
ps aux | head -1;ps aux –no-headers| sort -rn +3 | head
Use below command to get top cpu consuming processes
ps aux | head -1;ps aux –no-headers | sort -rn +2 |more
You can check if any backup is going on, run the following commands

ps aux | grep pkg
ps aux | grep gzip
ps aux | grep backup
We can trace the user responsible for high web server resource usage by the folowing command
cat /etc/httpd/logs/access_log | grep mp3
cat /etc/httpd/logs/access_log | grep rar
cat /etc/httpd/logs/access_log | grep wav etc
cat /etc/httpd/logs/access_log | grep 408 can be used to check for DDOS attacks on the server.

cat /etc/httpd/logs/access_log | grep rar

how to recover mysql root password

Follow three easy steps  to recover mysql root password.
 
irst of all stop mysqld service

#service mysqld stop or /etc/init.d/mysqld stop

start with skip grant table option

#mysqld_safe –skip-grant-tables &

now login with root without any password

# mysql -u root

here you got it!
now for own safety change mysql root password

mysql> set password=PASSWORD(‘yourpasswd’);
mysql> flush privileges;

now stop mysql service and start it again