Search This Blog

Tuesday, July 31, 2012

Synchronize time of two or more PCs with NTP

1) At first check whether NTP is installed or not. Install if its not installed.

#apt-get install ntp

2) Start or restart ntp using

#/etc/init.d/ntp restart/start

3) On server machine do following things.
Open /etc/ntp.conf and add following things


server ntp.ubuntu.com iburst
server pool.ntp.org
server 127.127.1.0
fudge 127.127.1.0 stratum 10


restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap

Here first two lines are external ntp servers which will be used to synchronize to time. 3rd and 4th line is used if machine has infrequent internet connection. Last line is used so that any machine from network 192.168.10.0 can use this machine as a server to synchronize time. So result would be that you would see same time on all machines in that network 192.168.10.0 and current machine(server).

Restart ntp using

#/etc/init.d/ntp restart

4) On client machine
Open /etc/ntp.conf and add ip address of the server machine. We assume that ip address of server machine was 192.168.10.12.

so in ntp.conf enter

server 192.168.10.12 iburst

Restart ntp
# /etc/init.d/ntp restart

Check using following command

#ntpq -c lpeer
And you should see ip address or hostname of server machine.

Thats it. Now onwards all the client machines in the network 192.168.10.0 and server machine(192.168.10.12) will always show same time and will remain synchronized.

Clear cache memory used by linux kernel and processor cache

You just give one command to do this:
# free && sync && echo 3 > /proc/sys/vm/drop_caches && free
This would clear only disk cache.

In order to clear processor cache memory, there is no perfect method. I can only suggest one method.
At first write a c program to allocate large amount of memory using malloc. That memory should be almost equal to the amount free memory available which you can see using top command. Now fill that allocated memory by writing it with random data or may be even 0. That would clear your processor cached.

Login without password using ssh

At first install openssh client and server using following commands.
#sudo apt-get install openssh-client
#sudo apt-get install openssh-server

Lets assume that there are two machines A and B. You want to login from B to A without using password..

1) So from machine B give following commands.
# ssh-keygen

After that press enter for the file (i.e. let it use default file), then press enter when asked for entering password.

Example from my machine:


root@hpc-13:~/.ssh# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): (PRESS ENTER)
Enter same passphrase again:  (PRESS ENTER)
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
ac:d6:6a:b2:98:f6:8a:0f:df:76:af:a6:82:7c:4f:c1 root@hpc-13
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|                 |
|    .  .         |
|     E  S        |
|      .o         |
|o.   .o .        |
|.=o=+.+.         |
|.oB=*Ooo.        |
+-----------------+

2) Now use ssh-copy-id command to do rest of the things.

 # ssh-copy-id -i ~/.ssh/id_rsa.pub username@hostname_of_remote_machine(machine A in our case)

Example from my machine:

root@hpc-13:~/.ssh# ssh-copy-id -i ~/.ssh/id_rsa.pub user@hpc-12
The authenticity of host 'hpc-12 (10.192.19.158)' can't be established.
RSA key fingerprint is 3f:9b:b2:b2:8e:36:09:4b:92:4c:df:bd:d6:14:b7:9f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'hpc-12,10.192.19.158' (RSA) to the list of known hosts.
user@hpc-12's password:
Now try logging into the machine, with "ssh 'user@hpc-12'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

3) Now try ssh to machine A

#ssh user@hostname_of_remote_machine(machine A in our case)

And you should be able to login without password.


Tuesday, July 10, 2012

How to find cached copy of any webpage url

Google stores all the pages in cache for few days and they can be found out by using this url

http://webcache.googleusercontent.com/search?q=cache:

Now just append the url who's cache copy you want to see. For example if you want to see cache copy of www.google.com then your url will be

http://webcache.googleusercontent.com/search?q=cache:http://www.google.com

You can offcourse try with those url which are not active currently for example facebook photos which are deleted later on.

Tuesday, June 26, 2012

error: Failed dependencies: libc.so.6 is needed

I actually got this error while trying to install rpm of driver of a network card on RHEL 6.2 64 bit. That error looked something like this:

# rpm -i  myri_dbl-2.  1.0.51076-3636.x86_64.rpm
error: Failed dependencies:
        libc.so.6 is needed by myri_dbl-2.1.0.51076-3636.x86_64
        libc.so.6(GLIBC_2.0) is needed by myri_dbl-2.1.0.51076-3636.x86_64
        libc.so.6(GLIBC_2.1) is needed by myri_dbl-2.1.0.51076-3636.x86_64
        libc.so.6(GLIBC_2.1.3) is needed by myri_dbl-2.1.0.51076-3636.x86_64
        libc.so.6(GLIBC_2.3) is needed by myri_dbl-2.1.0.51076-3636.x86_64
        libdl.so.2 is needed by myri_dbl-2.1.0.51076-3636.x86_64
        libdl.so.2(GLIBC_2.0) is needed by myri_dbl-2.1.0.51076-3636.x86_64
        libpthread.so.0 is needed by myri_dbl-2.1.0.51076-3636.x86_64
        libpthread.so.0(GLIBC_2.0) is needed by myri_dbl-2.1.0.51076-3636.x86_64


This error occurs because of some 32 dependencies which are required. The solution is to install 32 version of glibc.


# yum install libstdc++-4.4.6-4.el6.i686


This will mostly solve your problem.

Friday, June 22, 2012

To check which application is using a particular port

You give following command to check which application is using a particular port.

# netstat -ltnp | grep portno

or

# lsof -i :portno

Check whether hyperthreading is enabled or not ?

We can check whether hyper threading is enabled or not without checking in bios by giving following command
# cat /proc/cpuinfo
If the number of siblings and number of cores you see is same then hyper threading is not enabled. If they are not same then its enabled.
If its enabled, then "siblings" give logical cores present and "cpu core" gives actual physical cores.

Total number of cpu's is equal to maximum number of cpu id available in the result + 1.

If you want to find out how many cores are present in a particular cpu and what there numbers are then you can give following command.

#  cat /sys/devices/system/cpu/cpu2/topology/core_siblings_list

CPU affinity using taskset command in linux

In case of a machine having mulitple processor like NUMA processes generally perform better on one processor when compared to other processors. So its necessary to attach process to that particular processor so as to maximize performance. For such reasons, a tool named taskset can be used. The linux scheduler then acts according to processor affinity set by taskset command. But generally scheduler tries to keep process on same CPU as long as it supports natural affinity. So this taskset command may not work in all cases.

Command to check affinity of process with pid
# taskset -p pid
This command tells which cores have been assigned to the process with taht pid.

Command to set affinity of process
# taskset -p mask pid
This command is used to assign process with pid to cores given by that mask.

Mask is defined as follows:
It is a bitmap of processors present in the system. For example if there are 4 cores then 4 bits will be used in bitmap and if there are 8 cores then 8 bits will be used in bitmap.LSB indicates first core and MSB indicates last core. So to assign process with pid 1111 to cores 0,2,4,6 we will give following command
# taskset -p 0X55 1111
To assign it to cores 1,3,5,7 we will give following command
 # taskset -p 0Xaa 1111

Wednesday, June 20, 2012

Lock paged memory when using memcached by using memcached -k option

In case of memcached, paged memory should be locked for following reasons

1) If we reserve some paged memory for memcached then time would be saved in allocating memory for key/value pairs dynamically.
So memcached has memcached -k option to lock paged memory. But generally when you use this option you tend to get following error.

#memcached -u user -k &
warning: -k invalid, mlockall() failed: Cannot allocate memory

This occurs because by default llocked memory is only 64K. You can check this using
# ulimit -l

To change this, open /etc/security/limits.conf and then enter following lines at the end of file.

root   -     memlock   1048576

where root is the user who is going to run the memcached command from command line.

After that logout and login again and then check by using
#ulimit -l

vmap allocation for size=<> failed errror and adding kernel parameter while booting

This error arrises because the virtual memory allocated when operating system boots is limited. In order to solve this problem we have to increase virtual memory by giving external parameter to kernel when its booting.

This can be done in following way.

1)On the splash screen showing grub i.e.where operating system to be booted is shown, press e.

2)Then on the page which appears select that line which starts with the work "kernel". Again press e and go to the end of the line and write vmalloc=

3)After that press enter and boot that operating system. That would  remove that error.

Error inserting module : unknown symbol _udivdi3 undefined

This error occurs on 32 bit operating system. This won't come if you are using 64 bit operating system. If you wan't to avoid this error in 32 bit operating system then you will have to do following thing.

In your code wherever you are doing division by using "/" operator replace it by following
uint32_t do_div(uint64_t dividend, uint32_t divisor)


So a/b would be do_div(a/b).

RHEL Network card not detecting ( Troubleshooting network )

There might be many reasons for network not working as per our requirement. I am going to point out few things which I always do when there is some problem with network. And after working over all theses things for long time, I guess I will be covering most of the reasons for network not working as per our requirement.

Before you start, you can disable firewall using
#service iptables stop

1)You can use following command to configure your network adaptor
#system-config-network
After that you can give it IP address, netmask, broadcast address or allow it to take ip from dhcp server. Then you can save and quit and give following command.
#service network restart

2) #ifconfig
This is the command which you should use first to check if the network interfaces are as per your requirement. So this will confirm that network adaptor is enabled.

3)After this you can try connecting i.e. pinging some ip address in your network which is active. If ping does not work then mostly cable is not properly attached. You can use ethtool to figure that out.

#ethtool ethX
If cable is fine then it will show at the bottom "Link detected : yes"
Otherwise it will show "no" instead of "yes". In that case you can try fixing the cable properly.

4) If there is still problem you can check further information about network card and just cross check it with following command.
#ethtool -i ethX
This will show information about network card

5)You can also check whether network card driver has loaded properly by using following command.
#lsmod | grep


Friday, June 15, 2012

Installing Memcached with libevent and benchmarking it with memslap

Memcached is "Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load." Memcached is used by most of the companies today including Facebook, Craiglist, Flickr and Twitter. This is one of the thing which I worked on during my summer intern. I am just going to mention the steps for installing memcached and the problems which I faced doing it.

Installation:
1) Download libevent from  http://libevent.org/ . This is one of the dependency for installing memcached.

2) Extract it

3) Go inside extracted directory and type following things
#./configure --prefix=/usr/local
(If you don't put --prefix then chances are that later on while installing memcached it might give problems.)


# make && make install

4) Download source code of memcached from http://www.memcached.org/

5) Extract it

6) Go inside the extracted directory.
#./configure --libevent-with=/usr/local
# make && make install

7) You can check whether memcached is working by giving following command
# memcached -u nobody &
After that you can do 
# ps -el | grep memcached
to see if memcached is started.

8)Now its time to install memslap which is client for memcached. Its used for benchmarking purpose.

9) Download couchbase from http://www.couchbase.com/

10) Extract it and go inside libmemcached directory present in it.

11) Then build libmemcached.

# ./configure
# make

12) Now go inside clients directory present inside libmemcached and give following command
# ./memslap -s server_ip
to start benchmarking process. After some time (600s) you will get some output. You can vary parameters as per documentation of memslap.

Thursday, June 14, 2012

Installing g++ on rhel and the error " libtool: link: unsupported hardcode properties"

First let me just tell you how generally g++ is installed on RHEL and then the problem which I faced after installing that.

For RHEL,
# yum install gcc-c++

After I installed g++ on RHEL , then when I tried installing some tool/utility from its source code, I got following error "libtool: link: unsupported hardcode properties" while building the source code. This is what I did to solve this problem.

#make distclean
# ./configure
# make
# make install

And this solved my problem

No route to host error

This is one of the very common problem and at times it can be really irritating since it can be difficult to figure out the problem if you are not experienced user of linux and especially RHEL. Even after using RHEL for more than 2 years I got stuck over this problem for 4-5 hours trying to do everything possible and later realizing that problem was with firewall. Here are few steps which you can do.

1) First of all give ifconfig and check all interfaces and whether they are according to your requirement.
2) Give command #system-config-network and check network configuration
3) Check firewall rules. Disable it using
# service iptables stop

I guess in most of the cases problem must be with firewall. Remember newly installed RHEL does have firewall enabled by default. So that can cause problem if you are not experienced RHEL user.

Force user to logoff from remote or any terminal

So at times it may happen the a user logs in from remote terminal and forgets to log off. So in order to kill such a session of a remote user, following things can be done.
# who -u
This will give you the pid of the process user is using to log in.
Then you can kill that process using
#kill -9 pid

Tuesday, June 12, 2012

Registering RHEL 6

Initially when you install a new RHEL 6 on your pc and try using even basic utilities like gcc, it will show errors like no package named gcc installed. Even when you do yum install gcc it won't work and will throw errors like:

# sudo yum install gcc 
Updating Red Hat repositories.
Setting up Install Process
Error: Nothing to do
No package gcc available.

If you try
#sudo yum grouplist
Loaded plugins: product-id, subscription-manager Updating Red Hat repositories. No group data available Error: for configured repositories
If you try
#sudo yum repolist
Loaded plugins: product-id, subscription-manager
Updating Red Hat repositories.
repolist: 0

All these problems are mostly because your newly installed RHEL is not registered. You can confirm this by giving following command.
# yum repolist all

If the system is not registered it will give ouptut status as disabled. Now you can register your system with following command and then enter the required details.
# sudo rhn_register

After it has successfully registered, give following command.
#yum update

Monday, May 28, 2012

Laser chess source code (c++ and cilk++)

Here is the source code of game named laser chess (computer vs human) written in c++ and cilk++ so as to run it on super computer. In order to run this code you should install cilk++. This program can also be run on normal pc where the code will be same as running it on single core of a computer. For running it on super computer you can refer to intel's cilk++ guide. To run it on normal pc, just install cilk++ on your machine and run it. More details can be found inside manual provided along with the source code.

Manual: Laser chess
Laser chess source code (parallel version)

Serial version of this game can also be found on git@github.com:sanketp123/Laser-chess.git .


Installing and Uninstalling ubuntu kernel


Steps for installing ubuntu kernel 

  • Get the source code  
          apt-get source linux-image-$(uname -r)
  • Perform this step only for the first time you build kernel.
          Downloading dependencies
          sudo apt-get build-dep linux-image-$(uname -r)
  • Building kernel 
  • Now move inside the downloaded kernel directory and type following commands.
    fakeroot debian/rules clean
    fakeroot debian/rules binary-headers binary-generic
After this step, 3 files with .deb extension would be generated in the parent directory of your current folder. Install them using this command
  •  sudo dpkg -i linux*2.6.38-7.37*.deb
  •  Now reboot. After rebooting you can do uname -r to check whether you have booted into new kernel.  


Steps for uninstalling ubuntu kernel   

  • Open the Synaptic package manager. If its not present you can at first install it.
  • Now check your current kernel version using uname -r . Or just make a note of the kernel version which you want to remove.
  • Now inside Synaptic package manager you will find "search". Inside that type 'linux-image'. 
  • After that you will see different kernel images which are installed in your pc.
  • Now select the one which you want to remove and mark it for removal.
  • After that apply the changes to remove that kernel version.