NTP建 时间服务器


一般操作是直接使用NTP,跟默认的时间服务器同步,但是最好还是让所有节点跟集群中的某台作为时间服务器的节点同步。

步骤:
    选择一台服务器作为时间服务器。
    使用root用户,查看服务器是否安装ntp服务

    rpm -qa|grep ntp

     没有安装的话使用
yum install -y ntpd

      修改文件 /etc/ntp.conf,一共修改三处内容:
      ①将#去掉。并且将网段修改正确。

    restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap

     ②将以下4个server进行#注释掉

    #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

    ③最后添加俩句话:

    server 127.127.1.0 #local clock
    fudge  127.127.1.0 stratum 10

    编辑etc/sysconfig/ntpd文件

    # Drop root to id 'ntp:ntp' by default.
    SYNC_HWCLOCK=yes
    OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"

    启动ntpd服务,并且设置开机启动

    systemctl start ntpd.service
    systemctl enable ntpd.service

     
    每个需要同步的子节点进行确认有没有ntp。如果没有的话就安装下。
    root账户下在每个需要同步的子节点编写crontab任务(crontab -e)。这个任务的意义就是每10分钟和master01同步下服务器时间。

    0-59/10 * * * * /usr/sbin/ntpdate 192.168.xx.xx


将时区设为上海

rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

然后通过定时任务,与阿里云的时间服务器 ntp1.aliyun.com 同步


iptables -I INPUT -p udp --dport 123 -j ACCEPT



其他命令:


1.  安装ntpdate工具
    # yum -y install ntp ntpdate

2.  设置系统时间与网络时间同步
    # /usr/sbin/ntpdate ntp1.aliyun.com

3.  将系统时间写入硬件时间
    # hwclock --systohc

4.强制系统时间写入CMOS中防止重启失效
      hwclock -w  

      clock -w

posted @ 2020-03-23 10:46  walkersss  阅读(261)  评论(0编辑  收藏  举报