宝塔面板镜像源切换是指将面板安装、更新、插件下载及运行环境安装时默认使用的宝塔官方服务器节点替换为国内镜像节点或其他可用节点,从而解决下载缓慢、连接超时、安装失败等问题。
通过面板界面切换云端请求线路
登录宝塔面板后台。
点击左侧导航中的“面板设置”。
找到“面板云端请求线路”或“面板云端节点”选项。

默认值一般为“自动”或“官方节点”,将其切换为“国内节点”或“备用节点”。
保存设置后刷新面板页面。
若当前面板版本未提供该选项,可升级到最新版本后再操作。
此方法适合大多数普通用户,不需要执行命令行。
通过SSH命令切换面板节点
使用SSH工具连接服务器,执行以下命令进入面板管理菜单:
bt
在菜单中查找“切换面板云端请求线路”对应编号,不同版本编号可能不同,部分版本中该功能编号为
25,请以实际菜单显示为准。输入对应数字,选择“国内线路”或“备份线路”。
等待面板自动重载配置。
若面板命令列表中没有切换节点选项,可先升级面板到最新版本,或使用后续配置文件修改方法。
通过修改配置文件切换节点
进入面板数据目录:
cd/www/server/panel/data
备份当前节点配置文件:
cpnode.jsonnode.json.bak
使用
vi或nano编辑node.json:
vinode.json
找到类似
download、api、update等字段,将域名部分修改为镜像节点域名,示例内容如下:
{
"download":"https://dg2.bt.cn",
"api":"https://api.bt.cn",
"update":"https://download.bt.cn"
}注意:实际字段名称以当前面板版本为准,修改前务必进行备份。
保存退出后重启面板:
bt1
或执行:
/etc/init.d/btrestart
更换宝塔安装脚本下载源
全新安装宝塔面板时,可手动替换安装脚本中的默认下载域名。
默认安装命令:
curl-sSOhttps://download.bt.cn/install/install_panel.sh&&bashinstall_panel.shed8484bec
将 download.bt.cn 替换为国内备用节点,
curl-sSOhttps://dg2.bt.cn/install/install_panel.sh&&bashinstall_panel.shed8484bec
如果服务器无法直接访问上述域名,可先下载脚本,再通过镜像源下载:
wget-Oinstall_panel.shhttps://download.bt.cn/install/install_panel.sh sed-i's#https://download.bt.cn#https://dg2.bt.cn#g'install_panel.sh bashinstall_panel.shed8484bec
此方式适合新装服务器,可明显提高安装包下载速度。
更换系统软件源
宝塔面板安装运行环境时,会调用系统包管理器安装部分依赖,若系统源速度慢,也会影响整体安装效率。
CentOS / RHEL 系列
备份默认源:
mv/etc/yum.repos.d/CentOS-Base.repo/etc/yum.repos.d/CentOS-Base.repo.bak
下载阿里云镜像源,CentOS 7 执行:
curl-o/etc/yum.repos.d/CentOS-Base.repohttps://mirrors.aliyun.com/repo/Centos-7.repo
CentOS 8 或 Stream 需使用对应版本:
curl-o/etc/yum.repos.d/CentOS-Base.repohttps://mirrors.aliyun.com/repo/Centos-8.repo
清理缓存并生成新缓存:
yumcleanall yummakecache
Ubuntu 系列
备份默认源:
cp/etc/apt/sources.list/etc/apt/sources.list.bak
替换为阿里云镜像,以 Ubuntu 20.04 为例:
cat>/etc/apt/sources.list<<'EOF' debhttp://mirrors.aliyun.com/ubuntu/focalmainrestricteduniversemultiverse debhttp://mirrors.aliyun.com/ubuntu/focal-securitymainrestricteduniversemultiverse debhttp://mirrors.aliyun.com/ubuntu/focal-updatesmainrestricteduniversemultiverse debhttp://mirrors.aliyun.com/ubuntu/focal-proposedmainrestricteduniversemultiverse debhttp://mirrors.aliyun.com/ubuntu/focal-backportsmainrestricteduniversemultiverse EOF
更新软件源:
aptupdate
Debian 系列
备份源文件:
cp/etc/apt/sources.list/etc/apt/sources.list.bak
替换为清华镜像,以 Debian 11 为例:
cat>/etc/apt/sources.list<<'EOF' debhttps://mirrors.tuna.tsinghua.edu.cn/debian/bullseyemaincontribnon-free debhttps://mirrors.tuna.tsinghua.edu.cn/debian/bullseye-updatesmaincontribnon-free debhttps://mirrors.tuna.tsinghua.edu.cn/debian/bullseye-backportsmaincontribnon-free debhttps://mirrors.tuna.tsinghua.edu.cn/debian-securitybullseye-securitymaincontribnon-free EOF
更新缓存:
aptupdate
修改 hosts 文件指定节点IP
当域名解析不稳定或DNS被污染时,可通过 hosts 文件将宝塔下载域名指向可用IP。
获取可用节点IP,可使用
ping或dig命令测试:
pingdownload.bt.cn pingdg2.bt.cn
编辑
/etc/hosts:
vi/etc/hosts
添加一行:
129.198.197download.bt.cn
注意:IP需根据实际测试结果填写,不要直接使用示例IP。
保存后刷新DNS缓存:
systemctlrestartsystemd-resolved
或重启网络服务。
此方法可在不修改面板配置的情况下强制指定下载线路,但IP变更后需手动更新。
切换面板插件与运行环境下载源
面板安装 Nginx、MySQL、PHP、phpMyAdmin 等软件时,默认从宝塔节点下载预编译包,如果镜像源切换后仍下载缓慢,可尝试以下操作:
在面板“软件商店”中找到目标软件。
点击“安装”,选择版本时注意观察下载地址提示。
若长时间卡在“下载中”,可取消安装,切换面板节点后重新安装。
部分软件支持自定义下载地址,可在安装弹窗中手动填写镜像地址。
使用宝塔官方提供的备用安装脚本,
bash/www/server/panel/install/nginx.shinstall1.22
脚本内部下载地址可手动编辑替换为镜像节点:
sed-i's#https://download.bt.cn#https://dg2.bt.cn#g'/www/server/panel/install/nginx.sh
此方法适合有一定技术基础的用户,操作前请备份对应脚本。
验证镜像源是否生效
重新登录面板,打开“面板设置”确认节点信息。
查看面板运行日志:
tail-f/www/server/panel/logs/error.log
尝试执行面板修复命令:
bt16
安装一个小型插件或更新面板,观察下载速度。
使用
curl -I命令测试节点连通性:
curl-Ihttps://dg2.bt.cn
返回 200 OK 或 302 表示节点可用。
常见问题与处理
切换节点后面板无法访问:检查配置文件是否格式错误,恢复备份文件后重启面板。
系统源更新报错:确认系统版本与镜像源版本匹配,CentOS 7 不能使用 CentOS 8 源。
下载速度仍然很慢:尝试不同镜像节点,检查服务器带宽和本地网络。
SSL证书错误:可先执行
yum install ca-certificates -y或apt install ca-certificates -y更新证书库。面板升级失败:手动执行
bt 16修复面板,或重新执行官方安装脚本选择覆盖安装。