Linux系统时区设置
timedatectl set-timezone Asia/Shanghai (这里是设置亚洲上海上海)
Linux NTP服务器部署安装及配置
一、linux NTP服务器部署安装
1、验证服务器端NTP服务是否已安装
[root@vm ~]# rpm -qa ntp*
ntpdate-4.2.6p5-12.el6.centos.2.x86_64
ntp-4.2.6p5-12.el6.centos.2.x86_64
2、若系统为安装ntp服务 ,可通过rpm或yum进行安装
[root@vm ~]# yum install ntp -y
[root@vm ~]# rpm -ql ntp
/etc/ntp.conf # ntp服务器的主配置文件
/etc/rc.d/init.d/ntpd # 开机启动ntpd脚本文件
3、国内稳定NTP时间同步服务器域名
times.aliyun.com
ntp.aliyun.com
4、使用ntpdate同步时间服务器
[root@vm ~]# ntpdate times.aliyun.com
17 Oct 10:05:27 ntpdate[26878]: step time server 120.25.115.19 offset 4.115593 sec
二、linux NTP服务配置
1、NTP服务 ntp.conf 参数详解
默认ntp.conf内容如下
[root@vm ~]# vi /etc/ntp.conf
#系统时间与BIOS事件的偏差记录
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery # 拒绝所有IPv4的client连接此NTP服务器
restrict -6 default kod nomodify notrap nopeer noquery # 拒绝所有IPv6的client连接此NTP服务器
restrict 127.0.0.1 # 放行本机localhost对NTP服务的访问
restrict -6 ::1
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap # 放行192.168.1.0网段主机与NTP服务器进行时间同步
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
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
#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
# with symmetric key cryptography.
keys /etc/ntp/keys
----
各项参数详解
利用restrict 来管理权限控制
Restrict [IP] mask [netmask_IP] [parameter]
Parameter 的
ignore :拒绝所有类型的NTP联机。
nomodify: 客户端不能使用ntpc与ntpq这两个程序来修改服务器的时间参数,但客户端可透过这部主机来进行网络校时;
noquery:客户端不能够使用ntpc与ntpq等指令来查询时间服务器,不提供NTP的网络校时。
notrap:不提供trap 这个运程事件登入的功能。
notrust:拒绝没有认证的客户端。
Kod:kod技术可以阻止“Kiss of Death “包对服务器的破坏。
Nopeer:不与其他同一层的NTP服务器进行时间同步。
利用server 设定上层NTP服务器,格式如下:
server [IP or hostname] [prefer]
参数主要如下:
perfer:表示优先级最高
burst :当一个运程NTP服务器可用时,向它发送一系列的并发包进行检测。
iburst :当一个运程NTP服务器不可用时,向它发送一系列的并发包进行检测。
2、配置NTPserver
调整NTP配置文件\
[root@vm ~]# vi /etc/ntp.conf
Hosts on local network are less restricted.
允许局域网内设备与这台服务器进行同步时间.但是拒绝让他们修改服务器上的时间
restrict 192.168.23.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.20.0 mask 255.255.255.0 nomodify notrap
restrict 172.16.10.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.100.0 mask 255.255.255.0 nomodify notrap
允许上层时间服务器修改本机时间
restrict times.aliyun.com nomodify
restrict ntp.aliyun.com nomodify
restrict cn.pool.ntp.org nomodify
定义要同步的时间服务器
server times.aliyun.com iburst prefer # prefer表示为优先,表示本机优先同步该服务器时间
server ntp.aliyun.com iburst
server cn.pool.ntp.org iburst
logfile /var/log/ntpstats/ntpd.log # 定义ntp日志目录
pidfile /var/run/ntp.pid # 定义pid路径
Key file containing the keys and key identifiers used when operating
with symmetric key cryptography.
keys /etc/ntp/keys
ntp服务启动
[root@vm ~]# chkconfig ntpd on
[root@vm ~]# service ntpd start
Starting ntpd: [ OK ]
[root@vm ~]# ss -tunlp | grep ntp
udp UNCONN 0 0 192.168.23.100:123 : users:(("ntpd",24250,19))
udp UNCONN 0 0 127.0.0.1:123 : users:(("ntpd",24250,18))
udp UNCONN 0 0 :123 : users:(("ntpd",24250,16))
udp UNCONN 0 0 fe80::92b1:1cff:fe10:3a44:123 ::: users:(("ntpd",24250,21))
udp UNCONN 0 0 ::1:123 ::