Category Archive : Uncategorized

This article describes how to check and upgrade the Linux kernel in OpenVZ, KVM, and Dedicated Servers (including the CloudLinux platform).

Checking the Kernel Version

To check system parameters such as the kernel version and build date, OS architecture, hostname, etc., you can use the uname command, which is included in coreutils package:

  # uname -rv
  3.10.0-693.11.6.el7.x86_64 #1 SMP Thu Jan 4 01:06:37 UTC 2018

To view the current kernel version and build date, run uname -r. Depending on the platform your server is running on, you may see slightly different output, even for the same CentOS 7 operating system.

If you run a VPS (Virtual Private Server) as an OpenVZ container, you will see the “stab” in the kernel version:

  # uname -r
  2.6.32-042stab125.5

If you run CentOS 7 on a Dedicated Server or a KVM virtual server, you could see “el7” in the kernel version, which refers to Red Hat Enterprise Linux, from which CentOS is derived:

  # uname -r
  3.10.0-693.11.6.el7.x86_64

If you are running CloudLinux, you could see “lve” in the kernel version:

  # uname -r
  3.10.0-714.10.2.lve1.5.9.el7.x86_64

Another way to check would be with the following yum command:

  yum info kernel -q

This command may run noticeably longer, because yum uses a python interpreter and one or more plugins by default. However, it gives more detailed information. Here is an example of possible output from this command:

  # yum info kernel -q
  Available Packages
  Name        : kernel
  Arch        : x86_64
  Version     : 3.10.0
  Release     : 693.11.6.el7
  Size        : 43 M
  Repo        : updates/7/x86_64
  Summary     : The Linux kernel
  URL         : http://www.kernel.org/
  License     : GPLv2
  Description : The kernel package contains the Linux kernel (vmlinuz), the core of any
              : Linux operating system.  The kernel handles the basic functions
              : of the operating system: memory allocation, process allocation, device
              : input and output, etc.

Upgrading the Linux Kernel

If you have a VPS as an OpenVZ container, it is not possible to upgrade your kernel independently, because all virtual containers run the same kernel loaded on the node. Therefore, voluntary upgrade can be performed only on Dedicated Servers and KVM-based virtual servers.

To upgrade the kernel, you can run this yum command:

  yum upgrade kernel

By default, this command should ask for confirmation to install new kernel:

  Is this ok [y/d/N]:

If you want to skip the confirmation, you can use the -y switch:1)

  yum upgrade kernel -y

Once the new kernel is installed you need to load it. To do so, you need to reboot the server:

  reboot

Once the server has finished rebooting, you should check the loaded kernel version as described in previous section.

KernelCare Usage

KernelCare is a live-patching software for Linux kernels distributed by CloudLinux. When using KernelCare, the server does not require rebooting for kernel upgrades, and kernel patches are checked and applied on the fly automatically every 4 hours. It is available only for Dedicated Servers and KVM virtual servers.

You can check if KernelCare is installed as follows:

  # yum info kernelcare -q
  Installed Packages
  Name        : kernelcare
  Arch        : x86_64
  Version     : 2.14
  Release     : 2
  Size        : 217 k
  Repo        : installed
  From repo   : kernelcare
  Summary     : KernelCare tools
  URL         : http://www.cloudlinux.com
  License     : CLOUD LINUX LICENSE AGREEMENT
  Description : KernelCare userland tools

To check if patches have been applied, run:

  kcarectl --info

More details about KernelCare can be found in the following places:

Removing Old Kernels

Sometimes you may need to remove old kernels from the server manually. To check all installed kernels, this yum command could be used again:

  # yum list kernel -q
  Installed Packages
  kernel.x86_64                                       3.10.0-693.11.1.el7                                              @updates
  kernel.x86_64                                       3.10.0-693.11.6.el7                                              @updates

Using the command package-cleanup with the --oldkernels switch would remove all old kernels, leaving only ‘count‘ most recent ones (by default count=2). For example, to remove all kernels except the one most recently installed and loaded, run the following command:

  package-cleanup --oldkernels --count=1

What’s ss Command?

ss stands for socket statistics. It is used to dump socket statistics about network/socket connections.

It’s showing information similar to netstat, it works better and faster compared with netstat. It can display more TCP and state information than other tools.

Since the ss command gets all the information directly from kernel space (with single source) that’s why it’s faster than netstat.

What’s netstat Command?

netstat stands for network statistics. It displays network connections, routing tables, interface statistics, masquerade connections, multicast memberships and network protocol statistics.

The netstat command has been deprecated and replaced by the ss command in most of the Linux distributions.

It reads various /proc files to gather information. It would take more time when there are lots of connections to display.

How to Count Apache’s (Httpd) Current Connections in Linux Using ss Command?

Use the ss command with following options to count Apache current connections in Linux.

# ss -ant | grep :80 | wc -l
110

How to Count Apache’s (Httpd) Current Connections in Linux Using netstat Command?

Use the netstat command with the following options to count apache current connections in Linux.

# netstat -ant | grep :80 | wc -l
90

How to Display Apache’s (Httpd) Current Connections in Linux Using ss Command?

Use the ss command with the following options to display detailed information about apache’s current connections in Linux.

It displays an active internet connections in the server at port 80.

# ss -ant | grep :80
LISTEN     0      128          *:80                       *:*                  
TIME-WAIT  0      0      94.237.64.70:80                 172.69.44.142:16690              
TIME-WAIT  0      0      94.237.64.70:80                 172.69.68.173:60360              
TIME-WAIT  0      0      94.237.64.70:80                 172.68.146.130:25988              
TIME-WAIT  0      0      94.237.64.70:80                 162.158.231.34:52566              
TIME-WAIT  0      0      94.237.64.70:80                 162.158.231.34:54094              
TIME-WAIT  0      0      94.237.64.70:80                 108.162.229.40:21418              
TIME-WAIT  0      0      94.237.64.70:80                 162.158.231.145:33218              
TIME-WAIT  0      0      94.237.64.70:80                 162.158.50.236:63306              
TIME-WAIT  0      0      127.0.0.1:56262              127.0.0.1:80                 
ESTAB      0      0      94.237.64.70:80                 172.68.169.24:35698              
TIME-WAIT  0      0      94.237.64.70:80                 172.68.58.127:59962              
TIME-WAIT  0      0      94.237.64.70:80                 162.158.146.186:23750              
TIME-WAIT  0      0      94.237.64.70:80                 162.158.231.31:20908              
TIME-WAIT  0      0      94.237.64.70:80                 162.158.231.7:17936              
TIME-WAIT  0      0      94.237.64.70:80                 162.158.231.13:33318              
TIME-WAIT  0      0      94.237.64.70:80                 162.158.231.22:23296              
ESTAB      0      0      94.237.64.70:80                 162.158.38.72:45150          

How to Display Apache’s (Httpd) Current Connections in Linux Using netstat Command?

Use the netstat command with the following options to display detailed information about apache’s current connections in Linux.

It displays an active internet connections in the server at port 80.

# netstat -ant | grep :80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN     
tcp        0      0 94.237.64.70:80         172.69.44.142:16690     TIME_WAIT  
tcp        0      0 94.237.64.70:80         172.69.68.173:60360     TIME_WAIT  
tcp        0      0 94.237.64.70:80         172.68.146.130:25988    TIME_WAIT  
tcp        0      0 94.237.64.70:80         162.158.231.34:52566    TIME_WAIT  
tcp        0      0 94.237.64.70:80         162.158.231.145:33218   TIME_WAIT  
tcp        0      0 94.237.64.70:80         162.158.50.236:63306    TIME_WAIT  
tcp        0      0 127.0.0.1:56262         127.0.0.1:80            TIME_WAIT  
tcp        0      0 94.237.64.70:80         172.69.68.6:15564       TIME_WAIT  
tcp        0      0 94.237.64.70:80         172.69.69.240:58040     TIME_WAIT  
tcp        0      0 94.237.64.70:80         162.158.78.150:51818    ESTABLISHED
tcp        0      0 94.237.64.70:80         162.158.231.27:56412    TIME_WAIT  
tcp        0      0 94.237.64.70:80         172.69.70.187:55842     TIME_WAIT  
tcp        0      0 94.237.64.70:80         141.101.76.126:58756    ESTABLISHED
tcp        0      0 94.237.64.70:80         172.68.50.30:16508      ESTABLISHED
tcp        0      0 94.237.64.70:80         162.158.231.7:17780     TIME_WAIT  
tcp        0      0 94.237.64.70:80         162.158.231.16:60012    TIME_WAIT  
tcp        0      0 94.237.64.70:80         162.158.231.24:13312    TIME_WAIT  
tcp        0      0 94.237.64.70:80         162.158.231.13:30752    TIME_WAIT  
tcp        0      0 94.237.64.70:80         162.158.154.93:42576    ESTABLISHED

How to Count Number of Connection Currently Active in Apache from Each IP Address Using ss Command?

Use the ss command with the following options to count number of connection currently active in Apache from each IP address.

# netstat -ant | awk '{print $5}' | cut -d":" -f1 | sort | uniq -c | sort -nr
      6 162.158.155.70
      5 127.0.0.1
      2 172.68.51.180
      2 172.68.215.98
      2 172.68.215.86
      2 172.68.215.77
      2 172.68.215.75
      2 172.68.215.113
      2 172.68.215.111
      2 172.68.215.109
      2 172.68.215.101
      2 172.68.215.100
      2 162.158.150.128
      2 162.158.150.120
      2 162.158.118.154
      2 141.101.96.253
      2 141.101.96.243
      2 141.101.76.234
      2 141.101.105.254
	  .
	  .

How to Count Number of Connection Currently Active in Apache from Each IP Address Using netstat Command?

Use the netstat command with the following options to count number of connection currently active in Apache from each IP address.

# ss -at | awk '{print $5}' | cut -d":" -f1 | sort | uniq -c | sort -nr
      6 162.158.155.70
      5 127.0.0.1
      2 172.68.51.180
      2 172.68.215.98
      2 172.68.215.86
      2 172.68.215.77
      2 172.68.215.75
      2 172.68.215.113
      2 172.68.215.111
      2 172.68.215.109
      2 172.68.215.101
      2 172.68.215.100
      2 172.68.169.36
      2 162.158.150.128
      2 162.158.150.120
      2 162.158.118.154
      2 141.101.96.253
      2 141.101.96.243
      2 141.101.76.234
      2 141.101.105.254
	  .
	  .

How to Count Number of Connection Currently Established in Apache from Each IP Address Using ss Command?

Use the ss command with the following options to count number of connection currently established in Apache from each IP address.

# ss -at | grep ESTAB | awk '{print $5}' | cut -d":" -f1 | sort | uniq -c | sort -n
      1 103.5.134.182
      1 162.158.150.84
      1 172.68.169.30
      1 172.68.206.84
      1 182.111.155.129
      1 69.10.49.214

How to Count Number of Connection Currently Established in Apache from Each IP Address Using netstat Command?

Use the netstat command with the following options to count number of connection currently established in Apache from each IP address.

# netstat -ant | grep ESTAB | awk '{print $5}' | cut -d":" -f1 | sort | uniq -c | sort -n
      1 103.5.134.182
      1 172.68.206.84
      1 182.111.155.129
      1 69.10.49.214

How to Count Apache’s (httpd) Actual Running Processes in Linux Using ps Command?

ps command is used to display all running processes in Linux system. Use the following format, if you would like to count running Apache processes in Linux.

# ps -auxw | grep httpd | grep -v grep | wc -l
12

How to Check List of Apache Processes in Linux Using ps Command?

ps command is used to display all running processes in Linux system. Use the following format, if you would like to display running httpd processes in Linux.

# ps auxw | grep httpd | grep -v grep
nobody    7988  0.0  0.5 253280 23252 ?        S    14:32   0:00 /usr/sbin/httpd -k start
nobody    8050  0.0  0.6 253412 24276 ?        S    14:33   0:00 /usr/sbin/httpd -k start
nobody    8054  0.0  0.6 253280 23288 ?        S    14:33   0:00 /usr/sbin/httpd -k start
nobody    8158  0.0  0.6 253280 23296 ?        S    14:33   0:00 /usr/sbin/httpd -k start
nobody    8159  0.0  0.5 253280 23176 ?        S    14:33   0:00 /usr/sbin/httpd -k start
daygeek   8202  0.0  0.6 253416 23304 ?        S    14:34   0:00 /usr/sbin/httpd -k start
nobody    8203  0.0  0.5 253280 23052 ?        S    14:34   0:00 /usr/sbin/httpd -k start
nobody    8207  0.0  0.5 253280 23044 ?        S    14:34   0:00 /usr/sbin/httpd -k start
nobody    8213  0.0  0.6 253280 23300 ?        S    14:34   0:00 /usr/sbin/httpd -k start
nobody    8216  0.0  0.5 253280 23052 ?        S    14:34   0:00 /usr/sbin/httpd -k start
nobody    8218  0.0  0.6 253416 23304 ?        S    14:34   0:00 /usr/sbin/httpd -k start
nobody    8266  0.0  0.5 253148 23052 ?        S    14:35   0:00 /usr/sbin/httpd -k start
nobody    8267  0.0  0.5 253144 22800 ?        S    14:35   0:00 /usr/sbin/httpd -k start
nobody    8391  0.3  0.5 253144 22800 ?        S    14:35   0:00 /usr/sbin/httpd -k start
nobody    8393  0.5  0.5 253012 21776 ?        S    14:35   0:00 /usr/sbin/httpd -k start
nobody    8394  1.0  0.5 253144 22800 ?        S    14:35   0:00 /usr/sbin/httpd -k start
root     30500  0.0  0.0 227356  3584 ?        Ss   Jul25   2:33 /usr/sbin/httpd -k start

On some occasions apache server will just fail, and become crashed, failing to restart with an error message like

# tail /var/log/httpd/error_log

[Sun Dec 22 10:05:27.006998 2013] [core:emerg] [pid 15001:tid 140145945569216] (28)No space left on device: AH00023: Couldn't create the fcgid-proctbl mutex
[Sun Dec 22 10:05:38.000403 2013] [core:emerg] [pid 15018:tid 140368783902656] (28)No space left on device: AH00023: Couldn't create the proxy mutex
[Sun Dec 22 10:05:38.000456 2013] [proxy:crit] [pid 15018:tid 140368783902656] (28)No space left on device: AH02478: failed to create proxy mutex

If you see an error similar to the bellow, it could indicate that your server has run out of semaphores. To see how many semaphores are being used, type the following command

# ipcs -s

------ Semaphore Arrays --------
key        semid      owner      perms      nsems
0x00000000 38797312   apache     600        1
0x00000000 38731777   apache     600        1
0x00000000 38830082   apache     600        1
0x00000000 38961155   apache     600        1
0x00000000 38895620   apache     600        1
0x00000000 38993925   apache     600        1
0x00000000 39026694   apache     600        1
0x00000000 39059463   apache     600        1
0x00000000 39092232   apache     600        1
0x00000000 39125001   apache     600        1
0x00000000 39157770   apache     600        1
0x00000000 39288843   apache     600        1
0x00000000 39223308   apache     600        1
0x00000000 39321613   apache     600        1
0x00000000 39354382   apache     600        1
0x00000000 39387151   apache     600        1
0x00000000 39419920   apache     600        1
0x00000000 39452689   apache     600        1
0x00000000 39485458   apache     600        1

To fix it and get Apache server started again, we must clean the semaphores. Run the following command to flush them:

for whatever in `ipcs -s | awk '{print $2}'`; do ipcrm -s $whatever; done

If that command may not work on older server then you may need to do the following

# /etc/init.d/httpd stop
# ipcs -s | grep nobody | gawk '{ print $2 }' | xargs -n 1 ipcrm sem
# /etc/init.d/httpd start

Final, you may want to increase the semaphore limits on your server. You can do that by adding the following to the /etc/sysctl.conf

kernel.msgmni = 512
kernel.sem = 250 128000 32 512

After, type the following command to update new setting for kernel

# sysctl -p

While the mailserver generally requires little interaction for those sending or receiving average volumes of email, there may be times when you wish to manage Exim’s settings.

To do so, first log in to your server in a terminal client using secure shell (SSH). Use the following commands to work with Exim.

Display the number of email messages in the queue

exim -bpc

Display information about email messages in the queue

exim -bp

Displays time queued, size, message-id, sender and recipient.

How to list email count with sender information from the Exim mail queue ?

We can use the base command “exim -bp” to do our concern. The output of the command “exim -bp” contains the user details, both sender and receiver email address. So, we can use it for our purpose. 🙂

Syntax:

exim -bp|grep "<"|awk {'print $4'}|cut -d"<" -f2|cut -d">" -f1|sort -n|uniq -c|sort -nr

Where;

exim -bp : Is the base command to list all email in the mail queue with its details.

grep “<” : To grep out the Sender address line only.

awk {‘print $4’} : Output only the sender name section.

cut -d”<” -f2|cut -d”>” -f1 : To crop ‘<‘ and ‘>‘ 🙂

sort -n|uniq -c|sort -nr : To re-arrange and count.

Example:

root@server# exim -bp|grep "<"|awk {'print $4'}|cut -d"<" -f2|cut -d">" -f1|sort -n|uniq -c|sort -nr
     15 root@domain0.com
     10 user@domain1.com
      8 user@domain2.com
      5 user@domain3.com
      3 user@domain4.com
      3 user@domain5.com
      2 user@domain6.com
      2 user@domain7.com

In this example, 15 emails are in the Exim mail queue for the account ‘root@domain0.com’ and 10 for the user ‘user@domain1.com’ and so on.

To count all emails from that user, you may use the exiqgrep command with -f switch.

exiqgrep -f sendername|grep "<"|wc -l

That’s it!

Display a summary of messages in the queue

exim -bp | exiqsumm 

Displays count, volume, oldest, newest, domain, and totals.

Display Exim’s current activity

exiwhat

exiwhat

Test Exim SMTP transaction

exim -bh ipaddress 

Spoofs an SMTP transaction, emanating from ipaddress. Exim’s status will be displayed as the transaction runs. Note that the message will not be delivered.

SMTP transaction

Display Exim settings

exim -bP

Exim settings

Search the mail queue for messages from a specific sender

exiqgrep -f [luser]@domain

Search the mail queue for messages from a specific recipient or domain

exiqgrep -r [luser]@domain

Display messages older than a specified number of seconds

exiqgrep -o seconds [...]

Display messages newer than a specified number of seconds 

exiqgrep -y seconds [...]

Locate messages matching a specific size

exiqgrep -s '^4..$' [...]

For example, 400-499 bytes. Use -z to match only frozen messages, or -x to match only unfrozen messages. To display just the message-id, use -I, while -c displays the message count.

Display the message count of the mail queue 

exiqgrep -c ...

Start a queue run

root@localhost# exim -q -v

Start a queue run isolated to local deliveries

root@localhost# exim -ql -v

Remove a message from the queue 

root@localhost# exim -Mrm <message-id> [ <message-id> ... ]

Freeze a message

root@localhost# exim -Mf <message-id> [ <message-id> ... ]

Throw a message

root@localhost# exim -Mt <message-id> [ <message-id> ... ]

Deliver a message

root@localhost# exim -M <message-id> [ <message-id> ... ]

Deliver a message (if the retry time has been reached) 

root@localhost# exim -Mc <message-id> [ <message-id> ... ]

Force a message to fail

root@localhost# exim -Mg <message-id> [ <message-id> ... ]

Remove all frozen messages

root@localhost# exiqgrep -z -i | xargs exim -Mrm

Remove all messages older than a defined number of seconds

root@localhost# exiqgrep -o seconds -i | xargs exim -Mrm

Freeze All Queued Mail from a Named Sender

root@localhost# exiqgrep -i -f luser@example.net| xargs exim -Mf

View a message’s mail headers

root@localhost# exim -Mvh <message-id>

View a message’s body

root@localhost# exim -Mvb <message-id>

View a message’s logs 

root@localhost# exim -Mvl <message-id> 

Add a recipient to a message

root@localhost# exim -Mar <message-id> <address> [ <address> ... ]

Edit a message sender

root@localhost# exim -Mes <message-id> <address>

 

Home and navigation

When you first log into your server, you will be in your home directory.

  • For the root user, this is /root/.

Linux folder structure

Linux uses a nested folder structure to store different files. The top-level directory is considered the root directory, and is designated by /. Folders beneath the root level are separated by slashes. For example, all of your website content is located in /var/www/vhosts/example.com/.

TIP:

Remember that / is not the same as /root/. The / is the root level of the server. You cannot get any higher than that. The home directory for the user called root is /root/.

Common paths:

  • /var/www/vhosts/example.com/httpdocs/ – web document root
  • /var/www/vhosts/example.com/statistics/logs/ – per-domain access and error logs
  • /var/www/vhosts/example.com/conf/ – per-domain configuration files
  • /etc/ – configuration files
  • /etc/init.d/ – software daemon start files

Move into another directory

Use this command to move into a directory:

cd

You can specify the full path from the root of the server:


cd /var/www/vhosts/example.com/conf/

You can type the path from where you are now (leave out the beginning /):

cd downloads/

You can go up a directory level:

cd ..

You can go to your home directory:

cd ~

Where am I?

Working with your server without graphics can take a little getting used to. If you ever need to see exactly which folder you’re in, use the following command:

pwd

It stands for print working directory. You’ll see output like this:


/var/www/vhosts/

What’s here?

Next, we want to see a list of files and folders in our current directory:

ls -alh

ls is the list command, and -alh modifies the standard list in three ways. a means that all files, even hidden files, should be shown. l means that the long format is used – it shows things like file size and the date every file was last modified. h makes the sizes display in convenient units. Here’s some sample output:


drwxr-x--- 10 domainuser psaserv 4.0K Oct 20 19:51 .
drwxr-xr-x 14 root       root    4.0K Aug 17 22:16 ..
-rw-r--r--  1 domainuser psacln    58 May 31 22:49 .htaccess
-rw-r--r--  1 domainuser psacln  2.1K Apr 20  2010 about.php
-rw-r--r--  1 domainuser psacln   907 Feb 25  2010 archive.php
drwxr-xr-x  2 domainuser psacln  4.0K Jul  2 16:43 image
-rw-r--r--  1 domainuser psacln  1.9K Mar  5  2010 index.php

Files

Let’s break down the elements of a file that are displayed when you run the ls -alh command from the previous section.


-rw-r--r--  1 domainuser psacln  1.9K Mar  5  2010 index.php
  • -rw-r–r– – These are the permissions for this file. r stands for “read,” w stands for “write,” and x stands for “execute.” The first character is standalone, and the next nine are in groups of three: the first triplet (rw-) applies to the owner, the second (r–) to the group, and the third (r–) to everyone. So, in this example, the owner has read and write access, the group just has read access, and everyone has read access. See File Permissions for an in-depth discussion.
  • 1 – Number of links to this file.
  • domainuser – The owner of this file.
  • psacln – The group this file belongs to.
  • 1.9K – The size of this file.
  • Mar 5 2010 – The date this file was last modified.
  • index.php – The name of this file.

Change permissions, owner, and group

This section shows basic commands for changing the access settings on a file. It is highly recommended that you read File Permissions before making any changes, so you’ll know what kinds of changes are good and what might be a security risk.

To change permissions:

chmod 755 index.php

chmod is the command. 755 is a code which tells what kinds of read, write, and execute permissions you want for the file. index.php is an example – you should replace with your file name.

Quick permissions guide:

7 = Read + Write + Execute
6 = Read + Write
5 = Read + Execute
4 = Read
3 = Write + Execute
2 = Write
1 = Execute
0 = All access denied

First number is for the owner, second for the group, and third for everyone.

To change owner:

chown domainuser index.php

chown is the command, short for “change owner.” domainuser is an example of a possible owner name – you should substitute this with your desired owner name. Note that the owner must exist on the server. index.php is an example – you should replace with your file name.

To change group:

chgrp psacln index.php

chgrp is the command, short for “change group.” psacln is an example of a common Plesk group – you should substitute this with your desired group name. Note that the group must exist on the server.

Change owner and group at once:

chown domainuser:psacln index.php

This command is exactly like the previous chown example, except that the group is also specified, after a colon (:).

Copy file

Use this command to copy a file to a different location (first example), or to the same folder but with a new name (second example):

cp logo.png image/logo.png
cp index.php index.php_old

cp is the command. The first file listed is the one you want to copy. The second file is the new name for the copied version of the file, including any path information for where the copy should be located. You can use a relative path like in the example above (that is, there is an image folder inside your current folder already), or you can use a full server path starting with /.

You can also copy an entire folder (along with all subfolders) using -R:

cp -R image/ image2

Move or rename file

The format for the move command is very similar to that for the copy command. Here’s an example:

mv logo.png image/logo.png

mv is the basic command. This moves logo.png into the image/ subdirectory.

You can also use it to rename a file:

mv index.php index.php_old

This renames index.php to index.php_old.

Finally, you can move a folder just as easily as a single file. This example shows how to move the folder image/ up one level (.. means “up one level”):

mv image/ ..

Compressing and decompressing a file using zip

Use this command to compress a file:

zip -r archive_name.zip folder_to_compress

Use this command to decompress a file:

unzip archive_name.zip

In these examples, zip and unzip are the commands. The -r option tells the command to work recursively. The archive_name.zip listed is the name of the file. Lastly, folder_to_compress is the directory you wish to compress.

Rsync

The rsync command can be used instead of the cp command, and works on all platforms of linux. Rsync can be used in the same way as cp with added benefits such as file permission and ownership preservation, compression during transfer, and comparison between files for updates to back ups.

rsync -a logo.png images/logo.png
rsync -a index.php index.php_old

rsync is the command, followed by the ‘-a’ flag which lets the system know to preserve the permissions, ownership, timestamp, and if rsyncing a directory, to do it recursively. The next part, ‘logo.png’ is the source file followed by the destination for that file to be copied to.

Another use for rsync is the ability to copy files and folders over a network to another server. This can be very helpful if you want to run some back ups, or migrate from one server to another within the (mt) Media Temple network. This first example will show you how to copy the entire document root for example.com to another server using it’s SSH login credentials.

rsync -avz example.com user@host:/path/to/destination

When you hit enter, you will be prompted to enter in the password for user on the remote server. This will move the entire directory, example.com and it’s contents over to the destination on the remote server. The options, ‘-avz’ let rsync know that you want to archive the file permissions, ownership, get a verbose readout of what file is being processed, and you would like to compress the files in order to use less bandwidth.

You can also reverse this to download a copy of files from a remote server to your local machine.

rsync -avz user@host:/path/to/source ./

Once again, you will be prompted for the password for the user account on the remote server. This will copy the specified file from the remote server to the current working directory on your local machine.

Create or edit a file

  • Create or edit a file:
vi file.html

If this is a new file, it’ll be empty when you open it, and you can start adding content. If this is an existing file, you’ll see its contents, which you can now edit.

vi tip: Press “i” to enter “insert mode” so you can type and copy/paste. Use the arrow keys to move back and forth in the file. Press “Esc” to exit “insert mode” when you are done modifying the file. Type “:wq” to save and quit.

See Understanding basic vi (visual editor) for more details.

  • Create an empty file (which you can later open for editing):
touch new_file.html

If you use an existing file name, it will instead “touch” that file and update its last-modified date.

Files are created with the owner and group of your SSH user. Once you’ve created a new file, it’s a good idea to run ls -alh to make sure its ownership matches the rest of the files in the directory. If not, run the chown command from the earlier section.

Read or search within a file

If you need to look through a file, the quickest way to get all the contents on your screen is cat:

cat index.html

<html>
<head>
<title>Home</title>
</head>
<body>
<p>Hello, world!</p>
</body>
</html>

However, this can be overwhelming if you have a large file. In that case, you can use less or | more to conveniently scroll through the content. less uses the arrow keys, and more uses Enter. Type q to exit either of them.

less access_log
cat access_log | more
  • Search files for a specific phrase:
cat error_log | egrep "permission"

This will list only the lines containing the word “permission.” cat shows the contents. Next, type the name of the file. | means the output should be filtered through the next command. egrep does the search. Your search term should go in quote marks, just in case it has special characters.

Delete file

You can also delete a file using SSH. Be sure you don’t need it any more before you delete it.

rm index.php_old

You will receive output like the following:

rm: remove regular file `index.php_old'? 

Type y confirm, or n to cancel. If you don’t want to be prompted, add -f to the command:

rm -rf index.php_old

Also, if you want to remove an entire directory and all its contents, including subdirectories, add -r. It can become tedious quickly to approve every deletion in a directory, so -f is commonly used.

Please be cautious with the rm -rf command. It will irreversibly delete a folder and all of the files and subfolders in it.

To make sure you’re deleting the right thing, you can always run a list command first. For example:

ls -alh /path/to/unwanted/folder/

Here’s the recursive deletion command:

rm -rf /path/to/unwanted/folder/

Disk use

  • Total server disk use:
df -h

You will see output like this, with an amount used and a percent used:

Filesystem            Size  Used Avail Use% Mounted on
/dev/vzfs              20G  3.1G   17G  17% /
simfs                  20G  3.1G   17G  17% /tmp
simfs                  20G  3.1G   17G  17% /var/tmp
  • Show all folder sizes for the current directory recursively, with their sizes:
du -h

If you run this from a high-level directory, it can take a while to complete.

  • Show a disk use summary for the current directory:
du -sh

Again, this can take a little while if you’re running it in a high-level directory.

  • Here’s an advanced find command you can run to find files over 10 MB (no variables in this one, just copy and paste):

find / -mount -noleaf -type f -size +10000k -print0 | xargs -0 ls -lhSr | awk '{printf "%*s %s\n",7,$5":",$9}'

DV server administration

Plesk admin password

  • Show Plesk admin password:
cat /etc/psa/.psa.shadow

MySQL access


The DV server has a simple shortcut for logging into MySQL:

my

Type quit to exit.

If you want to export or import a database, see Export and import MySQL databases.

Processes and system services

  • Show current server processes:
ps -auxf
  • Show processes and memory use live:
top
  • Start/Stop Services:
/etc/init.d/httpd restart

This example restarts Apache. You can also use start and stop. See Restart Plesk services for a list of services./span>

  • Check Bean Counters for system resource limits (hard and soft limits, failcounts, etc.):
cat /proc/user_beancounters

For an explanation of the results of several of these commands, and for more advanced resource tracking and troubleshooting, consider reading Troubleshooting DV Memory Issues.

Log Files

Log files can tell you a lot about what’s happening on your DV server. Log files are generally very long, so you should use one of these commands to sort through them easily:

  • Show the most recent 100 lines of the file:

tail -n 100 /var/www/vhosts/example.com/statistics/logs/error_log
  • Watch this file live. Interact with your server (by trying to reproduce the error, or navigating your website) while this is running and watch the log file update. Use CTRL-C to exit.

tail -f /var/www/vhosts/example.com/statistics/logs/access_log

Log locations

  • Apache error log for your domain:

/var/www/vhosts/example.com/statistics/logs/error_log

  • Statistic log for your domain:

/var/www/vhosts/example.com/statistics/logs/access_log

  • Server error log:

/var/log/messages

  • Apache error log:

/var/log/httpd/error_log

  • MySQL logs:

/var/log/mysqld.log

  • Mail logs:

/usr/local/psa/var/log/maillog

  • SSH history – just type:
history

Well, to get rid of this you need to set phpMyadmin variable to either 0 that is unlimited or whichever value in seconds you find suitable for your needs. Or you could always use CLI(command line interface) to not even get such errors(For which you would like to take a look at this link.

Now about the error here, first on the safe side make sure you have set PHP parameters properly so that you can upload large files and can use maximum execution time from that end. If not, go ahead and set below three parameters from C:\xampp\php\php.ini file,

  1. max_execution_time=3000000 (Set this as per your req)
  2. post_max_size=4096M
  3. upload_max_filesize=4096M

Once that’s done get back to finding phpMyadmin config file named something like “config.default.php”. On XAMPP you will find it under “C:\xampp\phpMyAdmin\libraries” folder. Open the file called config.default.php and set :

$cfg['ExecTimeLimit'] = 0;

Once set, restart your MySQL and Apache and go import your database.

Enjoy… 🙂

Linux is an open source widely spread community. There are millions of Linux users and intruders as well, their job is to make malicious activities on different servers to leak information or change the things as it works. It is really important to stop malicious activities and SPAM attacks on cPanel Hosting Server. There are a number of steps but you must enable/disable some Tweaks on cPanel server.

Setting in “Exim Configuration Manager” can help you with that,

1. Login to WHM control panel by using root login details

2. Go to Main ‘Service Configuration

Then click on Exim Configuration Manager

3. Enable RBL filtering by Basic Editor RBLs switch to “On” and if you like you may additional RBL from manage option.

4. Please turn ON Sender Verification Callouts

5. Please turn ON Sender Verification

5. Please turn ON Reject SPF failures

6. Then save the entire configuration this will stop most of the spams on the server.

Now let’s make some changes in Tweak Setting,

1. Login to WHM control panel by using root user

2. Goto Main Server Configuration Tweak Settings

3. Set “Initial default/catch-all forwarder destination = Fail”

4. Max hourly emails per domain = 200

5. Please turn ON Count mailman deliveries towards a domain’s Max hourly emails

6. The maximum percentage of failed or deferred messages a domain may send per hour = 60%

7. Then save the entire configuration this will stop most of the spams on the server.

To print a list of the messages in the queue, enter:

# exim -bp

To remove a message from the queue, enter:

# exim -Mrm {message-id}

To remove all messages from the queue, enter:

# exim -bp | awk '/^ *[0-9]+[mhd]/{print "exim -Mrm " $3}' | bash
suggested following clean command:
# exim -bp | exiqgrep -i | xargs exim -Mrm

Task: Delete Mail Linux Exim Server

To delete email for a particular user use shell pipes. By default the exim mail queue is located at /var/spool/exim/input directory. To delete email for a particular user called vivek@nixcraft.co.in, enter:
# exiqgrep -ir email@domain.com | xargs exim -Mrm
# exiqgrep -ir vivek@nixcraft.co.in | xargs exim -Mrm

Sometimes there can be so many frozen mails in the  Exim mail queue.

To know the number of frozen mails in the mail queue, you can use the following command

exim -bpr | grep frozen | wc -l 

In order to remove all frozen mails from the Exim mail  queue, use the following command

exim -bpr | grep frozen | awk {‘print $3’} | xargs exim -Mrm 

You can also use the command given below to delete all frozen mails

exiqgrep -z -i | xargs exim -Mrm

If you want to only delete frozen messages older than a day, you can try the following

exiqgrep -zi -o 86400

where you can change the value 86400 depending on the time frame you want to keep (1 day = 86400 seconds).

Making the following update to your Nginx .conf file will prevent your website from being accessed directly by it’s IP address

You’ll need to create a new server block and configure it such that any requests to the servers IP address will instead be redirected to the domain name.

server {
    listen 80;
    
    # Listen to your server ip address
    server_name 111.111.111.111; 
    
    # Redirect all traffic comming from your-server-ip to your domain
    return 301 $scheme://example.com$request_uri;
}

Now, when a request is made to 111.111.111.111 it will be redirected to example.com.

I noticed that on my CentOS 6 box, I was still running nginx 1.0.15. I wanted to upgrade to nginx 1.10.1. However, when I ran sudo yum update nginx, it showed that there were no Packages marked for Update.

Luckily, getting the latest version through Yum is straight-forward and only requires adding a new repo. First, create a new file, nginx.repo, in the yum repo directory.

$ vim /etc/yum.repos.d/nginx.repo

Next, give it the following contents:

[nginx] 
name=nginx repo  
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/  
gpgcheck=0  
enabled=1  

Save the file, then shut down the nginx service (unnecessary if nginx wasn’t on the system previously)

$ sudo service nginx stop  

Now, run the yum update command again (or install if nginx wasn’t on the system previously)

$ sudo yum update nginx

It should now let you update to the latest version! As soon as you install the new version, start nginx back up.

$ sudo service nginx start