centos7设置时区,时间+时间同步的三种方式

这篇具有很好参考价值的文章主要介绍了centos7设置时区,时间+时间同步的三种方式。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

centos7设置时区,时间+时间同步的三种方式

1.centos7设置时区

1.1查看当前时区:

timedatectl 

centos7设置时区,时间+时间同步的三种方式

1.2查看时间命令:

date

centos7设置时区,时间+时间同步的三种方式

1.3选择时区命令

[root@localhost test]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
 1) Africa
 2) Americas
 3) Antarctica
 4) Arctic Ocean
 5) Asia
 6) Atlantic Ocean
 7) Australia
 8) Europe
 9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#? 5     
Please select a country.
 1) Afghanistan		  18) Israel		    35) Palestine
 2) Armenia		  19) Japan		    36) Philippines
 3) Azerbaijan		  20) Jordan		    37) Qatar
 4) Bahrain		  21) Kazakhstan	    38) Russia
 5) Bangladesh		  22) Korea (North)	    39) Saudi Arabia
 6) Bhutan		  23) Korea (South)	    40) Singapore
 7) Brunei		  24) Kuwait		    41) Sri Lanka
 8) Cambodia		  25) Kyrgyzstan	    42) Syria
 9) China		  26) Laos		    43) Taiwan
10) Cyprus		  27) Lebanon		    44) Tajikistan
11) East Timor		  28) Macau		    45) Thailand
12) Georgia		  29) Malaysia		    46) Turkmenistan
13) Hong Kong		  30) Mongolia		    47) United Arab Emirates
14) India		  31) Myanmar (Burma)	    48) Uzbekistan
15) Indonesia		  32) Nepal		    49) Vietnam
16) Iran		  33) Oman		    50) Yemen
17) Iraq		  34) Pakistan
#? 9
Please select one of the following time zone regions.
1) Beijing Time
2) Xinjiang Time
#? 1

The following information has been given:

	China
	Beijing Time

Therefore TZ='Asia/Shanghai' will be used.
Local time is now:	Thu May 11 17:50:40 CST 2023.
Universal Time is now:	Thu May 11 09:50:40 UTC 2023.
Is the above information OK?
1) Yes
2) No
#? 1

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

设置timezone的时区

sudo timedatectl set-timezone 'Asia/Shanghai'
或者
echo "Asia/Shanghai" > /etc/timezone

2.设置时间

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

3.使用NTP服务时间同步

3.1安装ntp

yum -y install ntp

3.2启动ntp服务

 systemctl start  ntpd
 systemctl enable  ntpd

3.3查看ntp服务

systemctl status ntpd

centos7设置时区,时间+时间同步的三种方式

3.4修改ntp.conf文件

vim /etc/ntp.conf

centos7设置时区,时间+时间同步的三种方式

3.5重启服务

systemctl restart ntpd

3.6检查同步状态

centos7设置时区,时间+时间同步的三种方式

3.7执行硬件时间向软件时间同步

 hwclock -w

3.8查看当前时间

date

4.使用ntpdate同步

4.1最简单的方法,让所有集群中的主机跟某个时间服务器的 时间同步,执行 ntpdate 时间服务器。

ntpdate ntp1.aliyun.com

centos7设置时区,时间+时间同步的三种方式
不过,这种方法不好.ntpdate同步时间是跳跃的,这将导致文件时间标记,监控数据的紊乱. 而且ntpdate只运行一次就结束,即只同步一次.所以即使我们要写这样写 vi /etc/crontab

* * * * root /usr/sbin/ntpdate ntp1.aliyun.com && /sbin/hwclock -w

4.2执行硬件时间向软件时间同步

 hwclock -w

4.3查看时间是否正确

date

5.使用chrony服务时间同步

5.1安装chrony

yum -y install chrony

5.2启动chrony服务

systemctl enable --now chronyd

5.3查看chrony状态

systemctl status chronyd

5.4修改配置文件

grep server /etc/chrony.conf 

centos7设置时区,时间+时间同步的三种方式文章来源地址https://www.toymoban.com/news/detail-445254.html

5.5重启服务

systemctl restart chronyd

5.6检查时间同步状态

chronyc sources

5.7硬件时间向系统时间同步

hwclock -w

5.8查看时间是否正确

date

6.手动修改时间

6.1修改时间方法

date -s "你想设置的时间"

6.2按格式输出时间

date "+%Y-%m-%d %H:%M:%S"

6.3设置时区

timedatectl set-timezone Asia/Shanghai

6.4 查看

timedatectl list-timezones |grep Shanghai

到了这里,关于centos7设置时区,时间+时间同步的三种方式的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【已解决】CentOS7等linux系统时区时间不对显示误差8小时

    中国使用的是东八区上海时间,而linux服务器,一般默认是0时区 UTC ,所以需要将时区改为东八区 CST 将时区改为东八区后,显示的实际仍然不对,仍然差8小时或16小时,这说明时间不对 时间修改正确后,服务器重启,时间显示又错误了,因为没改硬件时钟时间 linux系统时间

    2024年02月06日
    浏览(30)
  • CentOS7修改主机名的三种方法

    在CentOS7中,有三种定义的主机名: 静态的(Static hostname) “静态”主机名也称为内核主机名,是系统在启动时从/etc/hostname自动初始化的主机名。 瞬态的(Tansient hostname) “瞬态”主机名是在系统运行时临时分配的主机名,例如,通过DHCP或mDNS服务器分配。 灵活的(Pretty ho

    2024年01月16日
    浏览(31)
  • Ubuntu、CentOS 修改时区、设置24小时时间格式

     修改设置时区  方法一 tzselect 方法二 仅限于RedHat Linux 和 CentOS系统 timeconfig 方法三 适用于Debian dpkg-reconfigure tzdata 方法四 复制相应的时区文件,替换CentOS系统时区文件;或者创建链接文件 cp /usr/share/zoneinfo/EST5EDT /etc/localtime 或者 ln -s /usr/share/zoneinfo/EST5EDT /etc/localtime 时间同步

    2024年02月05日
    浏览(34)
  • centos7配置时间同步网络时间

    centos7配置时间同步网络时间 1、安装 NTP 工具。 2启动 NTP 服务。 3、将 NTP 服务设置为开机自启动。 4、验证

    2024年01月18日
    浏览(31)
  • centos 重启 nginx 的三种方式

    以上内容转载于ChatGPT中文网,动态生成

    2024年02月10日
    浏览(43)
  • FFmpeg 播放器实现音视频同步的三种方式

    我们基于 FFmpeg 利用 OpenGL ES 和 OpenSL ES 分别实现了对解码后视频和音频的渲染,本文将实现播放器的最后一个重要功能:音视频同步。 老人们经常说, 播放器对音频和视频的播放没有绝对的静态的同步,只有相对的动态的同步,实际上音视频同步就是一个“你追我赶”的过

    2024年02月06日
    浏览(48)
  • centos7部署时间同步(ntp)服务器

    这里搭建ntp服务器,服务端和客户端,客户端去拉取服务端的时间,为自己所用。 a.安装ntp b.配置文件 最后加上下面的 c.开启服务 d.确认NTP同步正常 输出是 synchronised to NTP server 那证明已经连上了NTP服务器, 如果输出是 unsynchronised 开头的 那证明还没有连上NTP服务器,过几分钟

    2024年01月19日
    浏览(44)
  • VS2022设置编码方式为utf-8的三种方式

    此方法同样适用Visual Studio的其他版本 在字符串前面使用 u8 ,可保证解析时安装utf-8的方式解析 安装插件:Force UTF-8 更改VS的编码方案 首先需要打开高级保存选项 然后打开 文件 — 高级保存选项 即可进行设置 参考链接: 探究Visual Studio中的乱码问题 - CSDN

    2024年02月11日
    浏览(39)
  • 树莓派设置开机自启动的三种方式

    一. 配置rc.local文件方式 编辑/etc/rc.local文件 在文件中exit 0 之前添加需要执行的命令,文件路径使用绝对路径,如: 注意:如果程序是阻塞的,则必须加上符号,表示在后台运行,否则系统无法启动 重启系统,就可以生效了 二. 新建desktop文件设置树莓派开机启动项 这种方式

    2024年02月17日
    浏览(37)
  • SpringSecurity设置登录账号密码的三种方式

    一、SpringBoot整合SpringSecurity: 1.新建SpringBoot工程,引入SpringSecurity依赖 2.编写一个测试Controller  3.修改访问端口(默认8080) 4.启动SpringBoot工程,访问http://localhost:8001/test/hello  如上自动跳转到登录页面,输入账号user,密码在控制台输出,如下所示  5.查看是否登录成功(如下

    2024年02月01日
    浏览(33)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包