Ntp:系统自带,网络时间同步
提供时间同步的服务器:http://www.ntp.org.cn/pool
常用命令:
ntpq –p 查看本地NTP与上级服务器的通讯情况
ntpdate 192.168.100.10 手动同步
Ntp:一台机器作为服务端、其他机器客户端
升级:https://www.fcblog.cn/post/42.html
1、yum安装
查看版本:ntpd --version 卸载ntp:yum remove ntp ntpdate
服务端:
yum install ntp ntpdate ntpdate(默认安装,可以只装ntp)
修改配置文件:vi /etc/ntpd.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
添加ntp池:
Server 127.127.1.0 iburst
启动ntp:systemctl start ntpd
设置开机自启:systemctl enable ntpd
查看ntp状态:ntpstat
防火墙设置:打开udp123端口
Firewall-cmd –permanent –add-port=123/udp
Firewall-cmd –reload
查看已打开端口: iptables –L -n
客户端:
Yum install ntp
修改配置: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
添加一行:这里是ntp服务器ip
Server 服务器ip
时间同步:ntpdate –u 服务器ip
启动服务:systemctl start ntpd
设置自启:systemctl enable ntpd
2、包安装:
安装依赖包:yum install gcc gcc-c++ openssl-devel libstdc++* libcap*
Rpm包:
rpm –ivh rpm包、修改配置、启动服务
Tar包:
tar -zxvf ntp-4.2.8p12.tar.gz cd ntp-4.2.8p12/
./configure --prefix=/usr --bindir=/usr/sbin --enable-all-clocks --enable-parse-clocks --docdir=/usr/share/doc/ntp-4.2.8p12
编译并安装: make && make install
修改配置: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
添加一行:这里是ntp服务器ip
Server 服务器ip
启动 ntp 服务:/usr/sbin/ntpd -c /etc/ntp.conf
查看 ntp 服务是否启动:ps -ef | grep ntpd
查看 ntp 服务端口:netstat -tunlp | grep 123
时间同步:ntpdate –u 服务器ip
ntpd启动后,客户机要等几分钟再与其进行时间同步,否则会提示“no server suitable for synchronization found”错误。
3、Ntp客户端升级:
备份: cp -ar /etc/ntp /etc/ntp.bak
cp /etc/ntp.conf /etc/ntp.conf.bak
cp /etc/init.d/ntpd /etc/init.d/ntpd.bak
cp /etc/sysconfig/ntpd /etc/sysconfig/ntpd.bak
cp /etc/sysconfig/ntpdate /etc/sysconfig/ntpdate.bak
卸载yum安装的ntpd服务:yum remove ntp ntpdate
解压源码压缩文件:tar -zxvf ntp-4.2.8p12.tar.gz
cd ntp-4.2.8p12/
./configure --prefix=/usr --bindir=/usr/sbin --enable-all-clocks --enable-parse-clocks --docdir=/usr/share/doc/ntp-4.2.8p12
编译并安装: make && make install
--prefix安装的目录 --bindir会将主程序放置到这个文件夹 --docdir=doc文档的存放目录
创建软链接:ln -s /usr/local/ntp-4.2.8p12 /usr/local/ntp
查看 ntp 版本:ntpd --version
恢复备份:cp /etc/ntp.conf.bak /etc/ntp.conf。
启动 ntp 服务:/usr/sbin/ntpd -c /etc/ntp.conf
查看 ntp 服务是否启动:ps -ef | grep ntpd
查看 ntp 服务端口:netstat -tunlp | grep 123