1、自建yum仓库,分别为网络源和本地源
1)加载虚拟光驱镜像文件并设置为已连接状态
2)配置autofs服务
[root@centos8-1 ~]# rpm -q autofs
autofs-5.1.4-48.el8_4.1.x86_64
[root@centos8-1 ~]# systemctl is-active autofs
active
[root@centos8-1 ~]# systemctl is-enabled autofs
enabled
3)备份默认repo文件
[root@centos8-1 ~]# cd /etc/yum.repos.d/
[root@centos8-1 yum.repos.d]# mkdir bak
[root@centos8-1 yum.repos.d]# ls
bak CentOS-Linux-Media.repo
CentOS-Linux-AppStream.repo CentOS-Linux-Plus.repo
CentOS-Linux-BaseOS.repo CentOS-Linux-PowerTools.repo
CentOS-Linux-ContinuousRelease.repo CentOS-Linux-Sources.repo
CentOS-Linux-Debuginfo.repo epel-modular.repo
CentOS-Linux-Devel.repo epel-playground.repo
CentOS-Linux-Extras.repo epel.repo
CentOS-Linux-FastTrack.repo epel-testing-modular.repo
CentOS-Linux-HighAvailability.repo epel-testing.repo
[root@centos8-1 yum.repos.d]# mv C* e* bak/
4)编辑repo配置文件
[root@centos8-1 ~]# cat > /etc/yum.repos.d/centos-custom.repo <<EOF
> [Local-BaseOS]
> name=Local-BaseOS
> baseurl=file:///misc/cd/BaseOS
> enabled=1
> gpgcheck=1
> gpgkey=file:etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
>
> [Local-AppStream]
> name=Local-AppStream
> baseurl=file:///misc/cd/AppStream
> enabled=1
> gpgcheck=0
> gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
>
> [BaseOS]
> name=BaseOS
> baseurl=https://mirrors.aliyun.com/centos/\$releasever/BaseOS/\$basearch/os
> enabled=1
> gpgcheck=0
>
> [AppStream]
> name=Appstream
> baseurl=https://mirrors.aliyun.com/centos/\$releasever/AppStream/\$basearch/os
> enabled=1
> gpgcheck=0
>
> [Extras]
> name=Extras
> baseurl=https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/os
> enabled=1
> gpgcheck=0
>
> [Epel]
> name=Epel
> baseurl=https://mirrors.aliyun.com/epel/\$releasever/Everything/\$basearch
> enabled=1
> gpgcheck=0
> EOF
5)生成缓存
[root@centos8-1 ~]# yum makecache
Local-BaseOS 6.7 MB/s | 2.3 MB 00:00
Local-AppStream 52 MB/s | 6.2 MB 00:00
BaseOS 1.8 MB/s | 7.4 MB 00:04
Appstream 2.1 MB/s | 8.9 MB 00:04
Extras 10 kB/s | 10 kB 00:00
Epel 1.8 MB/s | 10 MB 00:05
Extra Packages for Enterprise Linux Modular 8 - x86_64 280 kB/s | 941 kB 00:03
Extra Packages for Enterprise Linux 8 - x86_64 3.2 MB/s | 10 MB 00:03
Metadata cache created.
6)测试软件安装
[root@centos8-1 ~]# yum -y install zsh
Last metadata expiration check: 0:02:58 ago on Sat 18 Sep 2021 12:56:09 PM CST.
Dependencies resolved.
==============================================================================================
Package Architecture Version Repository Size
==============================================================================================
Installing:
zsh x86_64 5.5.1-6.el8_1.2 Local-BaseOS 2.9 M
Transaction Summary
==============================================================================================
Install 1 Package
Total size: 2.9 M
Installed size: 7.2 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : zsh-5.5.1-6.el8_1.2.x86_64 1/1
Running scriptlet: zsh-5.5.1-6.el8_1.2.x86_64 1/1
Verifying : zsh-5.5.1-6.el8_1.2.x86_64 1/1
Installed:
zsh-5.5.1-6.el8_1.2.x86_64
Complete!
2、编译安装http2.4,实现可以正常访问,并将编译步骤和结果提交。
OS:CentOS 8.3 64位
[root@centos8-1 ~]# cat /etc/centos-release
CentOS Linux release 8.3.2011
IP:192.168.104.80/24
[root@centos8-1 ~]# ip a sh
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:50:56:32:7f:62 brd ff:ff:ff:ff:ff:ff
inet 192.168.104.80/24 brd 192.168.104.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::ab9c:73af:218c:9602/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:50:56:21:68:e4 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.162/24 brd 10.0.0.255 scope global dynamic noprefixroute eth1
valid_lft 1332sec preferred_lft 1332sec
inet6 fe80::78bd:6a7c:4df:f12c/64 scope link noprefixroute
valid_lft forever preferred_lft forever
1)确定是否关闭防火墙和SELinux
[root@centos8-1 ~]# systemctl is-active firewalld
inactive
[root@centos8-1 ~]# sestatus
SELinux status: disabled
2)编写脚本
[root@centos8-1 ~]# vim /data/install_httpd.sh
#!/bin/bash
#Author:liuxiaofu
#set -ue
REG='\e[1;31m'
GREEN='\e[1;32m'
END='\e[0m'
VERSION=2.4.48
TARGET_DIR=/usr/local/src
INSTALL_DIR=/apps/httpd
CONFIG_FILE_DIR=/etc/httpd
PACK="gcc apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config"
CPU_CORE="$(lscpu | sed -nr '/^CPU\(.*/s/[^0-9]+//p')"
# Create users and groups
getent group apache &> /dev/null
if [ $? -eq 0 ];then
echo -e "${REG}group is exist${END}"
else
groupadd -r -g 88 apache
fi
id apache &> /dev/null
if [ $? -eq 0 ];then
echo "${RED}user is exist${END}"
else
useradd -r -s /sbin/nologin -g apache -u 88 -d /var/www/ apache
fi
# Download the HTTPD package
wget -O ${TARGET_DIR}/httpd-${VERSION}.tar.bz2 https://dlcdn.apache.org//httpd/httpd-${VERSION}.tar.bz2 &>/dev/null || curl -s -o ${TARGET_DIR}/httpd-${VERSION}.tar.bz2 https://dlcdn.apache.org//httpd/httpd-${VERSION}.tar.bz2 &>/dev/null
# Installing dependency packages
for I in ${PACK}
do
yum -y install $I &> /dev/null
done
if [ $? -ne 0 ]
then
echo -e "${RED}Install failed.${END}"
exit
fi
# Decompressing files
cd ${TARGET_DIR}
tar xf httpd-${VERSION}.tar.bz2
# Go to the decompressing directory
cd httpd-${VERSION}
# Generate the makefile file
./configure --prefix=${INSTALL_DIR} --sysconfdir=${CONFIG_FILE_DIR} --enable-ssl &>/dev/null
# Compile and install
make -j ${CPU_CORE} &> /dev/null && make install &> /dev/null
# Write the PATH
echo 'PATH=${INSTALL_DIR}/bin/:$PATH' > /etc/profile.d/httpd.sh
source /etc/profile.d/httpd.sh
# Replace users and groups in the configuration file
sed -i -e '/^User/cUser apache' -e '/^Group/cGroup apache' ${CONFIG_FILE_DIR}/httpd.conf
# Start httpd
apachectl start && echo -e "${GREEN}Start the httpd finish.${END}"
3)给脚本增加执行权限
[root@centos8-1 ~]# chmod +x /data/install_httpd.sh
4)运行脚本
5)测试网页是否正常访问
3、利用sed 取出ifconfig命令中本机的IPv4地址
[root@centos8-1 ~]# ifconfig eth0 | sed -nr '2s/(^.*inet )(.*)(net.*)/\2/p'
192.168.104.80
[root@centos8-1 ~]# ifconfig eth0 | sed -rn '2s/.*inet //;2s/net.*//p'
192.168.104.80
[root@centos8-1 ~]# ifconfig eth0 | sed -rn '2s#([^[:digit:]]+)([^[:alpha:]]+).*#\2#p'
192.168.104.80
4、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
[root@centos8-1 ~]# sed -r -e 's/^#[[:space:]]+//' -e 's/^#//' -e 's/^$//' /etc/fstab
/etc/fstab
Created by anaconda on Fri Sep 17 22:43:50 2021
Accessible filesystems, by reference, are maintained under '/dev/disk/'.
See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
After editing this file, run 'systemctl daemon-reload' to update systemd
units generated from this file.
UUID=fca0a541-69c9-4e35-9ca6-c9a0c317ae86 / xfs defaults 0 0
UUID=6858b3cf-cc5d-450e-a14b-f05dc49fb76d /boot ext4 defaults 1 2
UUID=67d655e0-2ced-4cb5-9ff2-daac9f8b3d44 /data xfs defaults 0 0
UUID=63b9b6bd-e492-4a5b-8aed-2e5588b52db2 none swap defaults 0 0
5、处理/etc/fstab路径,使用sed命令取出其目录名和基名
# 取目录名
[root@centos8-1 ~]# echo '/etc/fstab/' | sed -nr 's#(.*)/([^/]+)/?#\1#p'
/etc
# 取基名
[root@centos8-1 ~]# echo '/etc/fstab/' | sed -nr 's#(.*)/([^/]+)/?#\2#p'
fstab
6、列出ubuntu软件管理工具apt的一些用法(自由总结)
1) apt update: 更新本地软件包索引
2) apt upgrade:升级系统中所有可升级的包
3) apt full-upgrade:将系统升级到新的版本,会移除旧的软件包
4) apt install 包名:安装软件包
5) apt remove 包名:移除单个软件包(保留配置文件)
6) apt autoremove 软件包:移除安装包并解决依赖关系
7) apt purge 包名:移除软件包及配置文件
8) apt list [包名]:列出包含条件的包列表(可使用通配符),不加条件列出所有包
9) apt list --installed:列出所有已安装的包
10) apt list --upgrade:列出所有可以升级的包
11) apt show 包名:列出包的信息,包括(依赖关系、安装和下载大小、包的来源、包内容的描述等)
12) apt search 包名:在仓库中搜索匹配到的包的列表
13) apt edit-sources:编辑/etc/apt/source.list文件
14) apt-cache madison 包名:查看仓库中软件包有哪些版本可以安装
15) apt install 包名=具体版本:安装包的时候指定具体的版本
16) apt-file [-xF] search 包名:查看文件来自于哪个包安装,支持正则表达式(apt-file命令默认没有需要apt -y install apt-file安装!)