Ntp Clock Synchronization in Linux: linuxntp Clock Synchronization

Source: Internet
Author: User

Ntp Clock Synchronization in Linux: linuxntp Clock Synchronization

Some time ago, there was a demand in the project. We needed to synchronize the linux and windows Time. There were also many posts on the Internet similar to clock synchronization, which was roughly similar. However, this linux machine was a bit special, there is no service command, and it is required to connect to the target linux machine through scripts on another suse linux machine for clock synchronization. At first, I was also troubled for a long time, but the methods were all developed by people. Next I will describe the implementation process:

Operating linux -------- destination linux ---------- destination windows

1. there are three machines, the linux where the script is located ---- operating linux, the client machine to be synchronized ----- destination linux, clock source machine ----- destination windows; first, enable the clock synchronization service for both the target linux and the target Windows. Many posts on the Internet will not be mentioned here;

2. establish a trust relationship between operating linux and the target linux (operate linux to generate a key and hand it over to the target linux so that the two do not need to enter a password for ssh connection through scripts ), this is also available on the Internet. Let's talk about it;

3. Write a synchronization script on linux:

Because there is no service command, you can only use the process that kills ntpd first to disable the ntp service. Originally, you wanted to kill the process by checking the process Number of ntpd, however, in EOF, you cannot use the ps command to find the process number of a remote machine. You can only find the process Number of the Local Machine. Instead, you have to use pkill to match the process name to kill the process, however, there are only two ntpd-related processes on the machine, one of which is the process I am searching for, so it is okay to use this.

(Process number = ps-ef | grep ntpd | grep-v grep | awk '{print $1 }')

Ssh root @ destination linux IP address <EOF
Cd/share/init/ntp
Pkill-9 ntpd
./Ntpdate destination windows ip Address
Echo "server ip prefer for windows">/etc/ntp. conf
./Ntpd
EOF

The above is part of the script, which is the main content. If you are interested, you can go into it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.