美文网首页
centos 时间同步API解决方法

centos 时间同步API解决方法

作者: 一回生 | 来源:发表于2020-08-25 17:44 被阅读0次

    背景:

    由于公司的环境比较特殊,服务器都需要使用代理才能上网,而代理只支持http、socks。 尝试使用redsocks、proxychains代理ntpdate无果的情况下,使用api获取当前时间,进行时间同步

    实现方式

    proxychains方式,报错如下,无法正常代理

    [root@chain16 ~]# proxychains4 ntpdate -u ntp1.aliyun.com
    [proxychains] config file found: /etc/proxychains.conf
    [proxychains] preloading /usr/lib/libproxychains4.so
    [proxychains] DLL init: proxychains-ng 4.1425 Aug 17:22:25
    ntpdate[32353]: no server suitable for synchronization found                    
    

    于是搜索了网上的做法,获取时间并进行设置

    #方法一
    date -s "$(curl -s http://quan.suning.com/getSysTime.do|jq '.sysTime2'|sed 's/\"//g')"
    date -s $(curl -s http://worldtimeapi.org/api/timezone/Asia/Hong_Kong|jq '.datetime'|sed 's/\"//g')
    

    以上方法以内jq json处理

    需要安装

    yum install epel-release
    yum install jq
    

    相关文章

      网友评论

          本文标题:centos 时间同步API解决方法

          本文链接:https://www.haomeiwen.com/subject/kxvzjktx.html