In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains the "Linux server time synchronization how to achieve", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Linux server time synchronization how to achieve" it!
First, the server installs the NTP time correction package and modifies the independent host
Rm-rf / etc/localtime # clears the original linked file first
Ln-s / usr/share/zoneinfo/Asia/Shanghai / etc/localtime # modify the time zone to East 8.
The time zone setting for date-R # viewing.
Then adjust the system time to synchronize with the time server
Install the NTP time correction package on the Debian system:
The code is as follows:
Apt-get install ntpdate # install ntp
Install the NTP time correction package on the CentOS system:
The code is as follows:
Yum-y install ntpdate ntp # install ntp
Install the NTP time correction package on the Ubuntu system:
The code is as follows:
Sudo apt-get install-y ntpdate ntp
II. Modify / etc/ntp.conf configuration file on server side
Edit / etc/ntp.conf
Server cn.pool.ntp.org restrict default nomodifynotrapnoquery restrict 127.0.0.1 # enable internal recursive network interface lo restrict 192.168.9.0 mask 255.255.255.0 nomodifynotrap # clients in the internal subnet can perform network time correction, but cannot modify the time parameters of the NTP server
Because the local time is configured, you also need to configure a NTP server that uses the system clock as the time source, and you need to add the following records in the / etc/ntp.conf file:
Server 127.127.1.0 fudge 127.127.1.0 stratum 10
Then save and exit.
Then enter the following command:
Ntpdate-d cn.pool.ntp.org # Debug View time difference ntpdate cn.pool.ntp.org # Manual Calibration system time date-R # check whether the time is synchronized
Server side modifies the system configuration of ntpd
Vi / etc/sysconfig/ntpd SYNC_HWCLOCK=yes # synchronizes the hardware clock of an independent host
Then: wq exits
Chkconfig-- levels 235 ntpd on # configure boot to start ntp service, periodically synchronize time / etc/init.d/ntpd start# to start ntp synchronization
4. Configure ntpd service on client side
Note: the client side ensures a smooth network with the server side.
Edit the / etc/ntp.conf file and comment out the first two lines
# restrict default kod nomodify notrap nopeer noquery # restrict-6 default kod nomodify notrap nopeer noquery # server 0.centos.pool.ntp.org iburst # server 1.centos.pool.ntp.org iburst # server 2.centos.pool.ntp.org iburst # server 3.centos.pool.ntp.org iburst
Add to it
Restrict server address nomodify
Server server address prefer
Service ntpd start starts the ntpd service
Chkconfig ntpd on adds boot entry
Check the operation of ntpd (network connectivity (whether 123ports are open) and synchronization)
Ntpq-p to see if the output is correct
Date-R View time per machine
If the firewall rules under linux are very strict, it may affect the ntpd alignment. Just open sport 123.
Iptables-I INPUT-p udp-m udp-- sport 123-j ACCEPT
Time synchronization ② between intranet linux servers
First, set the master machine, set the time zone, and then modify the configuration file.
Rm-rf / etc/localtime # first clear the original link file ln-s / usr/share/zoneinfo/Asia/Shanghai / etc/localtime # to modify the time zone to East 8. The time zone setting for date-R # viewing. Change local time to standard time
Hwclock-- systohc & & hwclock-w use system time to brush in hardware time
Edit / etc/ntp.conf file
Add to it
Restrict 127.0.0.1 # enable internal recursive network interface lo restrict 192.168.5.0 mask 255.255.255.0 nomodify # clients in the internal subnet can perform network time correction, but cannot modify the time parameters of the NTP server
Because the local time is configured, you also need to configure a NTP server that uses the system clock as the time source, and you need to add the following records in the / etc/ntp.conf file:
Server 127.127.1.0 fudge 127.127.1.0 stratun 10
In the above record:
The specified IP address is a "pseudo" IP address that determines the local system as the time source.
The specified IP address 127.127.1.1 tells NTP to use the internal clock as the time source.
"fudge" defines the level of the clock, and without this record, the node is the first-tier server. It is a good idea to redefine the level to 10 so that the client will know that the server is not a reliable source of time when querying the server.
This method of time synchronization should only be used when the local network cannot use an external time source.
Start the ntp service
Service ntpd start
Set up boot boot
Chkconfig ntpd on
Then configure the client to edit the / etc/crontab file on the host 192.168.5.103, which is used to set the node to synchronize time like the master server every minute.
The settings are as follows:
* root / usr/sbin/ntpdate 192.168.5.102
Check to see if the time is consistent
* it is mentioned that ntp service only synchronizes system time by default. If you want ntp to synchronize hardware time at the same time, you can set the / etc/sysconfig/ntpd file.
In the / etc/sysconfig/ntpd file, add SYNC_HWCLOCK=yes so that the hardware time is synchronized with the system time.
The automatic script is as follows:
#! / bin/bash cat > / etc/ntp.conf restrict 127.0.0.1 restrict 192.168.5.0 mask 255.255.255.0 nomodify server 127.127.1.0 fudge 127.127.1.0 stratun 10 EOF service ntp restart chkconfig ntpd on # client modification echo > >
Update script 2
#! / bin/bash # backup the source file mv / etc/localtime / etc/localtimebak # modify the time zone to ln-s / usr/share/zoneinfo/Asia/Shanghai / etc/localtime # calibrate the current time date-s "2017-10-24 12:09:38" # use the system time to brush in the hardware time hwclock-- systohc # modify the configuration file cat > / etc/ntp.conf restrict 127.0.0.1 Restrict 192.168.9.0 mask 255.255.255.0 nomodify server 127.127.1.0 fudge 127.127.1.0 stratun 10 EOF # restart self-booting service ntpd restart chkconfig ntpd on
Time synchronization ③ is set on a single machine in the public network
Install the NTP time correction package and modify the independent host
Rm-rf / etc/localtime # first clear the original link file ln-s / usr/share/zoneinfo/Asia/Shanghai / etc/localtime # to modify the time zone to East 8. The time zone setting for date-R # viewing.
Then adjust the system time to synchronize with the time server
Install the NTP time correction package on the Debian system:
The code is as follows:
Apt-get install ntpdate # install ntp
Install the NTP time correction package on the CentOS system:
The code is as follows:
Yum-y install ntpdate ntp # install ntp
Install the NTP time correction package on the Ubuntu system:
The code is as follows:
Sudo apt-get install-y ntpdate ntp
II. Modify / etc/ntp.conf configuration file
Vi / etc/ntp.conf will see the following:
Server 0.centos.ntp.org server time.windows.com server time.nist.gov
This is the default ntp synchronization server. You can change it yourself.
I changed it to:
Server cn.pool.ntp.org server time-a.nist.gov server time.windows.com server time.nist.gov
Then save and exit.
Then enter the following command:
Ntpdate-d cn.pool.ntp.org # Debug check time difference ntpdate cn.pool.ntp.org # synchronization time date-R # check whether the time is synchronized
Modify the system configuration of ntp
Vi / etc/sysconfig/ntpd SYNC_HWCLOCK=yes # synchronizes the hardware clock of an independent host
Then: wq exits
Chkconfig-- levels 235 ntpd on # configure boot to start ntp service, periodically synchronize time / etc/init.d/ntpd start# to start ntp synchronization
The automatic script is as follows:
#! / bin/bash # backup source file mv / etc/localtime / etc/localtimebak # modify time zone to East eighth Zone ln-s / usr/share/zoneinfo/Asia/Shanghai / etc/localtime # install ntp service yum-y install ntpdate ntp # modify / etc/ntp.conf cat > / etc/ntp.conf server cn.pool.ntp.org server time-a.nist.gov server time.windows.com server time.nist.gov EOF # debug view Time difference ntpdate-d cn.pool.ntp.org # synchronization time ntpdate cn.pool.ntp.org & & echo "SYNC_HWCLOCK=yes" > > / etc/sysconfig/ntpd | | echo "Setting Filed!" # self-launch chkconfig-- levels 235 ntpd on / etc/init.d/ntpd start echo `date` Thank you for reading The above is the content of "how to achieve Linux server time synchronization". After the study of this article, I believe you have a deeper understanding of how to achieve Linux server time synchronization, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.