Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Friday, 31 January 2014

[FIXED]"MySQL is running but PID file could not be found" error


While restarting MySQL service, you may get the error below ,
"MySQL is running but PID file could not be found"
In order to to fix this error , Lets try to do the below steps,

1) Create the directory " var/run/mysql ".
# mkdir /var/run/mysql
2) Now create  file " mysqld.pid " .
# touch mysqld.pid
3) change its ownership of " mysqld.pid " to "mysql:mysql "
# chown mysql:mysql mysqld.pid
4) Restart MySQL service by,
# /etc/init.d/mysql start
That's it, try this and let me know you've get the result. :-)

[FIXED] "(20014)Internal error: Error retrieving pid file logs/httpd.pid Remove it before continuing if it is corrupted." while starting Apache/httpd.


 " (20014)Internal error: Error retrieving pid file logs/httpd.pid
Remove it before continuing if it is corrupted.
"

If you see the above  Error while stopping httpd/Apache , Just do the following steps ,

1) change the directory to  " /usr/local/apache/logs " .
# cd /usr/local/apache/logs

2) remove/rename the file "httpd.pid" ,by

# mv httpd.pid httpd.pid.bak

3) just stop and restart the Httpd , by

# /etc/init.d/httpd start
4) now check the status of  Apache/httpd by,

# /etc/init.d/httpd status

That's it. :-) 

Wednesday, 29 January 2014

[FIXED] How to Change Ubuntu/Lubuntu's Root password using "sudo command"

After installing Ubuntu/LUbuntu ,we could able to login through a user ,we didn't have the root privillage at that time.

If you want to gain the root privilege we have to know the Root password , but we haven't 

Just do the below commands to gain root privilege ,

1) open  terminal/console.

2) type the command ,

$ sudo su

you want to enter your password, type your password.

stebu@DareLegacy:~$ sudo su
[sudo] password for stebu: 


3)Change the root password by,

# passwd

 root@DareLegacy:/home/stebu# passwd 
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
root@DareLegacy:/home/stebu# 

Type your New password.

That's it. Now you can run as root. :-)
  

Executing Script/commands Using "alias command "

The alias command makes it possible to launch any command or group of commands,It allows a user to create simple names or abbreviations (even consisting of just a single character) for commands regardless of how complex the original commands are and then use them in the same way that ordinary commands are used.

Synax :
$ alias [-p] [name="value"]

In order to assign a lengthy command to a single character ,type

# alias <your_desired_string>="<command>"
 
example:
          # alias a="ls -l"

If you want make a alias for a script , type

$ alias <character>="sh <script_name>"
Example:

$ alias 1="sh exim.sh"
Multiple commands can be included in the same alias by inserting them within the same pair of quotation marks and separating them with semicolons(;). For example, the alias sp could be created to first launch hostname and then immediately launch hostname -i :
$ alias sp='hostname;hostname -i'

Now you can run the "Script/command" by typing the alias of it.
That's it. :-)


Change Cpanel default port.

We can  change Cpanel default port by editing the file " /var/cpanel/cpanel.config " .

 # vi  /var/cpanel/cpanel.config
Change  the below value to desired port ,

port=2082
  
This will change the  default Cpanel port, then run the below commands ,

# /usr/local/cpanel/whostmgr/bin/whostmgr2 --updatetweaksettings
# /etc/init.d/httpd restart

That's it :-)

Monday, 27 January 2014

SSH Login Without Password

Login to the Remote server via SSH  without password using ssh-keygen & ssh-copy-id.

"ssh-keygen creates the public and private keys. ssh-copy-id copies the local-host’s public key to the remote-host’s authorized_keys file. ssh-copy-id also assigns proper permission to the remote-host’s home, ~/.ssh, and ~/.ssh/authorized_keys. "
1) Generates ssh-key using ssh-keygen

$ ssh-keygen

Hit ENTER

2) Copy the public key to remote-host using ssh-copy-id


$ ssh-copy-id username@ipaddress -pXXXX


Here,

username - Type the username of remote host
ipaddress - Type IP address of remote host.
XXXX     - Type port number if any,(ignore " -pXXX " if the remote sever has no ssh port)

Note : You need to Enter a one-time password.That's it.

Now login to the remote server without password. :-)

Saturday, 25 January 2014

How to Backup Cpanel Reseller's Domains via Command

If you want to backup the domains under a reseller account in the server,It will be difficult to backup 100+ domains under the reseller account .

In order to backup Cpanel Reseller's Domains via script , Just do following two steps.

1) This command will generate the list of users under the reseller 'reseller'.
# cat /etc/trueuserowners | grep reseller | cut -d: -f1 > reseller_list.txt
Note : The file /etc/trueuserowners shows which reseller owns each account.


Now "reseller_list.txt" generated in your " pwd " contains the list of users under the reseller named ' reseller'.

To backup the domains under the reseller to a path /backup, you can execute the command :
# for i in `cat reseller_list.txt` ; do /scripts/pkgacct $i /backup; done

That's it . :-)

Friday, 24 January 2014

Reducing CPU Load in Server

Initial Check up :

To print the cpu load
# cat /proc/loadavg

To see the No: of user logged in server ,
#

To see the uptime and load average
# uptime

To see live process running
# top -c

To print  process current process
# ps aux

To filter user/process/pid from process, type
# ps aux | grep <user/process/pid>

If the cpu load is controllable ,just check the process list and filter the user which taking more resource of the server.

To kill the Process Id(PID) by
# pkill -9 <PID>

To kill the user By
# pkill -9 -u <username>

To kill the service , type
# killall -9 <service>
 Example:  # killall -9 php


To kill a file , type

# fuser -k <file_path>

Example:   # fuser -k  /usr/bin/php


Following command will find top 5 users in server.

# ps faux |grep -i 'p[h]p\|.pl\|perl\|dispatch' | grep -v 'ftp\|imap\|nobody\|mailnull\|root\|mysql\|cpanel\|32004\|32021' |  awk '{print $1}'  | sort | uniq -c | sort -nr | head -n 5

Following command will kill top 2 users in server


# for i in `ps faux |grep -i 'p[h]p\|.pl\|perl\|dispatch' | grep -v 'ftp\|imap\|nobody\|mailnull\|root\|mysql\|cpanel\|32004\|32021' |  awk '{print $1}'  | sort  | uniq -c  | sort -nr |head -n 2|awk '{print$2}'` ; do echo $i; killall -u $i; cat /proc/loadavg ; done


If the sever load is high , execute the commands

To kill the process using for loop ,

# for i in { 1..100 } ; do killall -9 php ; cat /proc/loadavg ; done
 or
 # for i in { 1..100 } ; do fuser -k /usr/bin/php ; cat /proc/loadavg ; done

In some cases ,users/process in the server may be the cause for server load , filter the user and run the command,
# ps aux | grep <user/process_name> | awk {'print $2'} | xargs kill -9 
If the server load is again increasing , stop the service which using  the server resource load , By executing the command ,

# /etc/init.d/<service> stop
Example:  # /etc/init.d/exim stop

The above command is not recommended to execute , Examine the process and block the unwanted   IPs.


Command to find sorted memory usage in server,

 # ps aux | awk '$11!~/\[*\]/ {print $6/1024" Mb --> "$11,$12,$13,$14}' | sort -g

 Troubleshooting wait average [Amount of time the CPU has been waiting for I/O to complete.]

# for x in `seq 1 1 10`; do ps -eo state,pid,cmd | grep "^D"; echo "----"; sleep 5; done 

Important - PLEASE do the below command if the load is increasing heavily ,

# ps aux |egrep "clam|php|find|maldet|exim|spam|lfd" | awk '{print $2}' | xargs kill -9

The above command will kill the processes specified in "egrep command" , add or remove the process according to the status of the server .


Please give the name in the '<user>' field of below script  to get process run by the user:


# user=<username> ;for blah in seq; do echo ; uptime;echo; echo "Running Proceses:" ;echo;for pass in 1 2 3 4; do echo "---Pass $pass---"; x=1 ; while [ $x -lt 2 ]; do ps faux | grep "^${user}" ; [ $? -eq 0 ] && echo "The above processes were found to be running for user ${user} when this was executed by  Stebu Johny during each pass at a 2 second interval `date` ..." || echo "No processes were found to be running for user ${user} when this was executed by  Stebu Johny during each pass at `date` ..."; sleep ".2"; let x++ ;done;echo;sleep 2;done; echo "MySQL Processes:";mysqladmin proc --verb | grep "${user}_" | perl -p -e 's/\s+\|/\|/g' | grep "" ; [ $? -eq 0 ] && echo "The above queries were found to be running for user ${user} when this was executed by  Stebu Johny at `date` ..." || echo "No queries were running for user ${user} when this was executed by  Stebu Johny at `date` ..."; echo $'\n'; echo "Incoming Connections:"; lynx --dump --width=10000 localhost/whm-server-status | grep "GET\|POST" | awk '{print $11,$12,$14}' | column -t | sort | grep "/~$/|Client\|$(grep ": ${user}$" /etc/userdomains | cut -d : -f1 | cut -c 1-31)"; echo; echo; done











Thursday, 23 January 2014

Create MySQL database via SSH


We can create MySQL databases  through two ways :

phpmyadmin 
or 
 through the SSH command line
how to create a MySQL database with SSH command

1) First log in to mysql with your user name (change if not root). You will be prompted for a password.
mysql  -p
2)  create the database with a unique name
CREATE DATABASE <new_database>;

3) If you want to give the other_user all the privileges, type the command:
GRANT ALL PRIVILEGES ON <new_database.>* to other_user@localhost;
4)Then, type:

flush privileges;

5) Now the other user can log in and access the database with the command

mysql -u other_user -p'passwd' new_database

Wednesday, 22 January 2014

How to change Cpanel password of all Users In the Server Via SSH

Scripts to change Cpanel password of all Users In the Server,

1)  Login to the server as root

2)  Run the following Command ,
# for i in `cat /etc/trueuserdomains | awk '{print $2}'`  ; do j=$(openssl rand -base64 10);  /scripts/chpass $i $j; echo "$i : $j" >> /root/accountdetails; done

3) That's it .. :-)

Note: This command will change all user's cpanel password instantly ,please be beware before using it.

thanks to sanju jagan for this Script. :-)

Tuesday, 21 January 2014

How to change cPanel password via SSH

If you do not have access to WHM then the cPanel password for a particular account can be updated from shell.
The following steps should help you to change / reset /update cPanel password of particular account from shell    

1) Access the server as a root user through SSH

2) Execute following command
 # /scripts/chpass <username> <password>

Thats it. :-) 

Backup and Restore a Domain account via SSH

How to Backup an account via SSH

In some situations, the account can also be backed up via SSH.
Every CPanel server comes with scripts that can be executed via SSH.


For this case we will use the script pkgacct from the /scripts folder on your server.
1. Log into your server by using SSH
2. Execute the CPanel script for the account backup:
# /scripts/pkgacct <username>
(replace the username with the actual account username that you are going to backup)
The screen output will look similar to this:
Copying domain Config…DoneCopying Mail files….DoneCopying proftpd file….DoneCopying www logs…DoneGrabbing mysql dbs…DoneGrabbing mysql privs…DoneCopying mailman lists….DoneCopying mailman archives….DoneCopying homedir….Done
3. The backup file will be placed in the users home directory.
You can now access the file and copy or move it to your backup drive or download it via ftp.

How to restore a Domain Account via SSH

1. Upload or copy the backup file (Example File Name: cpmove-joeuser.tar.gz) to the domain account             Home directory via FTP.
2. Log into your server by using SSH
3. Execute the appropriate CPanel script for the account restoration:
# /scripts/restorepkg <username>
(replace username with the domain account username)
(make sure that the file name matches the necessary naming convention – follow the naming scheme seen in our example)
This will restore the domain account from the backup, as well as it will create the CPanel account.. Please test accordingly..

Basic Linux Server Administration Commands


1. Uptime Command

In Linux uptime command shows since how long your system is running and the number of users are currently logged in and also displays load average for 1,5 and 15 minutes intervals.
# uptime
2. W Command

It will displays users currently logged in and their process along-with shows load averages. also shows the login name, tty name, remote host, login time, idle time, JCPU, PCPU, command and processes.
# w
Available options:
-h : displays no header entries.
-s : without JCPU and PCPU.
-f : Removes from field.
-V : (upper letter) – Shows versions.

3. Users Command

Users command displays currently logged in users. This command don’t have other parameters other than help and version.
# users
4. Who Command

who command simply return user name, date, time and host information. who command is similar to w command. Unlike w command who doesn’t print what users are doing. Lets illustrate and see the different between who and w commands.
# who
Who command Options:

-b : Displays last system reboot date and time.
-r : Shows current runlet.
-a, –all : Displays all information in cumulatively.

5. Whoami Command

whoami command print the name of current user. You can also use “who am i” command to display the current user. If you are logged in as a root using sudo command “whoami” command return root as current user. Use “who am i” command if you want to know the exact user logged in.
# whoami
6. ls Command

ls command display list of files in human readable format.
# ls -l
Sort file as per last modified time.
# ls -ltr
7. Crontab Command

List schedule jobs for current user with crontab command and -l option.
# crontab -l
Edit your crontab with -e option. In the below example will open schedule jobs in VI editor. Make a necessary changes and quit pressing :wq keys which saves the setting automatically.
# crontab -e
8. Less Command
less command allows quickly view file. You can page up and down. Press ‘q‘ to quit from less window.
# less install.log
9. More Command

more command allows quickly view file and shows details in percentage. You can page up and down. Press ‘q‘ to quit out from more window.
# more install.log
10. CP Command

Copy file from source to destination preserving same mode.
# cp -p fileA fileB
You will be prompted before overwrite to file.
# cp -i fileA fileB
11. MV Command

Rename fileA to fileB. -i options prompt before overwrite. Ask for confirmation if exist already.
# mv -i fileA fileB
12. Cat Command

cat command used to view multiple file at the same time.
# cat fileA fileB
You combine more and less command with cat command to view file contain if that doesn’t fit in single screen / page.
# cat install.log | less
# cat install.log | more
13. Cd command (change directory)

with cd command (change directory) it will goes to fileA directory.
# cd /fileA
14. pwd command (print working directory)

pwd command return with present working directory.
# pwd
15. Sort command

Sorting lines of text files in ascending order. with -r options will sort in descending order.
#sort fileA.txt
#sort -r fileA.txt
16. VI Command

Vi is a most popular text editor available most of the UNIX-like OS. Below examples open file in read only with -R option. Press ‘:q‘ to quit from vi window.
# vi -R /etc/shadows
17. SSH Command (Secure Shell)

SSH command is used to login into remote host. For example the below ssh command will connect to remote host (192.168.50.2) using user as narad.
# ssh <user_name>@192.168.50.2
To check the version of ssh use option -V (uppercase) shows version of ssh.
# ssh -V
18. Ftp or sftp Command

ftp or sftp command is used to connect to remote ftp host. ftp is (file transfer protocol) and sftp is (secure file transfer protocol). For example the below commands will connect to ftp host (192.168.50.2).
# ftp 192.168.50.2
# sftp 192.168.50.2
Putting multiple files in remote host with mput similarly we can do mget to download multiple files from remote host.
# ftp > mput *.txt
# ftp > mget *.txt
19. Service Command

Service command call script located at /etc/init.d/ directory and execute the script. There are two ways to start the any service. For example we start the service called httpd with service command.
# service httpd start
OR
# /etc/init.d/httpd start
20. Free command
Free command shows free, total and swap memory information in bytes.
# free
Free with -t options shows total memory used and available to use in bytes.
# free -t
     
21. Top Command

top command displays processor activity of your system and also displays tasks managed by kernel in real-time. It’ll show processor and memory are being used. Use top command with ‘u‘ option this will display specific User process details as shown below. Press ‘O‘ (uppercase letter) to sort as per desired by you. Press ‘q‘ to quit from top screen.
# top -u <username>
22. Tar Command
tar command is used to compress files and folders in Linux. For example the below command will create a archive for /home directory with file name as archive-name.tar.
# tar -cvf archive-name.tar /home
To extract tar archive file use the option as follows.
# tar -xvf archive-name.tar

23. Grep Command

grep search for a given string in a file. Only tecmint user displays from /etc/passwd file. we can use -i option for ignoring case sensitive.
# grep <string_to_search> /etc/passwd
24. Find Command

Find command used to search files, strings and directories. The below example of find command search tecmint word in ‘/‘ partition and return the output.
# find / -name <string>
25. lsof Command

lsof mean List of all open files. Below lsof command list of all opened files by user tecmint.
# lsof -u tecmint
26. last command

With last command we can watch user’s activity in the system. This command can execute normal user also. It will display complete user’s info like terminal, time, date, system reboot or boot and kernel version. Useful command to troubleshoot.
# last
You can use last with username to know for specific user’s activity as shown below.
# last <username>
27. ps command
ps command displays about processes running in the system. Below example show init process only.
# ps -ef | grep init
28. kill command

Use kill command to terminate process. First find process id with ps command as shown below and kill process with kill -9 command.
# ps -ef | grep init
root         1     0  0 07:53 ?        00:00:04 /sbin/init
root      7508  6825  0 11:48 pts/1    00:00:00 grep init

# kill- 9 7508
29. rm command

rm command used to remove or delete a file without prompting for confirmation.
# rm filename
Using -i option to get confirmation before removing it. Using options ‘-r‘ and ‘-f‘ will remove the file forcefully without confirmation.
# rm -i test.txt
30. mkdir command

mkdir command is used to create directories under Linux.
# mkdir directoryname

Install / Enable PHP MsSQL Extension in cPanel/WHM Server

If there is a requirement for MsSQL extension on cPanel/WHM server, you need to install it manually by following the steps listed below.

You need to install a few modules before installing the MsSQL extension.
1. unixODBC
2. freeTDS
3. mssql.so
Do not use rpms as it will show lots of dependency errors. Better download the source file and compile it.

Install unixODBC package

1. Get the source from here

2. tar -xvf unixODBC-2.2.12.tar.gz

3. Now use the following command to configure.

./configure -prefix=/usr/local -enable-gui=no

Please note that if you use enable-gui option as yes and dont have Qt package, you will get the error. So make sure you use it as no.

4. make

5. make install

Install freeTDS package

1. Download from ftp://ftp.freetds.org/pub/freetds/old/0.82/freetds-0.82.tar.gz (Note that if you are using a latest version of freetds, sometimes you may get an error while trying to run the configure with unixODBC option. So I have to use an older version 0.82.)

2. tar -xvf freetds-0.82.tar.gz

3. ./configure -with-tdsver=8.0 -with-unixODBC=/usr/local

4. make

5. make install

Configure freeTDS

1. Locate the freetds.conf and add the following entries.

[MSHOSTNAME]
host = MSHOSTNAME
port = 1433
tds version = 8.0

Generating mssql.so

In cPanel servers the extensions are located at /home/cpeasyapache/src/php-x.x.x/ext. Navigate to the above directory and then to mssql directory.

cd /home/cpeasyapache/src/php-x.x.x/ext/mssql

phpize
./configure
make
make install

The above commands will generate a copy of mssql.so in the installed extensions directory. Check and make sure that mssql.so is there and add the following to php.ini

extension=”mssql.so”

Restart httpd and check the modules using the following command.

php -m | grep mssql

or

You can create a phpinfo page with the following contents and search for mssql.

<?

phpinfo();

?>

Thats it. :-) 

Friday, 17 January 2014

Exim - Find Spammer

Steps to find the Orgin Of Spam Mails

Find the Total Queue on Exim
#exim -bpc
To get the sorted list of mails from domain
#  exim -bp | exiqsumm -c | head
To get a sorted list of email sender in exim mail queue,below command will show you the number of mails send by each one,
# exim -bpr | grep "<" | awk {'print $4'} | cut -d "<" -f 2 | cut -d ">" -f 1 | sort -n | uniq -c | sort -n
You will get a result as like follows,

1 mridul@testdomain.com

2 prasanth@test1domain.com

3 nithin@test123.com

4 stebu@testdomain.co.in

29 eljo@testdomain.in

124 hacker@test123domain.com

Print the total mails from the e-mail Id,
# exiqgrep -f <e-mail@domain> -i | wc -l
To print the mail Ids from the e-mail Id,
# exiqgrep -f <e-mail@domain> -i
You'll get mail Ids ,from the list Open one or two mails using the command,

# exim -Mvh <e-mail_ID >
# exim -Mvb <e-mail_ID >
# exim -Mvl <e-mail_ID >
 You'll get " auth_id "  from the mail header , If the user is spammer ,we want to stop it by changing  E-mail password of the authenticated user_e-mail id/domain.

spamming will definitely stop now , If it won't work  evaluate the  "exim_main log"
# tail -f /var/log/exim_mainlog | grep login
We can see the current spamming going through Exim ,Evaluate the log and check who is currently spamming , you 'll get a IP adress which is used for spamming , block IP by,
# csf -d <IP_address>  
Suspend the User for the securing the server.


To remove the mails from a specific user,type
# exiqgrep -f <e-mail@domain> -i | xargs exim -Mrm

To remove mailnull(<>) mails from the mail queue , type
exiqgrep -f "<>" -i | xargs exim -Mrm


If the spammer is sending mails using scripts :


Check mail log to know which home directory is used for spamming,

# tail -f /var/log/exim_mainlog|grep home

The following scripts will check the script that will originate spam mails:

# grep "cwd=/home" /var/log/exim_mainlog | awk '{for(i=1;i<=10;i++){print $i}}' | sort | uniq -c | grep cwd | sort -n
# awk '{ if ($0 ~ "cwd" && $0 ~ "home") {print $3} }' /var/log/exim_mainlog | sort | uniq -c | sort -nk 1
# grep 'cwd=/home' /var/log/exim_mainlog | awk '{print $3}' | cut -d / -f 3 | sort -bg | uniq -c | sort -bg
You will get a result as like follows for the first two scripts. The third script is just a sub of the first two scripts.
9 cwd=/home/test1/public_html10 cwd=/home/test2/public_html/a1/www15 cwd=/home/test3/public_html91 cwd=/home/test4/public_html178 cwd=/home/test5/public_html/web770 cwd=/home/test6/public_html/foro803 cwd=/home/test7/public_html/web124348 cwd=/home/test8/public_html/wp/wp-content/themes/twentyeleven
If we need to find out exact spamming script. The following script will shows the current spamming script running now. The following script will help you in all time of mail servers. It will help you to find the exact script which sending mails.
# ps auxwwwe | grep <user> | grep --color=always "<location of script>" | head
The usage of the above script is as shown below.
# ps auxwwwe | grep test8 | grep --color=always "/home/test8/public_html/wp/wp-content/themes/twentyeleven" | head
Once you find the exact script, the following script will help you to find the IP address which is responsible for spamming. You will get a list of IPs from the following script. The IPs address which has high number of access is most probably causing spamming. You can block the IP address in csf or apf firewall.
# grep "<script_name>" /home/user/access-logs/testdomain.com | awk '{print $1}' | sort -n | uniq -c | sort -n
Following command that will show you the script which is using script to send the email. If it is from php then use
# egrep -R "X-PHP-Script"  /var/spool/exim/input/*
It shows top 50 domains using mail server with options.
# eximstats -ne -nr /var/log/exim_mainlog
It shows from which user’s home the mail is going, so that you can easily trace it and block it if needed.it shows the mails going from the server.
# ps -C exim -fH ewww | grep home
It shows the IPs which are connected to server through port number 25. It one particular Ip is using more than 10 connection you can block it in the server firewall.
# netstat -plan | grep :25 | awk {'print $5'} | cut -d: -f 1 | sort | uniq -c | sort -nk 1
In order to find “nobody” spamming, issue the following command
# ps -C exim -fH ewww | awk '{for(i=1;i<=40;i++){print $i}}' | sort | uniq -c | grep PWD | sort -n
 It will give some result like:

Example :
6 PWD=/
347 PWD=/home/sample/public_html/test
Count the PWD and if it is a large value check the files in the directory listed in PWD
(Ignore if it is / or /var/spool/mail /var/spool/exim)

The above command is valid only if the spamming is currently in progress. If the spamming has happened some hours before, use the following command.
# grep "cwd=" /var/log/exim_mainlog | awk '{for(i=1;i<=10;i++){print $i}}' | sort | uniq -c | grep cwd | sort -n

To remove bounced emails from the server

  • # cd /var/spool/exim/input
  • # find . -type f -iname ‘*’ -exec grep -li "Failed" {} \; -exec rm {}\;

To remove all messages from the queue, enter:


# exiqgrep -i | xargs exim -Mrm
or 
# exim -bp | awk '/^ *[0-9]+[mhd]/{print "exim -Mrm " $3}' | bash
Or

Open a new screen using Screen command

# screen

change directory by ,

# cd /var/spool/exim/input/

remove all directories to clear entire Queue,

# rm -rf *

That's it ,Entire mail queue will clear by this. :-)

Full XEN VPS Migration

This guide has been written to aid you in SAFELY transfering Xen PV & HVM virtual servers between nodes.

Creating a Copy of the Virtual Server

We need to find the correct LV that needs backing up. You do this by issuing lvdisplay in ssh on the source node:

[root@herculis ~]# lvdisplay

--- Logical volume ---
LV Name /dev/vps/vm1010_img
VG Name vps
LV UUID pFtowh-vnxa-DXeE-KqqZ-N1h1-IQ2z-4VFSad
LV Write Access read/write
LV Status available
# open 0
LV Size 10.00 GB
Current LE 160
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:52
 --- Logical volume ---
LV Name /dev/vps/vm1010_swap
VG Name vps
LV UUID iBGJKk-do9U-5tGM-fqZT-fD1U-Ejqa-Dih3VT
LV Write Access read/write
LV Status available
# open 0
LV Size 256.00 MB
Current LE 4
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:53
vm1010 is the vps we need to backup so we now have the LV details we need.

Next we need to find some space on the the server to make the backup to. If you have enough space on the normal / partition you can put the backup there but in most cases you won't ,so you need to create an LV to put the backup into:
# lvcreate -n vm1010_backup --size 15G /dev/vps
We created an new LV called vm1010_backup with a size 5GB bigger than the source LV.

Now format the new LV and mount it:
# mkfs.ext3 /dev/vps/vm1010_backup
# mkdir -p /home/vm1010_backup
# mount /dev/vps/vm1010_backup /home/vm1010_backup
Next we need to shutdown the source vps either using SolusVM or the commandline:
# xm shutdown vm1010
Now its time to create the backup:
# dd if=/dev/vps/vm1010_img of=/home/vm1010_backup/vm1010_backup.img
When complete the backup will be stored in /home/vm1010_backup:
# ls -lh /home/vm1010_backup
-rw-r--r-- 1 root root 10G May 29 00:10 vm1010_backup.img
Transfer to the destination node

On the destination node you need to create a set of LV's for the backup and the new vps:
# lvcreate -n vm1010_backup --size 15G /dev/vps
# lvcreate -n vm1010_img --size 10G /dev/vps
The following is only for xen pv:
# lvcreate -n vm1010_swap --size 256M /dev/vps
# mkswap /dev/vps/vm1010_swap
Mount the LV on the destination node for the backup:
# mkfs.ext3 /dev/vps/vm1010_backup
# mkdir -p /home/vm1010_backup
# mount /dev/vps/vm1010_backup /home/vm1010_backup
Transfer the backup to the destination server:
# scp -C /home/vm1010_backup/vm1010_backup.img root@remote.server.com:/home/vm1010_backup/
Restoring the Virtual Server

Once the transfer is complete we can restore the backup to the new LV:
# dd if=/home/vm1010_backup/vm1010_backup.img of=/dev/vps/vm1010_img
Updating SolusVM and Starting the Virtual Server
When the restore is complete you need to update SolusVM so it knows where the vps has been moved to.
In SSH on your master do the following:
# /scripts/vm-migrate <VSERVERID> <NEWNODEID>
<VSERVERID> is the ID listed in your VM list in SolusVM <NEWNODEID> is the ID of the node listed in your node list in SolusVM

Example moving vserverid 150 to node 4:
# /scripts/vm-migrate 150 4
All you need to do now is boot up the vps on the new node by clicking the reboot button within SolusVM. You must use the reboot button so it writes a new configuration file on the new slave.
# Cleanup
When you have confirmed the vps has been moved and is up and running on the new slave you need to remove any LV's and mount points you made.

On the source node:
# umount /home/vm1010_backup
# lvremove /dev/vps/vm1010_backup
# lvremove /dev/vps/vm1010_img
# lvremove /dev/vps/vm1010_swap
On the destination node:
# umount /home/vm1010_backup
# lvremove /dev/vps/vm1010_backup

OpenVZ ntpdate Problem



Issue :

Some of OpenVZ containers, on servers that may have problems it will show "Can't adjust the time of day: Operation not permitted " . Well,its not a big deal,

ntpdate ri.ntp.carnet.hr
ntpdate[22082]: Can't adjust the time of day: Operation not permitted

Solution:

On HW host:

/usr/sbin/vzctl stop  <ctid>
 /usr/sbin/vzctl set <ctid>  --capability sys_time:on  --save
/usr/sbin/vzctl start  <ctid>

Check if everything is working now:

ntpdate ri.ntp.carnet.hrntpdate[3238]: adjust time server 161.53.30.170 offset -0.142383 sec

Thursday, 16 January 2014

Parked Domain

What is a Parked Domain? How Do I Create and Delete One?

Parked domains are often used by businesses that want to have more than one web address for advertising purposes. Parked domains are additional domains hosted on your account which display the same website as your primary domain and share web statistics as well; however, you can give the parked domain its own email boxes.

For example, if you own domain1.com and it is the primary domain of your cPanel account, you can set up domain2.com as a parked domain and it will load the content of domain1.com. When you visit domain2.com, you will notice that although the content of domain1.com is loading in the browser, the address bar will display http://domain2.com/. This is similar to a masked forward.

Domain Parking vs. a Parked Domain

When domain registrars offer domain parking, they are offering to park your domain on their servers and direct traffic to a page of their choice. This is a good temporary solution if you don't have a web hosting account, but it is very restrictive.

Add a Parked Domain

Domains must be registered with a valid registrar before they can be parked. In addition, a domain will not be functional unless it is configured to point to the same name servers as your primary domain.

To add a parked domain to your account:

  • Log into cPanel.
  • In the Domains section, click the Parked Domains icon.
  • Under Create a New Parked Domain, enter the domain name you would like to park on top of your primary domain.
  • Click Add Domain.
You have just added a parked domain.

Remove a Parked Domain

To remove a parked domain from your account:

  • Log into cPanel.
  • In the Domains section, click the Parked Domains icon.
  • Under Remove Parked Domains, find the domain you wish to remove.
  • In the Actions column for that domain, click Remove.

Redirect a Main Domain in cPanel to it's Parked Domain

I have a main domain, '<redirect-from>.com' with user name 'redirect' in my Cpanel and I have created a parked domain '<redirect-to.com>' in this account. As you know both are loading the same pages here.

I need to redirect the url, http://redirect-to.com/ to http://redirect-to.com/ , for that I have select the option, 'Redirect' from the cPanel and I have encountered an error like the following when adding the redirect. I have this problem only when creating a redirect via cPanel when creating redirect rule from the main domain to a parked domain in the same account.


Error Adding Redirection

Redirecting "" to "http://redirect-to.com/" will cause a redirection loop because "http://redirect-from.com/", which is located at "/home/redirect/public_html/", is above "http://redirect-to.com/", which is located at "/home/redirect/public_html/" .


I have created a rule in my htaccess as follows to redirect the main domain to it's parked domain.


# cat /home/redirect/public_html/.htaccess

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

RewriteEngine On

RewriteCond %{HTTP_HOST} ^redirect-from.com$ [NC]
RewriteRule ^(.*) http://redirect-to.com/$1 [R=301,L]


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Useful Commands

(D)DoS Deflate is a lightweight bash shell script designed to assist in the process of blocking a denial of service attack. It utilizes the command below to create a list of IP addresses connected to the server, along with their total number of connections. It is one of the simplest and easiest to install solutions at the software level.
 netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
Check DDOS Attack.Number of connections to port 80

# netstat -plan | grep :80 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

Check DDOS Attack.count IPv4 connections per IP

# netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | sed s/::ffff:// | cut -d: -f1 | sort | uniq -c | sort -n 
Find PORT_FLOOD attacker to the server

# cat /var/log/messages | grep 'Port Flood' | awk '{print $13}' | sed 's/SRC=//g' | sort | uniq -c | sort -n
Find all files with root SUID or SGID executables

# find / -type f \( -perm /4000 -a -user root \) -ls -o \( -perm /2000 -a -group root \) -ls 

List top 20 IP from which TCP connection is in SYN_RECV state.Useful on web servers to detect a .

# netstat -pant 2> /dev/null | grep SYN_ | awk '{print $5;}' | cut -d: -f1 | sort | uniq -c | sort -n | tail -20 
Command to find sorted memory usage in server 

 # ps aux | awk '$11!~/\[*\]/ {print $6/1024" Mb --> "$11,$12,$13,$14}' | sort -g
Command to free the cache memory

# echo 3 > /proc/sys/vm/drop_caches 

Print IP of Attackers

# egrep 'Failed password for invalid' /var/log/secure | awk '{print $13}' | uniq 

To get tables with innodb as engine

#mysql -N mysql -e "SELECT table_schema, table_name FROM INFORMATION_SCHEMA.TABLES WHERE engine = 'innodb';" | awk '{print $1}' | sort | uniq 

To get the statistics of Mysql running queries

# mysqladmin -i 5 -r status 

Shows files sorted by date recursively in a directory, so you can find all new files

# find . -printf '%T@ %c %p\n' | sort -k 1n,1 -k 7 | cut -d' ' -f2- 

To change the TTL value for all the db files.

1. SSH to old server as root
2. cd /var/named
3. perl -pi.bak -e "s/14400/399/g" *.db
4. /etc/rc.d/init.d/named restart

Rsync command

# rsync -e "ssh -p 8496" -avz /home/cpmove-custome1.tar.gz root@nyerere.web4africa.net:/home/ 

Mysql load decreasing

# for i in `mysqladmin proc | grep gurusloa_wizkid | awk '{print $2}'`; do mysqladmin kill $i;done 

Command to count no of files in a location

# find . -xdev -type f | cut -d "/" -f 2 | sort | uniq -c | sort -n 

Troubleshooting wait average [Amount of time the CPU has been waiting for I/O to complete.]

# for x in `seq 1 1 10`; do ps -eo state,pid,cmd | grep "^D"; echo "----"; sleep 5; done 

To find the number of mails sent by each accounts with path if any.

# grep "cwd=" /var/log/exim_mainlog|awk '{for(i=1;i<=10;i++){print $i}}'|sort|uniq -c|grep cwd|sort -n 

To find the number of mysql queries by a cpanel user

# mysqladmin pr | cut -d'|' -f5 | sort | uniq -c | sort -n 

To get the virtual memory usage by each process

# ps -e -o pid,vsz,comm= | sort -n -k 2 # sar -S top command and press the key (<) 4 times 
# service stor_agent stop stopping Adaptec Storage Manager agent ... 

Mysql grant all privileges command

mysql> grant all privileges on database_name.* to 'db_user'@'localhost' identified by 'anythingstrong'; 

To Edit the password of joomla or Mysql admin

# UPDATE `rhezonc1_r`.`jn1iq_users` SET `password` = MD5( 'somethingstrong' ) WHERE `jn1iq_users`.`id` =43; 

Command to view the users with no of php process

#for i in {1..10} ; do ps aux | grep php | awk '{print $1}' | sort | uniq -c | sort -n; echo "---------" ; sleep 5; done 

Command to see php processes continuosly

# for i in {1..10} ; do ps aux |grep php | grep olandowe; echo "---------" ; sleep 5; done 

Command to view the number of queries for a database and username

# mysqladmin pr | gawk -F '|' '{print $5 $3}' | sort | uniq -c | sort -n 

Exim command to delete mails in queue to a specific email account, with from as < >

# exim -bpu | grep -B 1 mail@todelete.com | grep -v mail@todelete.com | awk '{print $3}' | xargs exim -Mrm 

Commands to calculate the sum

# awk '{s+=$1} END {print s}' mydatafile # paste -sd+ mydatafile|bc # sum=0; while read num ; do sum=$(($sum + $num)); done < numbers.txt ; echo $sum # perl -lne '$x += $_; END { print $x; }' < infile.txt 

Why Apache is not starting

# strace -Ff -o output.txt -e open /etc/init.d/httpd start 

Multiple Skype

Press Alt + F2 then add the command skype --secondary

If this not worked then please try the below one

# cp -r ~/.Skype ~/.Skype.first # cp -r ~/.Skype ~/.Skype.second # sudo apt-get install --no-install-recommends gnome-panel # mkdir myapps # gnome-desktop-item-edit ~/myapps/ --create-new Now type in the command field the following command: skype --dbpath=~/.Skype.first # gnome-desktop-item-edit ~/myapps/ --create-new skype --dbpath=~/.Skype.second

Exim

Exim is a mail transfer agent (MTA) used on Unix-like operating systems. Exim is free software distributed under the terms of the GNU General Public License, and it aims to be a general and flexible mailer with extensive facilities for checking incoming e-mail.

Usefull EXIM Commands.

Initial Check :

To show what EXIM is doing right now.
# exiwhat

To show number of messages in the queue.
# exim -bpc

To print list of messages in the queue (time queued, size, message-id, sender, recipient).
# exim -bp

Open the mail header of given message_Id.
# exim -Mvh <message_id>

Open the mail body of given message_Id.


# exim -Mvb <message_id>

View the Message log for the given Id.
# exim -Mvl <message_id>


Try to send the mail in the given Id.
# exim -M <message_id>

To forcefully send the entire mail queue.
# exim -qf

To forcefully send the entire mail queue.
# exim -qff

To edit the sender of a message
# exim -Mes <message-id> <address>

To remove a message from the queue
# exim -Mrm <message-id>

To freeze a message
# exim -Mf <message-id>
  
Filtering the Mails :

To print Summary of the mails.
# exim -bp | exiqsumm

To find the Frozen mails on the Mail Queue,
# exiqgrep -zc
or
# exim -bpr | grep frozen | wc -l

To remove frozen mails from the Queue,
# exiqgrep -zi | xargs exim -Mrm

To view the message Ids of the given domain name or E-mail address..
# exiqgrep -f <domain_name/e-mail> -i

To print message Ids recieved by the domain name or E-mail address.
# exiqgrep -r <domain_name/e-mail> -i

To remove the mails from a specific user,type
# exiqgrep -f <e-mail@domain> -i | xargs exim -Mrm

The following script will give the summary of mails in the mail queue.
# exim -bpr | exiqsumm -c | head

You will get a result as like follows,

Count  Volume  Oldest  Newest  Domain
 -----      ------      ------     ------       ------

  114   171KB     24h     28m  testdomain.com
   15    28KB       36h     7m    gmail.com
    5     10KB       34h     10h   test2domain.com
    4     8192        27h     4h     yourdomain.com
    4     75KB       7m      7m    server.domain.com
    3     6041        23h     42m  test123.com


You can find useful commands/scripts used in exim in the following link,


More Reference:

https://github.com/Exim/exim/wiki

http://www.exim.org/exim-html-current/doc/html/spec_html/ch-log_files.html

http://www.exim.org/exim-html-4.20/doc/html/spec_13.html#IX1148

http://www.grscripts.com/tweaking.html 

Wednesday, 15 January 2014

Joomla

WHAT IS JOOMLA?

Joomla is an award-winning content management system (CMS), which enables you to build Web sites and powerful online applications. Many aspects, including its ease-of-use and extensibility, have made Joomla the most popular Web site software available. Best of all, Joomla is an open source solution that is freely available to everyone.

What’s a content management system (CMS)?

A content management system is software that keeps track of every piece of content on your Web site, much like your local public library keeps track of books and stores them. Content can be simple text, photos, music, video, documents, or just about anything you can think of. A major advantage of using a CMS is that it requires almost no technical skill or knowledge to manage. Since the CMS manages all your content, you don’t have to.

What are some real world examples of what Joomla! can do?

Joomla is used all over the world to power Web sites of all shapes and sizes. For example:
  • Corporate Web sites or portals
  • Corporate intranets and extranets
  • Online magazines, newspapers, and publications
  • E-commerce and online reservations
  • Government applications
  • Small business Web sites
  • Non-profit and organizational Web sites
  • Community-based portals
  • School and church Web sites
  • Personal or family homepages

Fastest Way to Install Joomla Through SSH

The Joomla archive is a relatively large file base. The Joomla stable version 1.5.15 has:

Uploading all these files via FTP to your remote web host can be slow and painful.

Our proposed faster solution is to install Joomla is via SSH. Here are the exact steps below:

  • Login to your server via SSH and cd to your web folder
  • Grab the latest Joomla stable code base. For example:
wget -c http://joomlacode.org/gf/download/frsrelease/11396/45610/Joomla_1.5.15-Stable-Full_Package.zip
  • Unzip the archive:
unzip Joomla_1.5.15-Stable-Full_Package.zip
  • Create a MySQL database and a user via PHPMyAdmin. Assign the user permission to the created database only. Note the database name, username and password.
  • Run the Joomla installer by visiting the folder where you unzipped the archive via browser. 
For example: http://www.example.com/joomla/. Follow the on-screen Joomla installation steps. Use the database login information from the step above.
  • Once the installation is complete, remove the following:
rm -rf installation
rm Joomla_1.5.15-Stable-Full_Package.zip
That’s it. You should now have a live Joomla site ready for publishing.

Linux Server Administration

A Linux server administrator is the one  who is responsible for setting up and maintaining the Linux Server is called as the Linux Server administrator.


Duties of a Server administrator


The duties of a Server administrators are wide-ranging, and vary widely from one organization to another. Serveradmins are usually charged with installing, supporting, and maintaining servers  and planning for and responding to service outages and other problems.

The server administrator is responsible for following things:

  • User administration (setup and maintaining account)
  • Maintaining server
  • Verify that peripherals are working properly
  • Quickly arrange repair for hardware in occasion of hardware failure
  • Monitor server performance
  • Create file systems
  • Install software
  • Create a backup and recover policy
  • Monitor server network communication
  • Update server as soon as new version of OS and application software comes out
  • Implement the policies for the use of the computer system and network
  • Setup security policies for domains. A server admin must have a strong grasp of computer security (e.g. firewalls and intrusion detection systems).
What is so special about the server administrator account?

The root account has full (unrestricted) access, so he/she can do anything with server. For example, root can remove critical system files.

Some of the  tasks for server administration are ,
  • Create new users
  • Resetting user passwords
  • Lock/unlock user accounts
  • Monitor server security
  • Monitor special services etc
Most important skill to a Server  administrator

Problem solving, period. This can some time lead into all sorts of constraints and stress. When a server goes down, you are called to solve the problem. You should able to quickly and correctly diagnose the problem. You must figure out what is wrong and how best it can be fixed in small amount of time.Always be keen to monitor the server is the best quality of a Server administrator.