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.