centos 时间同步API解决方法

背景:

由于公司的环境比较特殊,服务器都需要使用代理才能上网,而代理只支持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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。