软件包管理及初始化设置

gcc编译解析

四大步骤:预处理、编译、汇编、链接

预处理:gcc -E heelo.c -o heelo.i

对其中的伪指令(以#开头的指令,也就是宏)和特殊符号进行“替代”处理,这个文件的含义同没有经过预处理的源文件是相同的,仍然是C文件,但内容有所不同。

编译:gcc -S heelo.i -o heelo.s

将其翻译成等价的中间代码表示或汇编代码。

汇编:gcc -c hello.s -o hello.o

汇编过程实际上指把汇编语言代码翻译成目标机器指令的过程。

链接:gcc hello.o -o hello

汇编程序生成的目标文件并不能立即就被执行,
链接程序的主要工作就是将有关的目标文件彼此相连接,也即将在一个文件中引用的符号同该符号在另外一个文件中的定义连接起来,使得所有的这些目标文件成为一个能够被操作系统装入执行的统一整体,也就是可执行程序。

分为动态链接和静态链接,静态链接需添加"-static"

常用包管理器

RPM

是一种由红帽公司开发的软件包管理方式,在 Linux 中通过以 .rmp 为扩展名的文件对应用程序包进行管理。RPM 文件带有 .rpm 扩展名,RPM 程序包由一个存档文件组成,该文件包含特定程序包的库和依赖项。使用 RPM 我们可以方便的进行软件的安装、查询、卸载、升级、校验等工作。
**!!!无法解决包依赖问题**

命名格式:name-version-release.os.arch.rpm;软件名称-版本号-发布次数.适合linux系统.主机平台.rpm

常用命令
-ivh      安装一个包
-q        查询包是否被安装
-qi       查询被安装的包的信息,列出包中有哪些文件
-qf       查询文件所属包
-qa       列出所有的rpm包
–force    覆盖属于原先包的文件,强制覆盖安装
–nodeps   如果该RPM包的安装依赖其它包,即使其它包没装,也强制安装
YUM

YUM 是使用 RPM 作为软件包管理器的 Linux 操作系统的免费的开放源代码的命令行软件包管理应用程序,是基于 RPM 的前端管理工具,它是对 RPM 包进行管理的客户端,它是一种 Shell 前端软件包管理器。

注意:YUM是一个在线软件管理工具,所以使用YUM进行的操作大都是需要在联网的条件下才能正常使用。

对比RPM

  1. 可以自动解决软件包的依赖关系
  2. 可以对 RPM 包进行分组,基于组进行安装操作
  3. 引入仓库概念,支持多个仓库(即可以同时配置多个资源库),可以从发行官方存储库和其他第三方存储库安装 RPM 软件包
  4. 简洁的配置文件(/etc/yum.conf)

YUM 是在 RPM 的基础上对软件包进行管理,实现了 RPM 软件包管理器在功能上的扩展,YUM 必须依赖于 RPM,因此 YUM 是不能脱离 RPM 而独立运行的。

常用命令
参数说明
install <软件包名>安装 rpm软件包
update <软件包名>更新 rpm软件包
check-update检查是否有可用的更新 rpm软件包
remove <软件包名>删除指定的 rpm 软件包
list显示软件包信息
clean清理 yum 过期的缓存
provides<软件包名><文件路径>查询所需包
info <软件包名>查看软件包的具体信息
makecache重新加载yum源
DNF

可以理解为升级版的yum,基本用法和yum相同,centos8已默认安装dnf。

APT,常用于ubuntu中

基于 dpkg 打包系统,常用于ubuntu中,

参数说明
update更新数据库,需在安装包之前执行
upgrade升级已安装的包
install安装包
remove卸载包 (删除不干净,不建议使用)
purge彻底删除
list软件包列表
search package_name搜索包
show package_name显示包信息
  • 下载的软件的存放位置:/var/cache/apt/archives
  • 安装后软件的默认位置:/usr/share
  • 可执行文件位置:/usr/bin
  • 配置文件位置:/etc
  • lib文件位置:/usr/lib

配置yum/apt源仓库

yum源

路径在 /etc/yum.repos.d/ 下编辑 .repo 后缀的文件,,建议将原有的文件mv到别的地方或在该路径下另建个文件夹存放,有时一些软件包会因某些原因而无法在自己配置的源仓库中下载,可将文件移回到该路径继续使用。

相关仓库地址可在各大镜像源网址寻找,例如阿里云、腾讯云

#以centos8、rocky8为例
[root@rocky8  ~]#cd /etc/yum.repos.d
[root@rocky8  yum.repos.d]#vim base.repo
[BaseOS]
name=BaseOS
baseurl=https://mirror.tuna.tsinghua.edu.cn/centos/8/BaseOS/x86_64/os/
		https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/
gpgcheck=0
[AppStream]
name=AppStream
baseurl=https://mirror.tuna.tsinghua.edu.cn/centos/8/AppStream/x86_64/os/
		https://mirrors.aliyun.com/centos/8/AppStream/x86_64/os/
gpgcheck=0
[epel]
name=EPEL
baseurl=https://mirror.tuna.tsinghua.edu.cn/epel/$releasever/Everything/$basearch
		https://mirrors.aliyun.com/epel/$releasever/Everything/$basearch
gpgcheck=0                   需不需要检查该源来源的安全性
enabled=1                    启用该仓库,0为不启用

#加载yum源仓库
yum makecache

初始化安装建议搭建[BaseOS]、[AppStream]、[epel]这三个源,也可按需搭建,可搭建多个也可合为一个,centos7以下将[BaseOS]、[AppStream]合为一个仓库源即可

apt源

修改配置文件 /etc/apt/sources.list 即可,文件格式需以sources开头,可配置多份,直接备份,将各大镜像源中的apt源直接粘贴即可

阿里云,ubuntu 2004,下滑即可找到

deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

清华大学,ubuntu2004,可选相对应版本

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse

# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

初始化设置

centos/rocky初始化脚本
#!/bin/bash
#关闭SELinux
disable_selinux () {
    sed -i '/^SELINUX=/c SELINUX=disabled' /etc/selinux/config
}
#关闭防火墙
disable_firewall () {
    systemctl disable --now firewalld
}
#配置yum仓库
yum_config () {
    mkdir /etc/yum.repos.d/backup
    mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/
    cat > /etc/yum.repos.d/base.repo <<EOF
[BaseOS]
name=BaseOS
baseurl=https://mirror.tuna.tsinghua.edu.cn/centos/8/BaseOS/x86_64/os/
		https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/
gpgcheck=0
[AppStream]
name=AppStream
baseurl=https://mirror.tuna.tsinghua.edu.cn/centos/8/AppStream/x86_64/os/
		https://mirrors.aliyun.com/centos/8/AppStream/x86_64/os/
gpgcheck=0
[epel]
name=EPEL
baseurl=https://mirror.tuna.tsinghua.edu.cn/epel/8/Everything/x86_64
		https://mirrors.aliyun.com/epel/8/Everything/x86_64
gpgcheck=0                   
enabled=1 

EOF
}
#修改网卡名称
config_network () {
    sed -ri '/GRUB_CMDLINE_LINUX=/s#(.*)"$#\1 net .ifnames=0"#' /etc/default/grub
    grub2-mkconfig -o /boot/grub2/grub.cfg
}
#建议安装软件
install_packages () {
    yum -y install autofs vim-enhanced tcpdump chrony lrzsz tree telnet ftp lftp redhat-lsb-core bash-completion postfix wget bzip2 zip unzip xz lsof mlocate man-pages rsync
}
#更改提示符信息
set_env () {
    cat > /etc/profile.d/env.sh <<EOF
PS1="\[\e[1;32m\][\t \[\e[1;33m\]\u\[\e[35m\]@\h\[\e[1;31m\] \W\[\e[1;32m\]]\[\e[0m\]\\$"
export EDITOR=vim
export HISTTIMEFORMAT="%F %T "
EOF
}
disable_selinux
disable_firewall
set_cdrom
yum_config
config_network
install_packages
set_env
reboot
ubuntu

详细解析,也可写成脚本,在此为方便理解步骤过程

1、开启远程root登录,默认无法以root登录
sudo -i
passwd root
sed -i '/PermitRootLogin/c PermitRootLogin yes' /etc/ssh/sshd_conf
systemctl restart sshd
2、更换镜像源

同上apt源

3、建议安装软件
apt -y purge ufw lxd lxd-client lxcfs liblxc-common
apt -y install iproute2 ntpdate tcpdump telnet traceroute nfs-kernel-server nfs-common lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev  gcc openssh-server  iotop unzip zip
4、关闭防火墙
ufw disable
5、修改网卡名称
vim /etc/default/grub
#更改值为
GRUB_CMDLINE_LINUX=“net.ifnames=0 biosdevname=0update-grub
6、修改网络配置文件,注意文件以.yaml为后缀,留意同级的缩进
[root@rocky8  ~]#cd /etc/netplan/
[root@rocky8  ~]#cp /etc/netplan/*.yaml eth0.yaml
[root@rocky8  ~]#vim eth0.yaml
network:
  ethernets:
    eth0:
      dhcp4: no                                  静态地址
      addresses: [10.0.0.152/24]                 ip地址
      gateway4: 10.0.0.2                         网关
  version: 2                                     版本
  renderer: networkd                             固定格式


#如需动态自动获取地址,可将dhcp4改为yes,表示ipv4的自动获取

#执行
netplan apply
ip a     查看结果

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值