How to clear swap space – Ubuntu/Linux

 

To clear swap space in Ubuntu/Linux we need to use swapoff command as shown below:

$ swapoff -a

Above command will turn of swap completely.

Before running swapoff command you need to have enough free RAM available, since swapoff command will move all swap data to RAM.

If you wont have enough free RAM this command may make your system unstable.

Again to turn on swap you need to use swapon command ash shown below:

$ swapon -a

You need to have root/sudo permissions to run above commands.

Advertisements

Number of open files or file descriptors associated with a process

Since in *nix every thing is a file, When you try to find open files or file descriptor associated with a process you will see Actual file log, Unix Sockets, Library files, Network Sockets,  /dev files and others.

lsof is a command to list all open files.

To list all open files or file descriptors by a process:

$ lsof -p PID

or

$ lsof -a -p PID

or

$ ls /proc/PID/fd

where PID is a process ID of any process that is running.

To count all open files by a process:

$ lsof -p PID | wc -l

or

$ ls /proc/PID/fd | wc -l

To list all open files:

$ lsof 

To count all open files:

$ lsof | wc -l

CentOS – Hostname Change

 

To change host name in CentOS use following steps:

Open /etc/sysconfig/network file

$ vim /etc/sysconfig/network

Now modifiy HOSTNAME= value

HOSTNAME=my.domain.com

my.domain.com is desired host for my machine, similarly we can use other valid domain names.

Next edit /etc/hosts file, here we need to change the host that is associated to your main IPaddress for your server.

192.168.1.10   my.domain.com my

After completing above two changes restart network by using following command:

$ service network restart 

Now run hostname command:

$ hostname

Output:

my.domain.com

Above procedure will work both in CentOS 5 and 6 versions.

Enable/Disable ssh access to root

Its always better to disable ssh access to root user which will protect the server from any attacks. Its kind of additional security layer on top of firewall.

There are 2 ways to disable SSH access to root.

With DenyUsers:

In /etc/ssh/sshd_config file search for line DenyUsers, if it exists edit it as follows else add following line:

DenyUsers root

If you want to disable ssh login for multiple users on the server add as following:

DenyUsers root user1 user2 user3

After updating sshd_config add restart sshd service with following command:

$ service sshd restart

Now try to ssh to root, it should not allow login even though you entered right password.

With PermitRootLogin:

PermitRootLogin will support 2 options “yes” and “no”.

Option yes will allow ssh to root and option no wont allow ssh to root.

To allow ssh to root add following line in /etc/ssh/sshd_config file and restart sshd service:

PermitRootLogin yes

To disable ssh to root add following line in /etc/ssh/sshd_config file and restart sshd service:

PermitRootLogin no

-Sany

Install mysql server in Centos 5

 

To install mysql server in Centos 5 use following command:

$ yum install mysql mysql-server

After installing mysql server you need to set password for mysql root user with following command:

$ mysqladmin -u root password 'new-password'

Now try to access mysql with following command:

$ mysql -u root -p'new-password'

It will take you to myslq console.

To restart mysql server use following command:

$ service mysqld restart

To stop mysql server:

$ service mysqld stop

To start mysql server:

$ service mysqld start

To get status of mysql server:

$ service mysqld status

-Sany

Lampp – error while loading shared libraries: libc.so.6 xampp – Centos

Recently while restarting lampp server I got following error, which is used to work previously:

cat: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
/bin/sh: error while loading shared libraries: libdl.so.2: cannot open shared object file: No such file or directory
Starting XAMPP for Linux ...
/bin/bash: error while loading shared libraries: libdl.so.2: cannot open shared object file: No such file or directory
/bin/bash: error while loading shared libraries: libdl.so.2: cannot open shared object file: No such file or directory
/bin/bash: error while loading shared libraries: libdl.so.2: cannot open shared object file: No such file or directory
/bin/bash: error while loading shared libraries: libdl.so.2: cannot open shared object file: No such file or directory
/bin/bash: error while loading shared libraries: libdl.so.2: cannot open shared object file: No such file or directory
XAMPP for Linux started.

To resolve this issue I read some forums, tried some solutions. After struggling couple hours I got the solution.

Following is the solution that worked for me:

Open lampp file in your server and search for the line redhat-release.

Most probably you can find this at line number 50 in laamp script, it should looks like following:

if egrep "Fedora" /etc/redhat-release > /dev/null

For CentOS we need to replace Fedora with CentOS, after changing like looks like following:

if egrep "CentOS" /etc/redhat-release > /dev/null

After making above changes try to start lampp with following and it should work without any issue.

$ /opt/lampp/lampp start
or
./lampp start

where /opt/lampp is root directory of lampp server.

-Sany

How to install goaccess in Centos/Fedora/Ubuntu

GoAccess is an interactive command line tool to analyse apache2/apache-httpd/ngnix logs.

It provides realtime HTTP statistics for website administrators.

GoAccess will provide following statistics:

  •  Unique visitors per day – Including spiders
  •  Requested files (Pages-URL)
  • Requested static files – (Static content: png,js,etc)
  • Referrers URLs
  •  HTTP 404 Not Found response code
  •  Operating Systems
  • Browsers
  • Hosts
  • HTTP Status Codes
  • Top Referring Sites
  • Top Keyphrases used on Google’s search engine

Install GoAccess in Ubuntu/Debian based operating systems:

$ apt-get install goaccess

Install GoAccess in RHEL/Fedora/Centos base operating systems:

In RHEL/Fedora/Centos base operating systems there is no single command available to install GoAccess. We need to install it from source code.

First install dependency packages with following command:

$ yum install glib2 glib2-devel glibc make geoip ncurses-devel

Download GoAccess source code:

$ wget http://sourceforge.net/projects/goaccess/files/0.4.2/goaccess-0.4.2.tar.gz

Uncompress source code:

$ tar xzf goaccess-0.4.2.tar.gz

Now install it by running following commands:

$ cd goaccess-0.4.2

$ ./configure

$ make; make install

Following are options available with goaccess command:

Usage: goaccess [ -b ][ -s ][ -e IP_ADDRESS][ – a ]< -f log_file >

The following options can also be supplied to the command:

-f <argument> – Path to input log file.
-b – Enable total bandwidth consumption.
For faster parsing, don’t enable this flag.
-s – Enable HTTP status codes report.
For faster parsing, don’t enable this flag.
-a – Enable a List of User-Agents by host.
For faster parsing, don’t enable this flag.
-e <argument> – Exclude an IP from being counted under the
HOST module. Disabled by default.

Example commands:

$ goaccess -f /var/log/httpd/access_log

$ goaccess -s -b -e 192.168.*.*  -f /var/log/httpd/access_log

-Sany