Linux设置系统时区以及同步系统时间
一、tzselect设置时区
date -R #查看当期时区
tzselect #设置时区
设置后会提示永久生效的提示,提示信息如下:
You can make this change permanent for yourself by appending the line
TZ='Asia/Shanghai'; export TZ
to the file '.profile' in your home directory; then log out and log in again.
Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Shanghai
按提示执行命令:
TZ='Asia/Shanghai'; export TZ
#配置用户目录下文件,追加内容TZ='Asia/Shanghai'; export TZ
vim /root/.bash_profile >> TZ='Asia/Shanghai'; export TZ
另设置时区永久生效方式
ll /etc/ |grep localtime #查看当前localtime被软连接地址
ll /usr/share/zoneinfo #查看目录种的时区
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
二 、ntpdate同步时间
# 安装ntp服务器
yum -y install ntp ntpdate
# 开启服务
service ntpd start
# 同步时间
ntpdate 192.168.125.133(红色部分改为自己的IP地址)
2.1、定时同步时间
# 命令,进入一个VI的编辑界面,添加如下任务
crontab -e
# 一分钟同步一次
*/1 * * * * /usr/sbin/ntpdate time-a.nist.gov s2m.time.edu.cn ntp.sjtu.edu.cn > /dev/null 2 >&1
# 查看是否已经成功添加
Crontab –l
2.2、ntp常用服务器
国内
cn.pool.ntp.org 中国开源免费NTP服务器
ntp1.aliyun.com 阿里云NTP服务器
ntp2.aliyun.com 阿里云NTP服务器
time1.aliyun.com 阿里云NTP服务器
time2.aliyun.com 阿里云NTP服务器国外
time1.apple.com 苹果NTP服务器
time2.apple.com 苹果NTP服务器
time3.apple.com 苹果NTP服务器
time4.apple.com 苹果NTP服务器
time5.apple.com 苹果NTP服务器
time1.google.com 谷歌NTP服务器
time2.google.com 谷歌NTP服务器
time3.google.com 谷歌NTP服务器
time4.google.com 谷歌NTP服务器
pool.ntp.org 开源免费NTP服务器
还没有评论,来说两句吧...