Debian / Ubuntu 自动检查安装更新

Kevin 教程 2,081 次浏览 43条评论

服务器环境与常用的桌面版系统不同,很多人在部署好服务后就很少登录机器,除非有良好习惯才会经常上去检查更新。要想省心解决这个问题,可以设置系统自动检查安装更新。具体方法步骤如下。

激活自动更新程序

部分系统版本自带有unattended-upgrades软件包。如果没有,手动安装下。

# 检查系统是否已安装(没有安装则无信息返回)
dpkg -l | grep unattended-upgrades
# 从包管理器获取安装
apt-get update && apt-get install unattended-upgrades

安装后运行dpkg-reconfigure -plow unattended-upgrades命令启动服务配置向导。

 ┌────────────┤ Configuring unattended-upgrades ├─────────────┐
 │                                                            │
 │ Applying updates on a frequent basis is an important part  │
 │ of keeping systems secure. By default, updates need to be  │
 │ applied manually using package management tools.           │
 │ Alternatively, you can choose to have this system          │
 │ automatically download and install important updates.      │
 │                                                            │
 │ Automatically download and install stable updates?         │
 │                                                            │
 │               <Yes>               <No>                     │
 │                                                            │
 └────────────────────────────────────────────────────────────┘

选择YES确认开启,如果提示选择更新模式,直接回车使用默认值即可。之后程序会自动生成/etc/apt/apt.conf.d/20auto-upgrades配置文件激活服务。

通过编辑该配置文件,可以按需设置自动更新运行方式,并添加其他操作。下面为示例配置。

// 每天刷新软件包列表
APT::Periodic::Update-Package-Lists "1";
// 每天下载可用更新文件
APT::Periodic::Download-Upgradeable-Packages "1";
// 每7天运行升级软件包
APT::Periodic::Unattended-Upgrade "7";
// 每21天清除包缓存文件
APT::Periodic::AutocleanInterval "21";

更多功能参数请查看/etc/cron.daily/apt文件描述。

配置自动更新选项

如果需要调整更新策略,例如添加或排除软件包更新。在/etc/apt/apt.conf.d/50unattended-upgrades文件内设置,里面有详细配置说明。

Unattended-Upgrade::Origins-Pattern选项控制自动更新软件包类型,默认只升级系统安全类更新,适合大部分情况下使用。

// Debian 默认值
"origin=Debian,codename=${distro_codename},label=Debian-Security";
// Ubuntu 默认值
"origin=Ubuntu,archive=${distro_codename}-security";

为了掌握自动更新情况,可以添加邮箱地址以接收更新报告。别忘了取消注释使其生效。

Unattended-Upgrade::Mail "user@example.com";

安装配置邮件服务

要使上面设置的邮件通知功能生效,需要安装和配置mailx服务,详细流程请参考这篇文章

配置好邮件服务后,使用下面命令测试邮件是否可以正常发送。

echo "This is a test mailing" | mail -s "Test mail" user@example.com

测试自动更新服务

完成上面设置后,运行更新命令测试更新服务是否正常。

unattended-upgrade -v -d

如无意外,更新后会收到详细报告邮件。包括更新了哪些软件包,是否要重启服务器等信息。

更新通知邮件

到处,无人值守自动更新服务就设置完成了,以后不用再惦记检查更新这档事啦。

评论列表

  1. #1

    Hi, very nice website, cheers!
    ——————————————————
    Need cheap and reliable hosting? Our shared plans start at $10 for an year and VPS plans for $6/Mo.
    ——————————————————
    Check here: https://www.reliable-webhosting.com/

  2. #2

    penile injections vs dapoxetine https://salemeds24.wixsite.com/dapoxetine

  3. #3

    generic hydroxychloroquine https://hhydroxychloroquine.com/

  4. #4

    hydroxychloroquine long term https://hydroxychloroquine.webbfenix.com/

  5. #5

    will ivermectin kill corona https://ivermectin.mlsmalta.com/

  6. #6

    priligy uk price https://dapoxetine.confrancisyalgomas.com/

  7. #7

    brand cialis online pharmacy https://wisig.org/

  8. #8

    vidalista warnings https://vidalista40mg.mlsmalta.com/

  9. #9

    albuterol interactions with other drugs https://amstyles.com/

  10. #10

    plaquenil for chronic fatigue syndrome https://hydroxychloroquinee.com/

  11. #11

    women’s cialis testimonials https://tadalafili.com/

  12. #12

    price priligy usa https://ddapoxetine.com/

  13. #13

    buy cialis https://atadalafil.online/

  14. #14

    buy cialis https://tadalafileo.online/

  15. #15

    hydroxychloroquine for covid 19 dosage https://hydroxychloroquine.lm360.us/

  16. #16

    zoloft and tamoxifen interaction https://tamoxifen.mrdgeography.com/

  17. #17

    vidalista 40 mg daily https://vidalista.mlsmalta.com/

  18. #18

    time curve for cefixime effectiveness https://ceefexime.co/

  19. #19

    I am glad that I discovered this website, precisely the right info that I was searching for! https://local-auto-locksmith.co.uk/kia/

  20. #20

    I enjoy you because of all of the effort on this blog. Betty delights in carrying out internet research and it’s easy to see why. A lot of people hear all about the compelling form you convey both interesting and useful guidelines by means of the blog and attract contribution from other individuals about this area of interest and my child has always been becoming educated a great deal. Enjoy the remaining portion of the new year. You’re carrying out a dazzling job. https://lvagroupinc.com/

  21. #21

    I’m just commenting to let you be aware of of the fabulous discovery my cousin’s daughter experienced going through your site. She even learned lots of issues, most notably how it is like to have a very effective giving mindset to have many others just gain knowledge of chosen grueling matters. You really did more than our desires. Many thanks for distributing the important, healthy, educational and as well as easy thoughts on the topic to Gloria. https://luvoxfluvoxamine.com/

  22. #22

    I precisely had to say thanks all over again. I’m not certain the things I could possibly have created in the absence of the actual hints discussed by you concerning such concern. It actually was a real difficult condition for me personally, but discovering a new professional fashion you handled it forced me to cry for delight. I’m grateful for the assistance and as well , have high hopes you comprehend what a powerful job you’re carrying out educating men and women by way of your blog. I am certain you’ve never come across all of us. https://sinequandoxepin.com/#

  23. #23

    100 mg cialis cialis https://tadalafil.cleckleyfloors.com/

  24. #24

    how to get prescriptions without a doctor https://medpills.bee-rich.com/

  25. #25

    how to get prescriptions without a doctor https://buymeds.mlsmalta.com/

  26. #26

    medication without a doctor prescription https://edmeds.buszcentrum.com/

  27. #27

    acticin tablet

  28. #28

    buy cialis black online

  29. #29

    same day loans bad credit

  30. #30

    loan no credit check

  31. #31

    tadalafil prescription cost uk https://cialis.adicbc.com/

  32. #32

    tadalafil prescription cost uk https://cialis.studiowestinc.com/

  33. #33

    ciprofloxacin cost uk

  34. #34

    guaranteed payday loans no teletrack

  35. #35

    cialis website https://cialzi.com/

  36. #36

    does azithromycin have long term side effects http://aziithromycin.com/

  37. #37

    order hydroxychloroquine from india http://hydroxychloroquined.online/

  38. #38

    can tadalafil cause weight gain https://cialis.cleckleyfloors.com/

  39. #39

    can tadalafil cause weight gain https://cialis360.jueriy.com/

  40. #40

    Every weekend i used to visit this website, as i wish for enjoyment, since this this site conations really nice funny stuff too. https://cialis.bee-rich.com/tadalafil

  41. #41

    generic vidalista online canadian pharmacy http://vidallista.com/

  42. #42

    It is the best time to make some plans for the future and
    it’s time to be happy. I’ve learn this post and if I may
    I wish to counsel you few attention-grabbing issues or suggestions.
    Perhaps you could write next articles referring to this article.
    I want to read more issues about it! https://hydroxychloroquineb.bee-rich.com/

  43. #43

    I really like your writing style, good information, thanks for putting up :D. “The superfluous is very necessary.” by Francois Marie Arouet Voltaire.

    http://www.vreyrolinomit.com/

发表评论

电邮地址用于 Gravatar 头像显示,不会被公开可见。