1、自建yum仓库,分别为网络源和本地源
#备份yum旧文件
mkdir -p /etc/yum.repos.d/backup
mv /etc/yum.d/*.repo bakcup/
cat >/etc/yum.repos.d/base.repo <<EOF
[BaseOS]
name=CentOS-$releasever - Base
baseurl=https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
file:///mnt/BaseOS/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[AppStram]
name=CentOS-$releasever - AppStream
baseurl=https://mirrors.aliyun.com/centos/$releasever/AppStream/$basearch/os/
file:///mnt/AppStream/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[Extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch/os/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[EPEL]
name=Centos-$releasever - EPEL
baseurl=https://mirrors.aliyun.com/epel/$releasever/Everything/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-8
enabled=1
EOF
2、编译安装http2.4,实现可以正常访问,并将编译步骤和结果提交。
#安装依赖包
[root@centos8 ~]#dnf install gcc make apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config
#下载源代码
[root@centos8 ~]#wget https://mirrors.bfsu.edu.cn/apache//httpd/httpd-2.4.46.tar.gz
#解压目录
[root@centos8 ~]#tar zxvf httpd-2.4.46.tar.gz -C /usr/local/src
[root@centos8 ~]#cd /usr/local/src/httpd-2.4.46
#配置参数
[root@centos8 ~]#./configure --prefix=/apps/httpd24 --sysconfdir=/etc/httpd24 --enable-ssl
#编译并安装
[root@centos8 ~]#make -j 2 &&make install
#配置环境变量
[root@centos8 ~]#echo 'PATH=/apps/httpd24/bin:$PATH' > /etc/profile.d/httpd24.sh
[root@centos8 ~]#source /etc/profile.d/httpd24.sh
#创建apache用户
[root@centos8 ~]#useradd -r -u 48 -s /sbin/nologin -d /var/www apache
#配置http配置文件,修改用户为apache
[root@centos8 ~]#vim /etc/httpd24/httpd.conf
User apache
Group apache
#启动服务
[root@centos8 ~]#apachectl start
#测试
[root@centos8 ~]# ps -aux |grep httpd
root 18705 0.0 0.2 117504 5216 ? Ss 21:50 0:00 /apps/httpd24/bin/httpd -k start
apache 18709 0.4 0.4 2057880 7600 ? Sl 21:50 0:00 /apps/httpd24/bin/httpd -k start
apache 18710 0.3 0.6 2123416 11680 ? Sl 21:50 0:00 /apps/httpd24/bin/httpd -k start
apache 18711 0.0 0.4 2057880 7600 ? Sl 21:50 0:00 /apps/httpd24/bin/httpd -k start
root 18804 0.0 0.0 12112 1088 pts/1 R+ 21:51 0:00 grep --color=auto httpd
[root@centos8 ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
3、利用sed 取出ifconfig命令中本机的IPv4地址
ifconfig eth0 | sed -nr '/netmask/s#^[^0-9]+([0-9.]+).*$#\1#p'
ifconfig |awk 'NR==2{print $2}'
4、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
sed -i.bak '/^[#]/d' /etc/fstab
5、处理/etc/fstab路径,使用sed命令取出其目录名和基名
#目录名
echo /etc/fstab |sed -nr 's#(^.*\/)[a-z]+$#\1#p'
#基名
echo /etc/fstab |sed -nr 's#^.*\/([a-z]+)$#\1#p'