centos7-时间同步NTP安装,以及libopts.so.25问题解决
ntp时间同步服务器同来同步时间
文章目录
安装
依赖包
ntp服务安装需要三个包:
autogen-libopts-5.18-5.el7.x86_64.rpm
ntpdate-4.2.6p5-25.el7.centos.2.x86_64.rpm
ntp-4.2.6p5-25.el7.centos.2.x86_64.rpm
安装步骤
直接yum安装即可
yum -y install ntp
使用
有两种使用方法
-
执行命令来同步
ntpdate -u 202.120.2.101
-
设置为守护进程来同步
-
修改配置文件
vi /etc/ntp.conf #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 server time7.aliyun.com prefer iburst //添加一个同步服务器设置即可
-
启动守护程序
systemctl start ntpd //启动 systemctl stop ntpd //停止 systemctl status ntpd //查看服务状态 systemctl enable ntpd //设置开机自启
-
/etc/ntp.conf 配置文件
# 系统时间与BIOS事件的偏差记录
driftfile /var/lib/ntp/drift
#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地址的权限设置
restrict default nomodify notrap nopeer noquery
#确保localhost(这个常用的IP地址用来指Linux服务器本身)有足够权限.使用没有任何限制关键词的语法
restrict 127.0.0.1
restrict ::1
#
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
#设定NTP主机来源(其中prefer表示优先主机),192.168.7.49是本地的NTP服务器,所以优先指定从该主机同步时间。
server 0.centos.pool.ntp.org prefer
server 0.centos.pool.ntp.org iburst
#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 autokey # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 autokey # manycast client
# Enable public key cryptography.
#crypto
#
includefile /etc/ntp/crypto/pw
# Key file containing the keys and key identifiers used when operating
keys /etc/ntp/keys
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats
# Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-2013-5211 for more details.
# Note: Monit