Transplant NTP time synchronization tool to arm linux platform to create timing tasks
Download source code
wget -c http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.8p14.tar.gz
Unzip and compile
./configure --prefix=$PWD/install --exec-prefix=$PWD/install --host=arm-none-linux-gnueabi CC=arm-none-linux-gnueabi-gcc --with-yielding-select=yes
make
make install
A script to compile
#!/bin/sh
HOST=arm-none-linux-gnueabi
BUILD_HOST=/home/aron566/opt/arm-2014.05/bin/arm-none-linux-gnueabi-
ARM_GCC=${BUILD_HOST}gcc
ARM_CPP=${BUILD_HOST}g++
BASE=`pwd`
OUTPUT_PATH=${BASE}/install
make_dirs () {
#为了方便管理,创建有关的目录
cd ${BASE} && mkdir compressed install source -p
}
download_package () {
cd ${BASE}/compressed
#下载包
wget -c http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.8p14.tar.gz
}
tar_package () {
cd ${BASE}/compressed
ls * > /tmp/list.txt
for TAR in `cat /tmp/list.txt`
do
tar -xf $TAR -C ../source
done
rm -rf /tmp/list.txt
}
make_ntp () {
cd ${BASE}/source/ntp-4.2.8p14
./configure --prefix=$OUTPUT_PATH/ntp-4.2.8p14 --exec-prefix=$OUTPUT_PATH/ntp-4.2.8p14 --host=$HOST CC=$ARM_GCC --with-yielding-select=yes
make
make install
}
make_dirs
download_package
tar_package
make_ntp
exit $?
Upload files to the development board
Executable under the bin directory under the install directory
Copy to the /usr/bin
directory of the development board
run
Synchronize time command
ntpdate time.buptnet.edu.cn
Use date to view time
After the date command is viewed, UTC time (Universal Standard Time) is displayed, which is 8 hours away from Beijing Time (CST=UTC+8), so you need to set the time zone
Set time zone
After copying /usr/share/zoneinfo/Asia
the files in the ubuntu system directory Shanghai
to the development board directory /etc
and renamed localtime
it, use the command to reboot
restart
You can use the command to display UTC time
date -u
The system time obtained from the network is written into the hardware clock
hwclock -w
Create startup items
S92crontab
Add to the /etc/init.d
directory, add executable permissions
#!/bin/sh
#无需修改
DIRECTORY_NAME=/etc/crontabs
#无需修改
CONFIG_NAME=$DIRECTORY_NAME/root
#运行时配置,无需修改
RUN_DIRECTORY_NAME=/var/spool/cron/crontabs
RUN_CONFIG_NAME=$RUN_DIRECTORY_NAME/root
#定时任务
TASK_1="*/1 */1 */1 */1 */1 ntpdate time.buptnet.edu.cn"
TASK_2="*/1 */1 */1 */1 */1 hwclock -w"
start() {
#是否存在定时任务配置目录
if [ ! -d "${DIRECTORY_NAME}" ];then
mkdir $DIRECTORY_NAME -p
touch $CONFIG_NAME
chmod 777 $CONFIG_NAME
echo $TASK_1>>$CONFIG_NAME
echo $TASK_2>>$CONFIG_NAME
fi
mkdir -p $RUN_DIRECTORY_NAME
cp -p $CONFIG_NAME $RUN_CONFIG_NAME
chmod 777 $RUN_CONFIG_NAME
crond
[ $? = 0 ] && echo "START Crontabs OK" || echo "START Crontabs FAIL"
}
stop() {
echo "STOP Crontabs"
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?
Note that files written on windows may need to execute the following commands
dos2unix S92crontab #消除断元符
ntp server
1. Ensure that the network connection between the development board of the ntp server and the system of the ntp client is normal
2. Edit the file on the development board where the server is to be /etc/ntp.conf
executed and execute the command:
vi /etc/ntp.conf
#restrict default nomodify notrap noquery
restrict 127.0.0.1
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 5
driftfile /var/lib/ntp/drift
broadcastdelay 0.008
keys /etc/ntp/keys
3. Then open the ntp server
ntpd -c /etc/ntp.conf
4. After the ntp server is turned on, the following commands can be executed in the client system for five to ten minutes, otherwise the time synchronization will fail
ntpdate 192.168.1.48 #192.168.1.48修改成你的服务器的IP地址