十年匠心定制 · 商业建站与技术教学双线并行 咨询热线:400-886-1026 service@lmnt.cn
ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

Ubuntu24.04 系统深度实战:虚拟机安装|Netplan 网络|Apt 包管理全解析

Ubuntu24.04 系统深度实战:虚拟机安装|Netplan 网络|Apt 包管理全解析 ubuntu 2404 系统安装创建虚拟机创建过程省略。安装过程提示为了防止连网更新软件包该地方需断开网卡安装系统。系统安装完成后再配置网络。更改地址为 http://mirrors.aliyun.com/ubuntu使用华为的mirror速度更快http://mirrors.huaweicloud.com/ubuntu等待安装完成该过程需要从Internet上下载软件包还可以查看安装日志。安装完成重启系统出现以下提示不用理会直接回车继续重启。[FAIED] Failed unmounting /dev/cdrom安装后配置安装常规软件包vim和命令补全软件包。gggubuntu:~$sudoapt-getinstall-yvimbash-completion配置 IPgggubuntu:~$cd/etc/netplan/ gggubuntu:/etc/netplan$sudomkdirbackup gggubuntu:/etc/netplan$sudomv50-cloud-init.yaml backup gggubuntu:/etc/netplan$sudovim00-installer-config.yaml# This is the network config written by subiquitynetwork: ethernets: ens32: dhcp4: no addresses: -10.1.8.10/24 routes: - to: default via:10.1.8.2 nameservers: addresses: -223.5.5.5 -223.6.6.6 version:2# 应用配置gggubuntu:/etc/netplan$sudochmod60000-installer-config.yaml gggubuntu:/etc/netplan$sudonetplan apply配置 root 密码gggubuntu:~$sudopasswdroot[sudo]passwordforggg:123New password:123Retype new password:123passwd: password updated successfully配置 root 远程登录gggubuntu:~$sudovim/etc/ssh/sshd_config#PermitRootLogin prohibit-passwordPermitRootLoginyes# 重新sshd服务配置gggubuntu:~$sudosystemctl reloadsshgggubuntu:~$sudosystemctlenablesshubuntu 系统网络管理netplan介绍Netplan是Canonical(Ubuntu系统的开发和维护组织)开发的实用程序能在Linux系统上轻松配置网络。要配置网络接口只需创建所需网络接口的YAML描述然后Netplan将为所选的渲染器工具生成所有必需的配置。您可以在/usr/share/doc/netplan/examples中找到Netplan网络配置文件。Netplan当前支持以下后端渲染器例如NetworkManager和Systemd-networkd。netplan只是NetworkManager和Systemd-networkd前端工具。Netplan定义文件位于/etc/netplan目录例如/etc/netplan/00-ens32.yaml。示例示例1定义一个静态配置iprootubuntu:/usr/share/doc/netplan/examples# cat static.yamlnetwork:ethernets:ens33:dhcp4:noaddresses:-10.1.8.88/24routes:-to:defaultvia:10.1.8.2nameservers:addresses:-10.1.8.2-223.5.5.5version:2示例2定义一个动态获取iprootubuntu:/usr/share/doc/netplan/examples# cat dhcp.yamlnetwork:version:2renderer:networkdethernets:enp3s0:dhcp4:true命令应用上面定义的配置文件rootubuntu:~# netplan apply# 获取当前配置信息rootubuntu:~# netplan getnetwork: version:2ethernets: ens33: addresses: -10.1.8.88/24nameservers: addresses: -10.1.8.2 -223.5.5.5 dhcp4:falseroutes: - to:defaultvia:10.1.8.2ubuntu 系统软件包管理使用apt管理软件包atp和apt-xxx命令 区别-中文atp和apt-xxx命令 区别-英文apt 和 其他apt命令命令区别虽然 apt 与 apt-get 有一些类似的命令选项但它并不能完全向下兼容 apt-get 命令。也就是说可以用 apt 替换部分 apt-get 系列命令但不是全部。apt 命令取代的命令命令的功能apt installapt-get install安装软件包apt removeapt-get remove移除软件包apt purgeapt-get purge移除软件包及配置文件apt updateapt-get update刷新存储库索引apt upgradeapt-get upgrade升级所有可升级的软件包apt autoremoveapt-get autoremove自动删除不需要的包apt full-upgradeapt-get dist-upgrade在升级软件包时自动处理依赖关系apt searchapt-cache search搜索应用程序apt showapt-cache show显示装细节apt 还有一些自己的命令新的apt命令命令的功能apt list列出包含条件的包已安装可升级等apt edit-sources编辑源列表apt子命令rootubuntu:~# apt --tabtabautoclean dependsinstallreinstall update autopurge dist-upgrade list remove upgrade autoremove download moo search build-dep edit-sources policy show changelog full-upgrade purge showsrc cleanhelprdependssourceupdate 子命令update - update list of available packages从软件仓库中获取最新软件清单。rootubuntu:~# apt update相当于yum makecachelist 子命令list - list packages based on package names查看软件仓库中软件清单。# 可用于查看的选项rootubuntu:~# apt list --tabtab--all-versions --manual-installed--upgradable--installed--target-release--verbose# 查看软件包清单rootubuntu:~# apt listWARNING:aptdoes not have a stable CLI interface. Use with cautioninscripts. Listing... 0ad-data-common/jammy,jammy0.0.25b-1 all 0ad-data/jammy,jammy0.0.25b-1 all 0ad/jammy0.0.25b-2 amd64 0install-core/jammy2.16-2 amd64......# 查看特定软件包rootubuntu:~# apt list openssh-serverListing... Done openssh-server/jammy-updates,now1:8.9p1-3ubuntu0.1 amd64[installed]openssh-server/jammy-updates1:8.9p1-3ubuntu0.1 i386# 查看特定软件包所有版本rootubuntu:~# apt list openssh-server --all-versionsListing... Done openssh-server/jammy-updates,now1:8.9p1-3ubuntu0.1 amd64[installed]openssh-server/jammy1:8.9p1-3 amd64 openssh-server/jammy-updates1:8.9p1-3ubuntu0.1 i386 openssh-server/jammy1:8.9p1-3 i386show 子命令show - show package details查看仓库中软件包详细信息。rootubuntu:~# apt show openssh-server# 类似 dpkg -s openssh-serversearch 子命令search - search in package descriptionsrootubuntu:~# apt search --tabtab--full--names-only rootubuntu:~# apt search --names-only apache2install 子命令install - install packages从仓库中获取软件包并安装。rootubuntu:~# apt install --tabtab--allow-change-held-packages --fix-broken--purge--allow-downgrades --fix-missing--reinstall--allow-insecure-repositories --fix-policy--remove--allow-remove-essential --force-yes --show-progress --allow-unauthenticated --ignore-hold --show-upgraded --arch-only --ignore-missing--simulate--assume-no --install-recommends--solver--assume-yes --install-suggests --target-release --auto-remove --no-install-recommends --trivial-only--download--no-install-suggests--upgrade--download-only --only-upgrade --verbose-versions --dry-run --print-uris rootubuntu:~# apt install apache2 -y# 安装特定版本rootubuntu:~# apt install apache22.4.52-1ubuntu4.5reinstall 子命令reinstall - reinstall packages从仓库中获取软件包并再次安装系统中已安装。rootubuntu:~# apt reinstall apache2 -yremove 子命令remove - remove packages卸载系统中已安装软件包。rootubuntu:~# apt remove apache2 -yReading package lists... Done Building dependency tree... Done Reading state information... Done The following packages were automatically installed and are no longer required: apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap Useapt autoremoveto remove them. The following packages will be REMOVED: apache20upgraded,0newly installed,1to remove and282not upgraded. After this operation,546kB disk space will be freed.(Reading database...202598files and directories currently installed.)Removing apache2(2.4.52-1ubuntu4.5)... Processing triggersforman-db(2.10.2-1)... Processing triggersforufw(0.36.1-4build1)...autoremove 子命令autoremove - Remove automatically all unused packagesrootubuntu:~# apt autoremove -yupgrade 子命令upgrade - upgrade the system by installing/upgrading packages# 升级系统所有可更新软件包rootubuntu:~# apt upgrade# 升级系统中特定软件包rootubuntu:~# apt upgrade openssh-server -yfull-upgrade 子命令full-upgrade - upgrade the system by removing/installing/upgrading packages# 升级系统所有可更新软件包rootubuntu:~# apt full-upgrade# 升级系统中特定软件包rootubuntu:~# apt full-upgrade openssh-server -ydownload 子命令download - download packagesrootubuntu:~# apt download openssh-serverrootubuntu:~# lsopenssh-server_1%3a8.9p1-3ubuntu0.1_amd64.debedit-sources 子命令edit-sources - edit the source information filerootubuntu:~# export EDITORvimrootubuntu:~# apt edit-sources# 使用vim编辑文件 /etc/apt/sources.listapt-file作用查找软件包中文件。apt-file is a command line tool for searching files in packages for the APT package management system.帮助信息rootubuntu:~# apt-file --helpapt-file[options]action[pattern]apt-file[options]-factionfileapt-file[options]-DactiondebfilePattern options:--fixed-string-FDo notexpandpattern --from-deb-DUsefilelist of .deb package(s)as patterns;implies-F--from-file-fRead patterns from file(s), one per line(use-forstdin)--ignore-case-iIgnorecasedistinctions--regexp-xpattern is a regular expression --substring-match pattern is a substring(no glob/regex)Search filter options:--architecture-aarchUse specific architecture[L]--index-names-InamesOnly search indices listedinnames[L]--filter-suitessuitesOnly search indicesforthe listedsuites[L](E.g.unstable)--filter-originsoriginsOnly search indices fromorigins[L](E.g.Debian)Other options:--config-cfileParse the given APT configfile[R]--option-oA::BVSet the APT config option A::B toV[R]--package-only-lOnly display packages name--verbose-vruninverbose mode[R]--help-hShow this help. -- End of options(necessaryifpattern starts with a-)[L]: Takes a comma-separated list of values.[R]: The option can be used repeatedly Action: list|showpatternList filesinpackages list-indices List indices configuredinAPT. search|findpatternSearch filesinpackages update Fetch Contents files from apt-sources.示例# 更新apt仓库中文件清单缓存rootubuntu:~# apt-file update# 仓库中某个软件包的文件清单rootubuntu:~# apt-file list openssh-serveropenssh-server: /etc/default/ssh openssh-server: /etc/init.d/ssh openssh-server: /etc/pam.d/sshd openssh-server: /etc/ssh/moduli openssh-server: /etc/ufw/applications.d/openssh-server openssh-server: /lib/systemd/system/rescue-ssh.target......# 使用正则表达式查询ifconfig工具由哪个软件包提供rootubuntu:~# apt-file -x search .*bin/ifconfig$net-tools: /sbin/ifconfig
返回列表