Linux集群部署自定義時間同步服務器(ntpd)


              Linux集群部署自定義時間同步服務器(ntpd)

                                      作者:尹正傑

版權聲明:原創作品,謝絕轉載!否則將追究法律責任。

 

 

  身為一名運維人員,在搭建集群的時候,第一步需要做的就是同步每個機器的時間,尤其是在部署類似VPN這種服務,你不同步時間是會遇到坑的,我之前在部署openVPN是就遇到過類似的問題,我們通常對時間同步的方式:找一個機器(當然這個服務器可以是局域網的也可以是廣域網的喲),作為時間服務器,所有的機器與這台集群時間進行定時的同步,比如,每隔十分鍾,同步一次時間。

 

 

一.安裝ntp軟件

1>.操作平台

[yinzhengjie@node101 ~]$ free -m
              total        used        free      shared  buff/cache   available
Mem:           7808         133        7444           8         230        7465
Swap:          2047           0        2047
[yinzhengjie@node101 ~]$ 
[yinzhengjie@node101 ~]$ uname -r
3.10.0-327.el7.x86_64
[yinzhengjie@node101 ~]$ 
[yinzhengjie@node101 ~]$ uname -m
x86_64
[yinzhengjie@node101 ~]$ 
[yinzhengjie@node101 ~]$ hostname -i
172.30.1.101
[yinzhengjie@node101 ~]$ 
[yinzhengjie@node101 ~]$ cat /etc/hosts | grep yinzhengjie
172.30.1.101 node101.yinzhengjie.org.cn
172.30.1.102 node102.yinzhengjie.org.cn
172.30.1.103 node103.yinzhengjie.org.cn
[yinzhengjie@node101 ~]$ 

2>.檢查ntp軟件是否安裝

[yinzhengjie@s101 ~]$ rpm -qa | grep ntp      #如果沒有內容輸出,則說明沒有按照ntp服務

3>.使用root權限安裝ntp軟件

[yinzhengjie@s101 ~]$ sudo yum -y install ntp
[sudo] password for yinzhengjie: 
Loaded plugins: fastestmirror
base                                                                                                                                                            | 3.6 kB  00:00:00     
extras                                                                                                                                                          | 3.4 kB  00:00:00     
updates                                                                                                                                                         | 3.4 kB  00:00:00     
(1/2): extras/7/x86_64/primary_db                                                                                                                               | 174 kB  00:00:00     
(2/2): updates/7/x86_64/primary_db                                                                                                                              | 5.2 MB  00:00:02     
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: ftp.sjtu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package ntp.x86_64 0:4.2.6p5-28.el7.centos will be installed
--> Processing Dependency: ntpdate = 4.2.6p5-28.el7.centos for package: ntp-4.2.6p5-28.el7.centos.x86_64
--> Processing Dependency: libcrypto.so.10(OPENSSL_1.0.2)(64bit) for package: ntp-4.2.6p5-28.el7.centos.x86_64
--> Processing Dependency: libopts.so.25()(64bit) for package: ntp-4.2.6p5-28.el7.centos.x86_64
--> Running transaction check
---> Package autogen-libopts.x86_64 0:5.18-5.el7 will be installed
---> Package ntpdate.x86_64 0:4.2.6p5-28.el7.centos will be installed
---> Package openssl-libs.x86_64 1:1.0.1e-42.el7.9 will be updated
--> Processing Dependency: openssl-libs(x86-64) = 1:1.0.1e-42.el7.9 for package: 1:openssl-1.0.1e-42.el7.9.x86_64
---> Package openssl-libs.x86_64 1:1.0.2k-12.el7 will be an update
--> Running transaction check
---> Package openssl.x86_64 1:1.0.1e-42.el7.9 will be updated
---> Package openssl.x86_64 1:1.0.2k-12.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================================
 Package                                        Arch                                  Version                                                Repository                           Size
=======================================================================================================================================================================================
Installing:
 ntp                                            x86_64                                4.2.6p5-28.el7.centos                                  base                                549 k
Installing for dependencies:
 autogen-libopts                                x86_64                                5.18-5.el7                                             base                                 66 k
 ntpdate                                        x86_64                                4.2.6p5-28.el7.centos                                  base                                 86 k
Updating for dependencies:
 openssl                                        x86_64                                1:1.0.2k-12.el7                                        base                                492 k
 openssl-libs                                   x86_64                                1:1.0.2k-12.el7                                        base                                1.2 M

Transaction Summary
=======================================================================================================================================================================================
Install  1 Package  (+2 Dependent packages)
Upgrade             ( 2 Dependent packages)

Total download size: 2.4 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/5): ntpdate-4.2.6p5-28.el7.centos.x86_64.rpm                                                                                                                 |  86 kB  00:00:00     
(2/5): autogen-libopts-5.18-5.el7.x86_64.rpm                                                                                                                    |  66 kB  00:00:00     
(3/5): openssl-1.0.2k-12.el7.x86_64.rpm                                                                                                                         | 492 kB  00:00:00     
(4/5): ntp-4.2.6p5-28.el7.centos.x86_64.rpm                                                                                                                     | 549 kB  00:00:00     
(5/5): openssl-libs-1.0.2k-12.el7.x86_64.rpm                                                                                                                    | 1.2 MB  00:00:01     
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                  1.6 MB/s | 2.4 MB  00:00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : 1:openssl-libs-1.0.2k-12.el7.x86_64                                                                                                                                 1/7 
  Installing : ntpdate-4.2.6p5-28.el7.centos.x86_64                                                                                                                                2/7 
  Installing : autogen-libopts-5.18-5.el7.x86_64                                                                                                                                   3/7 
  Installing : ntp-4.2.6p5-28.el7.centos.x86_64                                                                                                                                    4/7 
  Updating   : 1:openssl-1.0.2k-12.el7.x86_64                                                                                                                                      5/7 
  Cleanup    : 1:openssl-1.0.1e-42.el7.9.x86_64                                                                                                                                    6/7 
  Cleanup    : 1:openssl-libs-1.0.1e-42.el7.9.x86_64                                                                                                                               7/7 
  Verifying  : ntpdate-4.2.6p5-28.el7.centos.x86_64                                                                                                                                1/7 
  Verifying  : ntp-4.2.6p5-28.el7.centos.x86_64                                                                                                                                    2/7 
  Verifying  : autogen-libopts-5.18-5.el7.x86_64                                                                                                                                   3/7 
  Verifying  : 1:openssl-1.0.2k-12.el7.x86_64                                                                                                                                      4/7 
  Verifying  : 1:openssl-libs-1.0.2k-12.el7.x86_64                                                                                                                                 5/7 
  Verifying  : 1:openssl-libs-1.0.1e-42.el7.9.x86_64                                                                                                                               6/7 
  Verifying  : 1:openssl-1.0.1e-42.el7.9.x86_64                                                                                                                                    7/7 

Installed:
  ntp.x86_64 0:4.2.6p5-28.el7.centos                                                                                                                                                   

Dependency Installed:
  autogen-libopts.x86_64 0:5.18-5.el7                                                      ntpdate.x86_64 0:4.2.6p5-28.el7.centos                                                     

Dependency Updated:
  openssl.x86_64 1:1.0.2k-12.el7                                                          openssl-libs.x86_64 1:1.0.2k-12.el7                                                         

Complete!
[yinzhengjie@s101 ~]$ 
[yinzhengjie@s101 ~]$ sudo yum -y install ntp

4>.檢查是否安裝成功 

[yinzhengjie@s101 ~]$ rpm -qa | grep ntp      #有內容輸出,則說明安裝成功,安裝完畢會有以下出輸出內容
ntpdate-4.2.6p5-28.el7.centos.x86_64
ntp-4.2.6p5-28.el7.centos.x86_64
[yinzhengjie@s101 ~]$ 
[yinzhengjie@s101 ~]$ rpm -qa | grep ntp      #有內容輸出,則說明安裝成功,安裝完畢會有以下出輸出內容

  

二.集群中時間服務器配置(需要root權限)

1>.設置本地網絡上的主機不受限制

[yinzhengjie@node101 ~]$ grep \#restrict  /etc/ntp.conf                             #查看修改前的內容
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
[yinzhengjie@node101 ~]$
[yinzhengjie@node101 ~]$ sudo sed -i 's@\#restrict@restrict@' /etc/ntp.conf                 #編輯配置文件,將注釋去掉,表示啟用授權功能
[sudo] password for yinzhengjie: 
[yinzhengjie@node101 ~]$ 
[yinzhengjie@node101 ~]$ grep 192.168.1.0 /etc/ntp.conf                             #查看修改后的內容
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
[yinzhengjie@node101 ~]$ 
[yinzhengjie@node101 ~]$ su root
Password: 
[root@node101 yinzhengjie]# 
[root@node101 yinzhengjie]# sed -i 's#192.168.1.0#172.30.1.0#' /etc/ntp.conf                #授權只有172.30.1.0網段的服務器可以來同步時間,其實我發現不修改咱能也能通過ntpdate來進行時間同步.
[root@node101 yinzhengjie]#

2>.注釋默認的時間服務器(設置為不采用公共的服務器

[yinzhengjie@s101 ~]$ grep ^server  /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
[yinzhengjie@s101 ~]$ 
[yinzhengjie@s101 ~]$ sudo sed -i 's@^server@#server@' /etc/ntp.conf       #編輯配置文件,將官方的配置注釋掉
[sudo] password for yinzhengjie: 
[yinzhengjie@s101 ~]$ 
[yinzhengjie@s101 ~]$ grep ^#server  /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
[yinzhengjie@s101 ~]$ 

3>.設置自定義時間服務器(添加默認的一個內部時鍾數據,使用它為局域網用戶提供服務

[yinzhengjie@s101 ~]$ su root
Password: 
[root@s101 yinzhengjie]# echo "#Add by yinzhengjie" >> /etc/ntp.conf 
[root@s101 yinzhengjie]# echo "server 127.127.1.0" >> /etc/ntp.conf                 #將本地時間作為時間同步源
[root@s101 yinzhengjie]# echo "fudge 127.127.1.0 stratum 10" >> /etc/ntp.conf           #指定間隔更新時間,我這里指定的是10分鍾。stratum(層級)的值不能太大,如果要向上級NTP更新可以設成2.
[root@s101 yinzhengjie]# 
[root@s101 yinzhengjie]# tail -3  /etc/ntp.conf 
#Add by yinzhengjie
server 127.127.1.0
fudge 127.127.1.0 stratum 10
[root@s101 yinzhengjie]# 
[root@s101 yinzhengjie]# exit 
exit
[yinzhengjie@s101 ~]$ 

4>.修改/etc/sysconfig/ntpd 文件

[yinzhengjie@s101 ~]$ su root
Password: 
[root@s101 yinzhengjie]# cat /etc/sysconfig/ntpd
# Command line options for ntpd
OPTIONS="-g"
[root@s101 yinzhengjie]# echo SYNC_HWCLOCK=yes >> /etc/sysconfig/ntpd    #讓硬件時間和系統時間一起同步
[root@s101 yinzhengjie]# 
[root@s101 yinzhengjie]# cat /etc/sysconfig/ntpd
# Command line options for ntpd
OPTIONS="-g"
SYNC_HWCLOCK=yes
[root@s101 yinzhengjie]# exit 
exit
[yinzhengjie@s101 ~]$ 

5>.啟動ntpd 

[root@node101 yinzhengjie]# systemctl start ntpd                        #啟動ntp服務
[root@node101 yinzhengjie]# 
[root@node101 yinzhengjie]# systemctl enable ntpd                    #設置開機自啟
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@node101 yinzhengjie]# 
[root@node101 yinzhengjie]# systemctl status ntpd
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2018-10-01 13:00:24 CST; 9min ago
 Main PID: 2760 (ntpd)
   CGroup: /system.slice/ntpd.service
           └─2760 /usr/sbin/ntpd -u ntp:ntp -g

Oct 01 13:00:24 node101.yinzhengjie.org.cn ntpd[2760]: ntp_io: estimated max descriptors: 1024, initial socket boundary: 16
Oct 01 13:00:24 node101.yinzhengjie.org.cn ntpd[2760]: Listen and drop on 0 v4wildcard 0.0.0.0 UDP 123
Oct 01 13:00:24 node101.yinzhengjie.org.cn ntpd[2760]: Listen and drop on 1 v6wildcard :: UDP 123
Oct 01 13:00:24 node101.yinzhengjie.org.cn ntpd[2760]: Listen normally on 2 lo 127.0.0.1 UDP 123
Oct 01 13:00:24 node101.yinzhengjie.org.cn ntpd[2760]: Listen normally on 3 ens33 172.30.1.101 UDP 123
Oct 01 13:00:24 node101.yinzhengjie.org.cn ntpd[2760]: Listening on routing socket on fd #20 for interface updates
Oct 01 13:00:24 node101.yinzhengjie.org.cn ntpd[2760]: 0.0.0.0 c016 06 restart
Oct 01 13:00:24 node101.yinzhengjie.org.cn ntpd[2760]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
Oct 01 13:00:24 node101.yinzhengjie.org.cn ntpd[2760]: 0.0.0.0 c011 01 freq_not_set
Oct 01 13:00:31 node101.yinzhengjie.org.cn ntpd[2760]: 0.0.0.0 c614 04 freq_mode
[root@node101 yinzhengjie]# 
[root@node101 yinzhengjie]# systemctl start ntpd #啟動ntp服務 

 

三.集群中其它節點(ntpd客戶端)配置(安裝后需要啟動ntpd)

1>.安裝ntp服務 

[yinzhengjie@s102 ~]$ sudo yum -y install ntp

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for yinzhengjie: 
Loaded plugins: fastestmirror
base                                                                                                                                                            | 3.6 kB  00:00:00     
extras                                                                                                                                                          | 3.4 kB  00:00:00     
updates                                                                                                                                                         | 3.4 kB  00:00:00     
(1/2): extras/7/x86_64/primary_db                                                                                                                               | 174 kB  00:00:00     
(2/2): updates/7/x86_64/primary_db                                                                                                                              | 5.2 MB  00:00:02     
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: ftp.sjtu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package ntp.x86_64 0:4.2.6p5-28.el7.centos will be installed
--> Processing Dependency: ntpdate = 4.2.6p5-28.el7.centos for package: ntp-4.2.6p5-28.el7.centos.x86_64
--> Processing Dependency: libcrypto.so.10(OPENSSL_1.0.2)(64bit) for package: ntp-4.2.6p5-28.el7.centos.x86_64
--> Processing Dependency: libopts.so.25()(64bit) for package: ntp-4.2.6p5-28.el7.centos.x86_64
--> Running transaction check
---> Package autogen-libopts.x86_64 0:5.18-5.el7 will be installed
---> Package ntpdate.x86_64 0:4.2.6p5-28.el7.centos will be installed
---> Package openssl-libs.x86_64 1:1.0.1e-42.el7.9 will be updated
--> Processing Dependency: openssl-libs(x86-64) = 1:1.0.1e-42.el7.9 for package: 1:openssl-1.0.1e-42.el7.9.x86_64
---> Package openssl-libs.x86_64 1:1.0.2k-12.el7 will be an update
--> Running transaction check
---> Package openssl.x86_64 1:1.0.1e-42.el7.9 will be updated
---> Package openssl.x86_64 1:1.0.2k-12.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================================
 Package                                        Arch                                  Version                                                Repository                           Size
=======================================================================================================================================================================================
Installing:
 ntp                                            x86_64                                4.2.6p5-28.el7.centos                                  base                                549 k
Installing for dependencies:
 autogen-libopts                                x86_64                                5.18-5.el7                                             base                                 66 k
 ntpdate                                        x86_64                                4.2.6p5-28.el7.centos                                  base                                 86 k
Updating for dependencies:
 openssl                                        x86_64                                1:1.0.2k-12.el7                                        base                                492 k
 openssl-libs                                   x86_64                                1:1.0.2k-12.el7                                        base                                1.2 M

Transaction Summary
=======================================================================================================================================================================================
Install  1 Package  (+2 Dependent packages)
Upgrade             ( 2 Dependent packages)

Total download size: 2.4 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/5): autogen-libopts-5.18-5.el7.x86_64.rpm                                                                                                                    |  66 kB  00:00:00     
(2/5): ntpdate-4.2.6p5-28.el7.centos.x86_64.rpm                                                                                                                 |  86 kB  00:00:00     
(3/5): openssl-1.0.2k-12.el7.x86_64.rpm                                                                                                                         | 492 kB  00:00:00     
(4/5): ntp-4.2.6p5-28.el7.centos.x86_64.rpm                                                                                                                     | 549 kB  00:00:00     
(5/5): openssl-libs-1.0.2k-12.el7.x86_64.rpm                                                                                                                    | 1.2 MB  00:00:02     
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                  1.0 MB/s | 2.4 MB  00:00:02     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : 1:openssl-libs-1.0.2k-12.el7.x86_64                                                                                                                                 1/7 
  Installing : ntpdate-4.2.6p5-28.el7.centos.x86_64                                                                                                                                2/7 
  Installing : autogen-libopts-5.18-5.el7.x86_64                                                                                                                                   3/7 
  Installing : ntp-4.2.6p5-28.el7.centos.x86_64                                                                                                                                    4/7 
  Updating   : 1:openssl-1.0.2k-12.el7.x86_64                                                                                                                                      5/7 
  Cleanup    : 1:openssl-1.0.1e-42.el7.9.x86_64                                                                                                                                    6/7 
  Cleanup    : 1:openssl-libs-1.0.1e-42.el7.9.x86_64                                                                                                                               7/7 
  Verifying  : ntpdate-4.2.6p5-28.el7.centos.x86_64                                                                                                                                1/7 
  Verifying  : ntp-4.2.6p5-28.el7.centos.x86_64                                                                                                                                    2/7 
  Verifying  : autogen-libopts-5.18-5.el7.x86_64                                                                                                                                   3/7 
  Verifying  : 1:openssl-1.0.2k-12.el7.x86_64                                                                                                                                      4/7 
  Verifying  : 1:openssl-libs-1.0.2k-12.el7.x86_64                                                                                                                                 5/7 
  Verifying  : 1:openssl-libs-1.0.1e-42.el7.9.x86_64                                                                                                                               6/7 
  Verifying  : 1:openssl-1.0.1e-42.el7.9.x86_64                                                                                                                                    7/7 

Installed:
  ntp.x86_64 0:4.2.6p5-28.el7.centos                                                                                                                                                   

Dependency Installed:
  autogen-libopts.x86_64 0:5.18-5.el7                                                      ntpdate.x86_64 0:4.2.6p5-28.el7.centos                                                     

Dependency Updated:
  openssl.x86_64 1:1.0.2k-12.el7                                                          openssl-libs.x86_64 1:1.0.2k-12.el7                                                         

Complete!
[yinzhengjie@s102 ~]$ 
[yinzhengjie@s102 ~]$ sudo yum -y install ntp 

2>.編寫時間同步腳本(在其他機器配置1分鍾與時間服務器同步一次)

[yinzhengjie@s102 ~]$ sudo crontab -e            #編輯同步腳本

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for yinzhengjie: 
no crontab for root - using an empty one
crontab: installing new crontab
[yinzhengjie@s102 ~]$ sudo crontab -l            #查看已經編輯的周期執行任務
*/1 * * * * /usr/sbin/ntpdate s101                #注意,在crontab中的命令必須得寫絕對路徑,否則會拋異常說命令找不到喲!
[yinzhengjie@s102 ~]$ 

3>.其它節點配置重復以上操作

  注意需要使用root 權限,如果你沒有root權限,如果你在公司沒有root權限的話,可以請求運維幫你提供相關命令的sudo權限喲,其它機器的配置只需要安裝ntp服務和編寫周期性任務腳本即可。我上面就配置了一個節點,其它節點我也做了類似的調整。

 

四.驗證各節點是否與時間服務器同步

1>.編寫管理集群的"xcall.sh"腳本

  以下腳本的執行需要配置無秘鑰登錄,關於如何配置無秘鑰登錄可以參考我之前的筆記:https://www.cnblogs.com/yinzhengjie/p/9065191.html。

[yinzhengjie@s101 ~]$ more `which xcall.sh`
#!/bin/bash
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie
#EMAIL:y1053419035@qq.com


#判斷用戶是否傳參
if [ $# -lt 1 ];then
        echo "請輸入參數"
        exit
fi

#獲取用戶輸入的命令
cmd=$@

for (( i=101;i<=105;i++ ))
do
        #使終端變綠色 
        tput setaf 2
        echo ============= s$i $cmd ============
        #使終端變回原來的顏色,即白灰色
        tput setaf 7
        #遠程執行命令
        ssh s$i $cmd
        #判斷命令是否執行成功
        if [ $? == 0 ];then
                echo "命令執行成功"
        fi
done
[yinzhengjie@s101 ~]$
[yinzhengjie@s101 ~]$ more `which xcall.sh`

2>.檢查各個節點配置 

[yinzhengjie@s101 ~]$ sudo xcall.sh crontab -l
sudo: timestamp too far in the future: Aug 21 10:54:52 2018

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for yinzhengjie: 
[root@s101 yinzhengjie]# xcall.sh crontab -l
============= s101 crontab -l ============
no crontab for root
============= s102 crontab -l ============
*/1 * * * * /usr/sbin/ntpdate s101
命令執行成功
============= s103 crontab -l ============
*/1 * * * * /usr/sbin/ntpdate s101
命令執行成功
============= s104 crontab -l ============
*/1 * * * * /usr/sbin/ntpdate s101
命令執行成功
============= s105 crontab -l ============
*/1 * * * * /usr/sbin/ntpdate s101
命令執行成功
[root@s101 yinzhengjie]# 
[root@s101 yinzhengjie]# exit 
exit
[yinzhengjie@s101 ~]$ 
[yinzhengjie@s101 ~]$ 
[yinzhengjie@s101 ~]$ sudo xcall.sh crontab -l

3>.檢查集群當前服務器時間

[yinzhengjie@s101 ~]$ xcall.sh date
============= s101 date ============
Sun Oct  1 11:29:26 EDT 2017
命令執行成功
============= s102 date ============
Sun Oct  1 11:29:26 EDT 2017
命令執行成功
============= s103 date ============
Sun Oct  1 11:29:26 EDT 2017
命令執行成功
============= s104 date ============
Sun Oct  1 11:29:26 EDT 2017
命令執行成功
============= s105 date ============
Sun Oct  1 11:29:26 EDT 2017
命令執行成功
[yinzhengjie@s101 ~]$ 
[yinzhengjie@s101 ~]$ xcall.sh date 

4>.修改服務器時間,並查看其它節點是否跟隨時間服務器的修改而修改

[yinzhengjie@s101 ~]$ sudo date -s "2018-8-21 14:14:11"
[sudo] password for yinzhengjie: 
Tue Aug 21 14:14:11 EDT 2018
[yinzhengjie@s101 ~]$ 
[yinzhengjie@s101 ~]$ 
[yinzhengjie@s101 ~]$ xcall.sh date
============= s101 date ============
Tue Aug 21 14:16:51 EDT 2018
命令執行成功
============= s102 date ============
Tue Aug 21 14:16:51 EDT 2018
命令執行成功
============= s103 date ============
Tue Aug 21 14:16:52 EDT 2018
命令執行成功
============= s104 date ============
Tue Aug 21 14:16:52 EDT 2018
命令執行成功
============= s105 date ============
Tue Aug 21 14:16:52 EDT 2018
命令執行成功
[yinzhengjie@s101 ~]$ 
[yinzhengjie@s101 ~]$ sudo date -s "2018-8-21 14:14:11" 

 

 

五.將系統時間和服務器硬件時間同步

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hwclock                             #注意,這是查看硬件時間
Mon 10 Jun 2019 09:29:11 PM CST  -0.694751 seconds
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# date                               #查看系統時間       
Mon Jun 10 21:29:15 CST 2019
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# date -s "2019-06-10 14:44:00"               #我們修改了系統時間
Mon Jun 10 14:44:00 CST 2019
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# date                             #系統時間的確是發生了修改
Mon Jun 10 14:44:02 CST 2019
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hwclock                            #硬件時間卻沒有跟着變化
Mon 10 Jun 2019 09:29:47 PM CST  -0.803342 seconds
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# date 
Mon Jun 10 14:44:09 CST 2019
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hwclock -w                        #於是我們把系統時間和硬件時間進行同步
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hwclock                           #再次查看硬件時間
Mon 10 Jun 2019 02:44:21 PM CST  -0.600744 seconds
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# date 
Mon Jun 10 14:44:25 CST 2019
[root@node101.yinzhengjie.org.cn ~]# 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM