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

当前系统版本

查看当前 ntpd 版本:

           ntpd --version

当前 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

成功卸载

            解压 ntp 压缩文件:


三、编译安装ntp-4.2.8p9

            解压源码压缩文件:

                                 tar -zxvf ntp-4.2.8p12.tar.gz   

解压生成的文件夹

            进入解压生成的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 $?

返回 0 表示没有错误

              编译并安装:

                                  make && make install

               创建软链接:

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

                查看 ntp 版本:

                                        ntpd --version

成功编译安装

配置 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

已经成功启动了

                     查看 ntp 服务端口:

                                                    netstat -tunlp | grep 123

                        检查同步情况:

                                                watch ntpq -p

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

                执行同步命令:    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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,233评论 4 360
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,013评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,030评论 0 241
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,827评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,221评论 3 286
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,542评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,814评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,513评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,225评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,497评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,998评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,342评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,986评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,055评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,812评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,560评论 2 271
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,461评论 2 266