在CentOS 7系统上自动同步北京时间,可以按照以下步骤进行操作:

1. 安装NTP: 打开终端并以root身份登录,执行以下命令安装NTP(Network Time Protocol)。

yum install ntp -y

2. 配置NTP服务器: 编辑NTP配置文件。

vi /etc/ntp.conf

找到并注释掉其他服务器,添加如下配置:

server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
server ntp3.aliyun.com iburst
server ntp4.aliyun.com iburst

保存并退出编辑器。

3. 启动NTP服务: 启动NTP服务,并设置开机自启动。

systemctl start ntpd
systemctl enable ntpd

4. 同步时间: 手动同步时间一次。

ntpdate -u ntp1.aliyun.com

验证同步: 查看时间是否同步成功。

date

5. 时区设置(如果需要): 如果需要设置时区为北京时间,可以使用以下命令。

timedatectl set-timezone Asia/Shanghai

通过以上步骤,你的CentOS 7系统会自动同步北京时间,并且设置时区为Asia/Shanghai。这将确保你的系统时间始终与北京时间保持同步。