linux 同步北京时间
时间: 2024-09-12 12:06:44 浏览: 94
在Linux系统中同步本地时间到北京时间,通常可以使用`ntpdate`命令或者设置cron定时任务来定期更新。以下是两个常用的方法:
1. **使用ntpd服务**:
- 首先安装ntpd服务,通过运行`sudo apt-get install ntp` 或者 `sudo yum install ntp` (取决于你的发行版)。
- 安装完成后,配置ntp.conf文件(一般位于/etc/ntp.conf),添加中国的公共服务器地址,例如:
```
server pool.ntp.org iburst
server time.nist.gov iburst
server asia.pool.ntp.org iburst
```
- 启动ntpd服务并使其开机自启动:`sudo systemctl start ntpd && sudo systemctl enable ntpd`
- 如果需要手动同步时间,可以在终端输入:`sudo ntpdate pool.ntp.org`
2. **使用ntpdate命令**:
- 直接执行一次同步:`sudo ntpdate ntp servers.example.com`,将`servers.example.com`替换为中国的时间服务器地址。
- 将这个命令加入到crontab中,设置定时执行,比如每天凌晨自动同步:`sudo crontab -e`, 然后添加一行类似:
```
0 0 * * * sudo ntpdate ntp.servers.example.com
```
完成上述步骤后,Linux系统的时钟应该会保持与北京时间同步。
阅读全文
相关推荐


















