Centos7はNTPサーバーのインストール設定に注意します

1.目標

centos7にntpサーバーをインストールしてセットアップします。

centos7でntpクライアントを設定します。

2.アーキテクチャ

NTPアーキテクチャ
ip 役割 OSとモジュール
10.1.1.5 ntpサーバー centos 7.6、ntpd
10.1.1.6 ntpクライアント centos 7.6、ntpd

3、ntpサーバーのインストールと構成

1.ntpコンポーネントをインストールします

yum install -y ntp ntpdate -y

2.サーバー上のntpコンポーネントを照会します(省略できます)

[root@ntpserver ~]# rpm -qa |grep ntp
fontpackages-filesystem-1.44-8.el7.noarch
python-ntplib-0.3.2-1.el7.noarch
ntpdate-4.2.6p5-29.el7.centos.2.x86_64
ntp-4.2.6p5-29.el7.centos.2.x86_64

3.ntpサーバー構成ファイルを変更します

cp /etc/ntp.conf{,.bak}
vim /etc/ntp.conf

●コメントアウト[#restrictdefault nomodify notrap nopeer noquery]

●行を追加します[restrict10.1.1.5 nomodify notrap nopeer noquery]

●行を追加します[10.1.1.0マスクを制限255.255.255.0nomodify notrap]

●コメントアウト[サーバー0.centos.pool.ntp.orgiburst]

●コメントアウト[サーバー1.centos.pool.ntp.orgiburst]

●コメントアウト[サーバー2.centos.pool.ntp.orgiburst]

●コメントアウト[サーバー3.centos.pool.ntp.orgiburst]

●行を追加します【サーバー127.127.1.0】

●1行追加【ファッジ127.127.1.0層10】

完全な構成を以下に示します

driftfile /var/lib/ntp/drift
restrict 10.1.1.5 nomodify notrap nopeer noquery
restrict 10.1.1.0 mask 255.255.255.0 nomodify notrap
restrict 127.0.0.1 
restrict ::1
server 127.127.1.0
Fudge 127.127.1.0 stratum 10
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor

注:上記の設定によると、ntpサーバーの時刻がリアルタイムと異なる場合、ntpクライアントは最終的にntpサーバーに従います。

ntpサーバーとインターネット時刻を同期させたい場合は、制限127.0.0.1をコメントアウトし、サーバー127.127.1.0をntp.aliyun.comなどに変更すると思います。

4. ntpdサービスを再起動し、起動後に自動的に開始するように設定します

systemctl restart ntpd
systemctl enable ntpd

5.ntpポートudp123を開きます

●方法1:ファイアウォールをオフにする

systemctl stop firewalld
systemctl disable firewalld

●方法2:ポートudp123を開く

firewall-cmd --permanent --add-port=123/udp
firewall-cmd --reload
firewall-cmd --list-all

6.NTPサーバーが正常にインストールされていることを確認します

[root@ntpserver ~]# netstat -tlunp | grep ntp
udp        0      0 192.168.122.1:123       0.0.0.0:*                           86814/ntpd          
udp        0      0 10.1.1.5:123            0.0.0.0:*                           86814/ntpd          
udp        0      0 127.0.0.1:123           0.0.0.0:*                           86814/ntpd          
udp        0      0 0.0.0.0:123             0.0.0.0:*                           86814/ntpd          
udp6       0      0 fe80::ee7:2e9:62c4::123 :::*                                86814/ntpd          
udp6       0      0 ::1:123                 :::*                                86814/ntpd          
udp6       0      0 :::123                  :::*                                86814/ntpd

4、ntpクライアント設定

1.ntpコンポーネントをインストールします

yum install -y ntp ntpdate -y

2.ntpクライアント構成ファイルを変更します

cp /etc/ntp.conf{,.bak}
vim /etc/ntp.conf

●コメントアウト[#restrictdefault nomodify notrap nopeer noquery]

●行を追加します[restrict10.1.1.5 nomodify notrap nopeer noquery]

●行を追加します[10.1.1.0マスクを制限255.255.255.0nomodify notrap]

●コメントアウト[サーバー0.centos.pool.ntp.orgiburst]

●コメントアウト[サーバー1.centos.pool.ntp.orgiburst]

●コメントアウト[サーバー2.centos.pool.ntp.orgiburst]

●コメントアウト[サーバー3.centos.pool.ntp.orgiburst]

●行を追加する【サーバー10.1.1.5】

●1行追加【ファッジ10.1.1.5層10】

3. ntpdサービスを再起動し、起動後に自動的に開始するように設定します

systemctl restart ntpd
systemctl enable ntpd

5、拡張

1.クライアントの時刻を手動で同期します

ntpdate 10.1.1.5

2.サーバーと上位のクロックサーバー間の通信を表示します

ntpサーバーとクライアントの両方を使用できます

ntpq -p

-------------------終了------------------ 2020年11月5日18:00:00-- ------------------------------

 

おすすめ

転載: blog.csdn.net/xoofly/article/details/109510499