background
When building a ETCD cluster, synchronization errors occur if the host time varies too much, and internal NTP server synchronization time is required if the external network is not available.
building an NTP imageCreate Dockerfile
# usage:# Docker build-T NTP. # Docker run Docker run-D--name Ntp-server-p123:123-v/etc/localtime:/etc/localtime:ro-v/etc/timezone:/etc/Timezone:ro ntpfrom Nginxrunsed-I. s/archive.ubuntu.com/mirrors.aliyun.com/g/etc/apt/sources.list&&sed-I. s/security.ubuntu.com/mirrors.aliyun.com/g/etc/apt/sources.list&& apt-Get Updaterun apt-getInstallNTP-Yadd./entrypoint.SH/bin/entrypoint.SHADD./ntp.conf/etc/ntp.conf# entrypoint ["/ETC/INIT.D/NTP","Start"]cmd ["SH","/bin/entrypoint.sh"]
Create a entrypoint.sh file
/etc/init.d/'daemon off; '
Create npt.conf
Restrict default nomodify notrap noqueryrestrict127.0.0.1Restrict192.168.0.0Mask255.255.255.0nomodifyrestrict10.10.10.0Mask255.255.255.0Nomodify#server0. Pool.ntp.org#server1. Pool.ntp.org#server2. Pool.ntp.orgserver127.127.1.0# local Clockfudge127.127.1.0StratumTenDriftfile/var/lib/ntp/Driftbroadcastdelay0.008
Build image
Docker build-t NTP.
start the NTP server
Docker run-d--name ntp-server-p 123:123-v/etc/localtime:/etc/localtime:ro-v/etc/timezone:/etc/timezone:ro NTP
View service Status
Docker exec-it ntp-server Service NTP status
Client Configuration
The current running container does not need to configure the client
Client and server cannot run on the same machine
The current server is using the host's time as the standard Time
Installing Ntpdate
sudo Install ntpdate
Synchronize host Time
sudo 192.168. 0.20
The IP here is the host that the NTP container is running on
Configure Scheduled Task update time
By the following command, you can open the user's timing files, files stored in the/var/spool/cron/crontabs folder, and the name of the file named
You can use the following command to list the details of a cron service for a user
Crontab-l
Edit the timed task with the following command
Crontab-e
Add at end of file
192.168. 0.20
Some common cycles
Executes every five minutes */5 * * * * hourly execution 0 * * * * daily execution 00 * * * Weekly execution c10/>000 monthly execution 001 * * Annual execution 0011 *
Restart Timed Task Service
sudo service cron restart
View Logs
Ten -f-u cron
Docker build NTP server