第四周作业

1、打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天的时间,并拷贝到/usr/local/src目录备份。

 

#find /etc/ -name '*.conf'|xargs tar -zcvf `date +F%`.tar.gz && cp -a *.tar.gz /usr/local/src

2、查找当前系统上没有属主或属组,且最近一个周内曾被访问过的文件或目录

 

#find / \( -nouser -o -nogroup \) -a -atime -7

3、查找/etc目录下至少有一类用户没有执行权限的文件

 

#find /etc ! -perm -111

4、自建网络yum源(通过httpd实现)

服务器端:(IP :10.0.0.7

#yum install -y httpd reposync

#systemctl enable --now httpd

#mkdir /var/www/html/centos

#reposync --repoid=extras --download-metadata -p /var/www/html/centos

客户端:

手动创建/etc/yum.repos.d/test.repo

[extras]

name=extras

baseurl=http://10.0.0.7/centos/extras

gpgcheck=1

gpgcheck=file://etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

5、利用sed 取出ifconfig命令中本机的IPv4地址

 

#ifconfig eth0|sed -En '2s/^[^0-9]+([0-9.]+) .*$/\1/p'

 

6、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符

 

sed -Ei.bak '/^#[[:space:]]+/s/^#[[:space:]]+//' /etc/fstab

 

7、处理/etc/fstab路径,使用sed命令取出其目录名和基名

 

#取基名
#echo "/etc/fstab"|sed -E 's#^(/.*/)([^/]+/?)#\2#'

#取目录名
#echo "/etc/fstab"|sed -E 's#^(/.*/)([^/]+/?)#\1#'

 

8 用脚本实现httpd的安装

#!/bin/bash

cd /usr/local
tar -xvf httpd-2.4.46.tar.bz2 -C /usr/local/src
cd /usr/local/src/httpd-2.4.46
./configure --prefix=/apps/httpd24 --sysconfdir=/etc/httpd24 --enable-ssl
make -j 2 && make install
echo 'PATH=/apps/httpd24/bin:$PATH' >/etc/profile.d/httpd24.sh
source /etc/profile.d/httpd24.sh
useradd -r -s /sbin/nologin -d /var/www -c Apache -u 48 apache
sed -Ei.bak -e 's/^(User).*/\3 apache/' -e 's/^(Group).*/\1 apache/' /etc/httpd24/httpd.conf
apachectl start

 

posted @ 2021-10-02 16:22  seraph21  阅读(41)  评论(1)    收藏  举报