我ntp-4.2.8
使用以下方式编译并安装此链接checkinstall
并通过在 上 运行创建了一个 rpm RHEL 6.5
。
我使用命令ntpd -l logs
手动启动ntpd。
启动后,我可以使用命令验证 ntp:
bash-4.1# ntpq -pn
remote refid st t when poll reach delay offset jitter
==============================================================================
209.118.204.201 .INIT. 16 u - 64 0 0.000 0.000 0.000
66.228.42.59 .INIT. 16 u - 64 0 0.000 0.000 0.000
97.107.129.217 .INIT. 16 u - 64 0 0.000 0.000 0.000
198.60.22.240 .INIT. 16 u - 64 0 0.000 0.000 0.000
bash-4.1#
运行 chkconfig 时,它会抛出错误:
bash-4.1# chkconfig --list ntpd
读取服务 ntpd 上的信息时出错:没有该文件或目录
检查路径/etc/init.d
,发现ntpd
其中不存在服务名称。
现在我复制了该位置的ntpd
二进制文件/etc/init.d
并执行了以下命令:
服务 ntpd 启动
现在我可以看到 ntpd 进程正在运行
bash-4.1# ps -aef | grep ntp
root 12409 20389 0 08:16 pts/2 00:00:00 grep ntp
root 30522 1 0 08:03 ? 00:00:00 /etc/init.d/ntpd start
但是当我运行服务命令时,我没有看到任何 ntpd 服务正在运行
bash-4.1# service --status-all | grep ntpd
bash-4.1#
并再次尝试该chkconfig
命令:
bash-4.1# chkconfig --list ntpd
service ntpd does not support chkconfig
现在我尝试使用 chkconfig 命令添加它但再次抛出错误:
bash-4.1# chkconfig --add ntpd
service ntpd does not support chkconfig
但是当我ntp-4.2.6p5-1.el6.x86_64.rpm
从iso
它安装时,它会自动添加到init.d
文件中并自行启动。
我应该在哪里以及如何进行输入ntp-4.2.8
以便它作为服务自动启动。
答案1
这是我的初始化文件 - 您可以尝试一下,检查您的路径等是否都正确;
#!/bin/bash
#
# ntpd This shell script takes care of starting and stopping
# ntpd (NTPv4 daemon).
#
# chkconfig: - 58 74
# description: ntpd is the NTPv4 daemon. \
# The Network Time Protocol (NTP) is used to synchronize the time of \
# a computer client or server to another server or reference time source, \
# such as a radio or satellite receiver or modem.
### BEGIN INIT INFO
# Provides: ntpd
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Should-Start: $syslog $named ntpdate
# Should-Stop: $syslog $named
# Short-Description: start and stop ntpd
# Description: ntpd is the NTPv4 daemon. The Network Time Protocol (NTP)
# is used to synchronize the time of a computer client or
# server to another server or reference time source, such
# as a radio or satellite receiver or modem.
### END INIT INFO
# Source function library.
. /etc/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
prog=ntpd
lockfile=/var/lock/subsys/$prog
start() {
[ "$EUID" != "0" ] && exit 4
[ "$NETWORKING" = "no" ] && exit 1
[ -x /usr/sbin/ntpd ] || exit 5
[ -f /etc/sysconfig/ntpd ] || exit 6
. /etc/sysconfig/ntpd
# Start daemons.
echo -n $"Starting $prog: "
daemon $prog $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $lockfile
return $RETVAL
}
stop() {
[ "$EUID" != "0" ] && exit 4
echo -n $"Shutting down $prog: "
killproc $prog
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $lockfile
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $prog
;;
restart|force-reload)
stop
start
;;
try-restart|condrestart)
if status $prog > /dev/null; then
stop
start
fi
;;
reload)
exit 3
;;
*)
echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"
exit 2
esac
要检查其在正确的运行级别调用,您需要执行chkconfig --add ntpd
并chkconfig ntpd on
允许执行权限chmod +x ntpd