安装libressl后升级ntp

 NTP 是网络时间协议(Network Time Protocol)的简称

生成libssl.so.10和libcrypto.so.10文件

一.强制卸载OpenSSL:
rpm -e --nodeps openssl
二.卸载后重装OpenSSL提示:
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

libssl.so.10: cannot open shared object file: No such file or directory

Please install a package which provides this module, or
verify that the module is installed correctly.

It’s possible that the above module doesn’t match the
current version of Python, which is:
2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]

If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq

三.解决方案
1.下载:https://www.openssl.org/source/old/1.0.1/openssl-1.0.1e.tar.gz 上传到服务器,

tar xvf openssl-1.0.1e.tar.gz
cd openssl-1.0.1e
./config shared zlib-dynamic   #生成Makefile文件
make            #生成libssl.so.1.0.0 和 libcrypto.so.1.0.0
cp  libssl.so.1.0.0  /usr/lib64
cp libcrypto.so.1.0.0  /usr/lib64
cd /usr/lib64
ln -s libssl.so.1.0.0 libssl.so.10
ln -s libcrypto.so.1.0.0 libcrypto.so.10

编译安装ntp

./configure --prefix=/usr/local/ntp --bindir=/usr/sbin --sysconfdir=/etc

make && make install

#!/bin/bash
# chkconfig: - 58 74
. /etc/init.d/functions
. /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

配置文件介绍

#系统时间与BIOS事件的偏差记录
driftfile /etc/ntp/drift
#设定NTP主机来源(其中prefer表示优先主机)
server 192.168.7.49 prefer  

restrict 控制相关权限。
语法为: restrict IP地址 mask 子网掩码 参数
其中IP地址也可以是default ,default 就是指所有的IP
参数有以下几个:

ignore  :关闭所有的 NTP 联机服务
nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。
notrust :客户端除非通过认证,否则该客户端来源将被视为不信任子网
noquery :不提供客户端的时间查询:用户端不能使用ntpq,ntpc等命令来查询ntp服务器
notrap :不提供trap远端登陆:拒绝为匹配的主机提供模式 6 控制消息陷阱服务。陷阱服务是 ntpdq 控制消息协议的子系统,用于远程事件日志记录程序。
nopeer :用于阻止主机尝试与服务器对等,并允许欺诈性服务器控制时钟
kod : 访问违规时发送 KoD 包。
restrict -6 表示IPV6地址的权限设置。

客户机与服务器时间同步

[root@cdh2 ~]# ntpdate -u 192.168.20.134

  1. 查看时间是否同步

[root@cdh2 ~]# ntpq -p 
remote refid st t when poll reach delay offset jitter
============================================================================== 
cdh1  LOCAL(0)  6 u 14  64  3   1.092  9.130  3.475
remote   #列出源的 IP 地址或主机名,“+”表示优先,“*”表示次优先
refid    #参考上一层ntp主机地址
st       #stratum阶层
when     #多少秒前曾经同步过时间
poll     #指出轮询间隔时间。该值会根据本地时钟的精度相应增加。
reach    #是一个八进制数字,指出源的可存取性。值 377 表示源已应答了前八个连续轮询。
delay    #网络延迟
offset   #是源时钟与本地时钟的时间差(毫秒)
jitter   #系统时间与bios时间差

查看时间,东部标准时间 (EST),这样会导致看到的时间不一致,需要修改时区。

# date
2019年 01月 04日 星期五 04:12:05 EST
# dpkg-reconfigure tzdata  #更改时区
# date  #查看当前系统时间
2019年 01月 04日 星期五 17:59:20 CST
hwclock  #查看当前硬件时间
date -s "2018-01-01 11:20:30"  #设置系统时间,字符串形式
hwclock --systohc  #将系统时间同步到硬件

ntpd、ntpdate的区别

ntpd可以是服务端,也可以是客户端,平滑同步

ntpdate立即同步,在生产环境中慎用ntpdate,也正如此两者不可同时运行。

由于是跳变,而不是使时间变快或变慢,依赖时序的程序会出错(例如,如果ntpdate发现你的时间快了,则可能会经历两个相同的时刻,对某些应用而言,这是致命的)。因而,唯一一个可以令时间发生跳变的点,是计算机刚刚启动,但还没有启动很多服务的那个时候。其余的时候,理想的做法是使用ntpd来校准时钟,而不是调整计算机时钟上的时间。

NTPD 在和时间服务器的同步过程中,会把 BIOS 计时器的振荡频率偏差——或者说 Local Clock 的自然漂移(drift)——记录下来。这样即使网络有问题,本机仍然能维持一个相当精确的走时。


原文地址:https://www.cnblogs.com/linuxws/p/12181028.html