0
点赞
收藏
分享

微信扫一扫

Linux日期与时间

王远洋 2022-05-03 阅读 89

1.时间命令

(1)查看时区

[root@node01 .ssh]# ll /etc/localtime
lrwxrwxrwx. 1 root root 35 Apr 15 21:28 /etc/localtime -> ../usr/share/zoneinfo/Asia/Shanghai

(2)修改时区

      ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

(3)修改时间

        date -s 12:12:12

        date -s 2022-12-12

        date -s '2022-12-12 12:12:12’

2.本地服务器之间日期同步

实现本地node01、node02、node03三台服务器时间同步,以同步node01主机时间为例

(1) 三台服务器安装时间同步服务

yum instal ntp -y

(2) node01 搭建ntp服务

[root@node01 .ssh]#  vi /etc/ntp.conf
#========权限控制============ 
restrict default kod nomodify notrap nopeer noquery 拒绝IPV4用户 
restrict -6 default kod nomodify notrap nopeer noquery 拒绝IPV6用户 
restrict 210.72.145.44 授权国家授时中心服务器访问本地NTP 
restrict 133.100.11.8 授权133.100.11.8访问本地NTP 
restrict 127.0.0.1 
restrict -6 ::1 
restrict 192.168.188.2 mask 255.255.255.0 nomodify 本地网段授权访问 
#=========源服务器=========== 
server cn.ntp.org.cn prefer 指定上级更新时间服务器,优先使用这个地址 
#=========差异分析=========== 
driftfile /var/lib/ntp/drift 
keys /etc/ntp/keys

(3)开启本地NTP服务器

    [root@node01 .ssh]# systemctl restart ntpd.service

    --关闭ntp命令systemctl stop ntpd.service

(4) node02、node03同步时间

    [root@node02 ~]# ntpdate node01

    [root@node03 ~]# ntpdate node01

3.本地服务器自动同步网络时间

(1) 三台服务器安装时间同步服务

      yum instal ntp -y

(2)三台服务器与其他服务器做时间同步

    [root@node01 .ssh]# ntpdate cn.ntp.org.cn

    [root@node02 .ssh]# ntpdate cn.ntp.org.cn

    [root@node03 .ssh]# ntpdate cn.ntp.org.cn

举报

相关推荐

0 条评论