Centos 7.4 升级 NTP 到 4.2.8p12 版本

    升级ntp主要是为了解决系统安全问题:

                    因为    centos7.4系统中默认安装的是 ntp 4.2.6p5版本,但是此版本漏洞很多,很容易被攻击导致无法提供服务等等问题。下面的链接是ntp 4.2.6p5版本漏洞详细:

                                    https://www.jianshu.com/p/a6a761617736

查看当前系统版本:

                             cat /etc/system-release

《Centos 7.4 升级 NTP 到 4.2.8p12 版本》 当前系统版本

查看当前 ntpd 版本:

                                ntpd –version

《Centos 7.4 升级 NTP 到 4.2.8p12 版本》 当前 ntpd 版本

一、 系统与软件版本**

          系统版本:

                                CentOS7.4

          ntpd软件版本:

                                ntp-4.2.8p12

          下载地址:

                                Windows下载地址:http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.8p12.tar.gz

                                Linux 下载地址:wget http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.8p12.tar.gz

二、安装准备

            安装依赖包:

                                yum install gcc gcc-c++ openssl-devel libstdc++* libcap*

            备份旧版本的配置文件:(不需要备份的话请跳过)

            建议备份因为源码安装不会生成配置文件如果不备份的话我会在下面贴出配置文件的内容

                                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

《Centos 7.4 升级 NTP 到 4.2.8p12 版本》 成功卸载

            解压 ntp 压缩文件:

三、编译安装ntp-4.2.8p9

            解压源码压缩文件:

                                 tar -zxvf ntp-4.2.8p12.tar.gz   

《Centos 7.4 升级 NTP 到 4.2.8p12 版本》 解压生成的文件夹

            进入解压生成的ntp-4.2.8p9文件夹:

                                cd ntp-4.2.8p12/

            编译安装ntpd:

./configure \

–prefix=/usr \

–bindir=/usr/sbin \

–enable-all-clocks \

–enable-parse-clocks \

–docdir=/usr/share/doc/ntp-4.2.8p12

                命令详解:

                                –prefix=安装的目录   

                                –bindir=会将主程序放置到这个文件夹

                                –docdir=doc文档的存放目录

                查看运行是否有错误:

                                                  执行:  echo $?

《Centos 7.4 升级 NTP 到 4.2.8p12 版本》 返回 0 表示没有错误

              编译并安装:

                                  make && make install

               创建软链接:

                                    ln -s /usr/local/ntp-4.2.8p12 /usr/local/ntp

                查看 ntp 版本:

                                        ntpd –version

《Centos 7.4 升级 NTP 到 4.2.8p12 版本》 成功编译安装

配置 ntp :

                执行 vim /etc/ntp.conf

                这个配置文件是将此节点配置成本地服务 server 端:

本地其他机器可以使用命令:        ntpdate mongodb04            来和此节点同步时间

添加以下配置:

# For more information about this file, see the man pages

# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

# Permit time synchronization with our time source, but do not

# permit the source to query or modify the service on this system.

restrict default nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could

# be tightened as well, but to do so would effect some of

# the administrative functions.

restrict 127.0.0.1

restrict ::1

# Hosts on local network are less restricted.

restrict 192.168.215.0 mask 255.255.255.0 nomodify notrap

# 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

server 127.127.1.0  # local clock

fudge 127.127.1.0 stratum 10

includefile /etc/ntp/crypto/pw

# Key file containing the keys and key identifiers used when operating

# with symmetric key cryptography.

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: Monitoring will not be disabled with the limited restriction flag.

disable monitor

                    然后就是启动 ntp 服务了:

                                                             /usr/sbin/ntpd -c /etc/ntp.conf

                    查看 ntp 服务是否启动:

                                                            ps -ef | grep ntpd

《Centos 7.4 升级 NTP 到 4.2.8p12 版本》 已经成功启动了

                     查看 ntp 服务端口:

                                                    netstat -tunlp | grep 123

《Centos 7.4 升级 NTP 到 4.2.8p12 版本》

                        检查同步情况:

                                                watch ntpq -p

《Centos 7.4 升级 NTP 到 4.2.8p12 版本》

在启动之后短时间内可能无法和此节点同步时间可能会出现下面的问题:

                执行同步命令:    ntpdate mongodb04

                                31 Aug 00:34:43 ntpdate[18417]: no server suitable for synchronization found

稍微等一会在进行同步:

                执行同步命令:    ntpdate mongodb04

                                31 Aug 00:39:20 ntpdate[18684]: adjust time server 192.168.215.184 offset -0.111364 sec

    原文作者:Smile_Laugh
    原文地址: https://www.jianshu.com/p/33933c240f59
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞