一招解决 ubuntu apt 命令被锁定 | server 运维论坛-大发黄金版app下载
问题背景
玩了个国外老版本服务器,ubuntu20的,结果触发自动更新。 cpu都跑炸了,而且一直100%,主要是不让我安装东西
root@kuibatian:~# sudo apt install screen reading package lists… done building dependency tree
reading state information… done the following packages were automatically installed and are no longer required: libllvm11 linux-headers-5.8.0-43-generic linux-hwe-5.8-headers-5.8.0-43 linux-image-5.8.0-43-generic linux-modules-5.8.0-43-generic linux-modules-extra-5.8.0-43-generic use ‘sudo apt autoremove’ to remove them. the following additional packages will be installed: libutempter0 suggested packages: byobu | screenie | iselect e: could not get lock /var/cache/apt/archives/lock. it is held by process 3625 (unattended-upgr) n: be aware that removing the lock file is not a solution and may break your system. e: unable to lock directory /var/cache/apt/archives/
解决
这个问题是由于系统自动更新进程(unattended-upgrades)正在运行,导致 apt 命令被锁定。以下是大发黄金版app下载的解决方案:
1. 暂时停止自动更新服务
# 停止 unattended-upgrades 服务
sudo systemctl stop unattended-upgrades
# 禁用自动更新
sudo systemctl disable unattended-upgrades
2. 删除锁文件
# 删除 apt 锁文件
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
sudo rm /var/lib/dpkg/lock-frontend
3. 修复 dpkg
# 尝试修复可能的依赖问题
sudo dpkg --configure -a
4. 清理过时的内核和包
# 清理不再需要的包
sudo apt autoremove
# 清理 apt 缓存
sudo apt clean
5. 重新尝试安装 screen
# 更新包列表
sudo apt update
# 安装 screen
sudo apt install screen
6. 长期大发黄金版app下载的解决方案
配置自动更新时间
编辑 /etc/apt/apt.conf.d/20auto-upgrades
:
sudo nano /etc/apt/apt.conf.d/20auto-upgrades
修改为:
apt::periodic::update-package-lists "1";
apt::periodic::download-upgradeable-packages "1";
apt::periodic::autocleaninterval "7";
apt::periodic::unattended-upgrade "1";
设置更新时间
编辑 /etc/apt/apt.conf.d/10periodic
:
sudo nano /etc/apt/apt.conf.d/10periodic
确保配置如下:
apt::periodic::update-package-lists "1";
apt::periodic::download-upgradeable-packages "1";
apt::periodic::autocleaninterval "7";
apt::periodic::unattended-upgrade "1";
7. 验证安装
# 检查 screen 是否成功安装
screen --version
注意事项
- 谨慎删除锁文件
- 建议在系统负载低时进行这些操作
- 如果问题持续存在,可能需要重启系统
额外的诊断命令
# 查看自动更新服务状态
systemctl status unattended-upgrades
# 查看系统日志
journalctl -u unattended-upgrades
这些步骤应该能帮助你解决 apt 被锁定的问题
执行图片
cpu 变小了
避雷帖子
本作品采用《cc 协议》,转载必须注明作者和本文链接
嗨,我是波波。曾经创业,有收获也有损失。我积累了丰富教学与编程经验,期待和你互动和进步!
公众号:上海php自学中心