Monthly Archives: April 2011

NTP server setting and synchronize two linux machines.

Software:NtpServer

From ROBOVIS Public Wiki

Jump to: navigationsearch

Sometimes when out in the field, several machines need to be time-synchronised. It usually isn’t super-important if the absolute time is wrong, just so long as the relative time differences between machines is very small. To do this:

  1. Pick a master computer. All the others will synch to this.
  2. Set up the master to sync to absolute time when in the lab, and itself

when in the field.

  1. Set up all the others to sync to the master.

Note that this how-to refers to some debian/ubuntu specific commands. For the most part, the ntp stuff is OS independent.

Contents

[hide]

[edit] Install

Before you start, install everything with:

# apt-get install ntp ntpdate

on all machines.

[edit] Set up the Master

Copy the following into the master’s /etc/ntp.conf:

# /etc/ntp.conf, configuration for ntpd

driftfile /var/lib/ntp/ntp.drift
statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

# You do need to talk to an NTP server or two (or three).
server ntp0.uq.edu.au

# ... and use the local system clock as a reference if all else fails
# NOTE: in a local network, set the local stratum of *one* stable server
# to 10; otherwise your clocks will drift apart if you lose connectivity.
server 127.127.1.0
fudge 127.127.1.0 stratum 5

# By default, exchange time with everybody, but don't allow configuration.
# See /usr/share/doc/ntp-doc/html/accopt.html for details.
restrict default kod notrap nomodify nopeer noquery

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1 nomodify

Note:

  • We try to lock to ntp0.uq.edu.au
  • 127.127.1.0 says ‘lock to myself’ (ignore the fact that this isn’t your

IP). – It is an ID for an internal ntp reference clock based on your hardware clock.

  • Our stratum (5) is lower than ntp.uq’s (2). This tells ntp that

ntp.uq’s clock is more reliable than ours.

[edit] Set up the Slaves

Copy the following into /etc/ntp.conf on each slave (ntp clients):

# /etc/ntp.conf, configuration for ntpd

driftfile /var/lib/ntp/ntp.drift
statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

# You do need to talk to an NTP server or two (or three).
server <master>

# By default, exchange time with everybody, but don't allow configuration.
# See /usr/share/doc/ntp-doc/html/accopt.html for details.
restrict default kod notrap nomodify nopeer noquery

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1 nomodify

Note:

  • replace <master> with the name or IP of your master.

[edit] Start and Test Everything

Start the ntp daemon on the master:

[root@master]# /etc/init.d/ntp stop
[root@master]# /usr/sbin/ntpdate ntp.usyd.edu.au
[root@master]# /etc/init.d/ntp start

Wait for the master to lock to something. You can see what’s going on with:

# ntpq -p

An ‘*’ in the first column signifies the server that we’re locked to. Be patient, it takes a few minutes for things to synch.

Then fire up the slaves:

[root@slave]# /etc/init.d/ntp stop
[root@slave]# /usr/sbin/ntpdate &lt;master&gt;
[root@slave]# /etc/init.d/ntp start

The ‘ntpdate’ line does a coarse synch to the master.

Then watch with ‘ntpq -p’. Hopefully the slaves will eventually lock to the master.

 

VMware error messages.

If you encounter this message while staring your vmware.

Could not connect Ethernet0 to virtual network “/dev/vmnet8″. More information can be found in the vmware.log file. Virtual device Ethernet0 will start disconnected.

Manually loading vmnet driver and restart vmnetwork.

# modprobe vmnet
# VMware-networks –start

In addition

Failed to open device “/dev/vmci”: No such file or directoryPlease make sure that the kernel module ‘vmci’ is loaded.Module DevicePowerOn power on failed.

For this message

sudo modprob vmci

C language, array size. simple but important.

<span style="font-family: monospace;">Just think about the following code.</span>
<code><dfn>#include&lt;iostream&gt;</dfn>
<var>using</var> <var>namespace</var> std;
<var>int</var> main()
{
    <var>int</var> a[]={1,2,3,4,5,6};
    <var>int</var> size;
    size=<var>sizeof(</var>a)/<var>sizeof</var>(<var>int</var>);      <cite>//total size of array/size of array data type</cite>
    cout&lt;&lt;size;                     
    <var>return</var> 0;
}</code>
<span style="font-family: monospace;">Totally simple and make sense.</span>
<span style="font-family: monospace;">Could you explain why sizeof(a) instead sizeof(a[]).</span>
<span style="font-family: monospace;">
</span>