您当前的位置:首页 > 学海无涯 > 其他网站首页其他
Centos修改北京时间
发布时间:2021-01-14作者:♂逸風★淩軒
CentOS7 修改默认时区为 北京时间
首先同步时间
yum install -y ntpdate ntpdate -u ntp1.aliyun.com
然后设置中国时区(北京时间)
timedatectl set-timezone Asia/Shanghai
CentOS8修改默认时区为 北京时间(方法一)
添加源:
rpm -ivh http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm
安装ntp服务
dnf install wntp
时间同步
ntpdate ntp1.aliyun.com
Dockerfile
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
最后设置定时任务
crontab -e
参考配置:
SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | * 1 * * * ntpdate -u ntp1.aliyun.com
CentOS8修改默认时区为 北京时间(方法二)
安装chrony
yum install -y chrony
修改
vim /etc/chrony.conf
注释并添加
#pool 2.centos.pool.ntp.org iburst server ntp.aliyun.com iburst
重新加载配置
systemctl restart chronyd.service
时间同步
chronyc sources -v
关键字词:centos,北京时间
