ntp安装、升级

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

  • 28
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值