Centos7.9同步外网yum源至内网

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache
yum repolist

安装软件

yum install -y yum-utils createrepo		# yum-utils包含reposync同步工具,createrepo用于对rpm文件进行索引建立
reposync -n --repoid=extras --repoid=updates --repoid=base --repoid=epel -p /library/Centos7.9/		# -n 指下载最新软件包,-p 指定目录,--repoid 指定本地的源,如果不指定就同步所有源

# 创建源索引
createrepo -po /library/Centos7.9/base/ /library/Centos7.9/base/
createrepo -po /library/Centos7.9/extras/ /library/Centos7.9/extras/
createrepo -po /library/Centos7.9/updates/ /library/Centos7.9/updates/
createrepo -po /library/Centos7.9/epel/ /library/Centos7.9/epel/
# 更新源索引
createrepo --update /library/Centos7.9/base/
createrepo --update /library/Centos7.9/extras/
createrepo --update /library/Centos7.9/updates/
createrepo --update /library/Centos7.9/epel/

创建yum源客repo配置文件

cat << EOF > /mirror/repo/CentOS-Base.repo

[base]
name=CentOS- Base
baseurl=file:///library/Centos7.9/base/
enable=1
gpgcheck=0
 
[updates]
name=CentOS- Updates
baseurl=file:///library/Centos7.9/updates/
enable=1
gpgcheck=0

[extras]
name=CentOS- Extras
baseurl=file:///library/Centos7.9/extras/
enable=1
gpgcheck=0

[epel]
name=CentOS- Epel
baseurl=file:///library/Centos7.9/epel/
enable=1
gpgcheck=0
EOF
<think>好的,我需要帮助用户在CentOS 7.9上配置时间同步,用户提到了ntpdate和chrony,可能对这两种方法感兴趣。首先,我要确认CentOS 7.9默认的时间服务是什么。记得CentOS 7以后可能转向了chrony,但ntpdate仍然可用。不过需要注意,有些资料提到ntpdate可能被弃用,推荐使用chrony的chronyc命令。 接下来,我需要分步骤说明两种方法的配置过程。对于chrony,应该包括安装、配置文件的修改、启动服务并设置开机自启,以及验证步骤。而ntpdate可能需要手动执行或者创建定时任务,比如cron job。同时,要提醒用户ntpdate可能不适合长期同步,更适合临时调整。 还要注意引用用户提供的参考资料,引用[1]提到使用NTP服务,而引用[2]则提到ntpdate的使用。需要正确关联这些引用,比如在安装ntp或chrony时引用[1],在讨论ntpdate时引用[2]。 另外,需要检查是否有可能的冲突,比如同时运行chronyd和ntpd服务会导致问题,应该提醒用户只启用其中一个。此外,防火墙和SELinux的设置可能会影响时间同步,是否需要提及呢?用户可能遇到连接不上时间服务器的问题,可以建议检查防火墙设置,开放123/udp端口,但用户的问题主要是配置方法,可能不需要深入,除非用户后续提问。 最后,生成相关问题时要考虑用户可能进一步的问题,比如如何验证同步状态、解决同步失败、或者与其他服务的集成等。需要确保问题覆盖常见的使用场景和故障排除。</think>### CentOS 7.9 时间同步方法(NTPdate 和 Chrony 配置教程) #### 一、使用 Chrony 配置时间同步(推荐) 1. **安装 Chrony 服务** Chrony 是 CentOS 7 默认的时间同步工具,支持更精准的时间调整和网络波动适应[^1]: ```bash sudo yum install chrony ``` 2. **修改配置文件** 编辑 `/etc/chrony.conf`,可替换默认服务器为中国区 NTP (如阿里云): ```bash server ntp.aliyun.com iburst server time1.cloud.tencent.com iburst ``` 3. **启动服务并设置开机自启** ```bash sudo systemctl start chronyd sudo systemctl enable chronyd ``` 4. **验证同步状态** ```bash chronyc tracking # 查看时间同步状态 chronyc sources -v # 检查时间信息 ``` --- #### 二、使用 NTPdate 手动同步时间(临时调整) 1. **安装 NTPdate** ```bash sudo yum install ntpdate ``` 2. **手动执行时间同步** 使用公共 NTP 服务器(如 `ntp.aliyun.com`): ```bash sudo ntpdate ntp.aliyun.com ``` 3. **设置定时任务(可选)** 通过 cron 每天自动同步一次: ```bash echo "0 2 * * * /usr/sbin/ntpdate ntp.aliyun.com" | sudo tee -a /etc/crontab ``` --- #### 三、注意事项 1. **服务冲突** Chrony 和 NTPdate 不建议同时运行。若已安装 `ntpd` 服务,需先停止: ```bash sudo systemctl stop ntpd sudo systemctl disable ntpd ``` 2. **防火墙配置** 若启用防火墙,需开放 UDP 123 端口: ```bash sudo firewall-cmd --add-service=ntp --permanent sudo firewall-cmd --reload ``` --- §§ 1. 如何检查 Chrony 是否成功同步时间? 2. 时间同步失败可能有哪些原因? 3. Chrony 和 NTP 协议有什么区别? 4. 如何为内网服务器搭建本地 NTP 时间? : Chrony 提供更平滑的时间调整,适用于高波动网络环境。 [^2]: NTPdate 适合单次手动同步,但长期建议使用 Chrony 或 NTP 服务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值