美文网首页
第四周-第六周作业

第四周-第六周作业

作者: 念念OPS | 来源:发表于2020-11-21 00:12 被阅读0次

    第四周

    1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
    2、查出用户UID最大值的用户名、UID及shell类型
    3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
    4、编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等 信息
    5、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等

    1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
    grep -ve '/sbin/nologin$' /etc/passwd|cut -d: -f1,7
    
    2.查出用户UID最大值的用户名、UID及shell类型
    cut -d: -f1,3,7 /etc/passwd|sort -rn -t: -k2|sed -n '1p'
    nobody:65534:/sbin/nologin
    
    3.统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
    ~]# ss -nt|tail -n  +2|tr -s ' ' ':'|cut -d: -f6|sort|uniq -c|sort -rn
          2 111.201.246.27
          1 169.254.0.55
    
    4.编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等 信息
    cat > createuser.sh <<EOF
    #!/usr/bin/bash
    read -p "please input USERNAME: " NAME
    [ -z $NAME ] && echo "You must input 1arg for USERNAME" && exit 1
    id $NAME &> /dev/null
    if [ $? -eq 0 ];then
    echo "user $NAME is existed"
    else
    useradd $NAME  &>/dev/null && id  $NAME
    fi
    EOF
    
    5、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
    ~]# cat .vimrc
    set cul
    set ai
    set nu
    autocmd BufNewFile *.sh exec ":call SetTitle()"
    func SetTitle()
            if expand("%:e") == 'sh'
            call setline(1,"#!/bin/bash")
            call setline(2,"#")
            call setline(3,"#***********************************************************")
            call setline(4,"#Author:            wangxingwei")
            call setline(5,"#mail:              2320036424@qq.com")
            call setline(6,"#Date               ".strftime("%Y-%m-%d"))
            call setline(7,"#FileName:          ".expand("%"))
            call setline(8,"#URL:               http://www.wangxingwei.top")
            call setline(9,"#Description:       The test scripts")
            call setline(10,"#Copyright (c):    ".strftime("%Y")." All rights reserved")
            call setline(11,"#***********************************************************")
            call setline(12,"")
            endif
    endfunc
    autocmd BufNewFile * normal G
    
    

    第五周

    1、查找/etc目录下大于1M且类型为普通文件的所有文件
    2、打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天的时间,并拷贝到/usr/local/src目录备份。
    3、利用sed 取出ifconfig命令中本机的IPv4地址
    4、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
    5、处理/etc/fstab路径,使用sed命令取出其目录名和基名

    1、查找/etc目录下大于1M且类型为普通文件的所有文件
    ~]# find /etc \( -type f -a -size +1M \) -exec ls -lh {} \;
    -rw-r--r--. 1 root root 8.2M Apr 24  2020 /etc/selinux/targeted/policy/policy.31
    -r--r--r--. 1 root root 8.8M Oct  7 12:05 /etc/udev/hwdb.bin
    
    2.打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天的时间,并拷贝到/usr/local/src目录备份。
    find /etc -name "*.conf" |xargs tar -czvf `date +%F`.gz && cp -a `date +%F`.gz /usr/local/src/
    
    3.利用sed 取出ifconfig命令中本机的IPv4地址
    ~]# ifconfig eth0|sed -rn '2s/^[^0-9]+([0-9.]+).*/\1/p'
    10.0.80.129
    
    4、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
    cp /etc/fstab /data/
    
    data]# sed -ri '/^# +/s/^#[[:space:]]//' fstab
    root@test8  data]# cat -A fstab
    $
    #$
    /etc/fstab$
    /etc/fstab$
    Created by anaconda on Wed Oct  7 11:58:14 2020$
    Created by anaconda on Wed Oct  7 11:58:14 2020$
    #$
    Accessible filesystems, by reference, are maintained under '/dev/disk/'.$
    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.$
    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$
    After editing this file, run 'systemctl daemon-reload' to update systemd$
    units generated from this file.$
    units generated from this file.$
    #$
    UUID=10835820-15f0-46ba-b30e-33b3f1a61cb8 /        xfs     defaults        0 0$
    UUID=1b507443-4301-442d-9a9d-87adde446ccd /boot    ext4    defaults        1 2$
    UUID=3bfbb7a1-76be-4559-9862-4a5131548f85 /data    xfs     defaults        0 0$
    UUID=aa2bcb41-56be-4d9d-9b60-6600eb8f12c4 swap     swap    defaults        0 0$
    
    5.处理/etc/fstab路径,使用sed命令取出其目录名和基名
    echo '/etc/fstab'|sed -r 's#(^.*)/(.*)#\1#'
    echo '/etc/fstab'|sed -r 's#(^.*)/(.*)#\2#'
    

    第六周

    1、自建yum仓库,分别为网络源和本地源
    2、编译安装http2.4,实现可以正常访问,并将编译步骤和结果提交。
    3、创建一个2G的文件系统,块大小为2048byte,预留1%可用空间,文件系统 ext4,卷标为TEST,要求此分区开机后自动挂载至/test目录,且默认有acl挂载选项
    4、创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小 为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录

    1、自建yum仓库,分别为网络源和本地源
    #reposerver配置
    yum -y install httpd
    systemctl enable --now httpd
    systemctl status httpd
    systemctl disable --now firewalld
    
    yum -y install autofs
    systemctl enable --now autofs
    
    mkdir -p /var/www/html/centos/7/os/x86_64/
    #光盘的base源放到自建仓库了
    cp -a /misc/cd/* /var/www/html/
    [root@reposerver ~]# hostname -I
    192.168.0.110
    
    #同步aliyun的仓库数据与元数据
    
    ~]# yum repolist
    已加载插件:fastestmirror
    Loading mirror speeds from cached hostfile
    源标识             源名称                                                                                                                                 状态
    base-aliyun   base---aliyun                                                           10,070
    extras-aliyun  extras---aliyun                                                          413
    repolist: 10,483
    #准备将aliyun的extras仓库同步到reposerver
    centos8 dnf工具集成
    dnf reposync --repoid=extras-aliyun --download-metadata -p /var/www/html/centos/7
    
    centos7 以前版本,reposync工具来自于yum-utils包 
    yum -y install yum-utils
    yum -y install createrepo
    reposync --repoid=extras-aliyun --download-metadata -p /var/www/html/centos/7
    #下载完成后你会发现没有repodata
    cd /var/www/html/centos/7/extras-aliyun
    extras-aliyun]# createrepo .
    就成功生成repodata目录啦
    extras-aliyun]# tree -d
    .
    ├── Packages
    └── repodata
    
    
    #repoclient配置
    yum.repos.d]# cat local.repo
    [base-local]
    name=base---local
    baseurl=http://192.168.0.110/centos/7/os/x86_64
    gpgcheck=0
    enable=1
    
    [extras-repo]
    name=extras---local
    baseurl=http://192.168.0.110/centos/7/extras-aliyun
    gpgcheck=0
    enable=1
    
    2、编译安装http2.4,实现可以正常访问,并将编译步骤和结果提交。
    src]# ls
    httpd-2.4.46.tar.bz2
    src]# tar xf httpd-2.4.46.tar.bz2
    root@test8  src]# ls
    httpd-2.4.46  httpd-2.4.46.tar.bz2
    root@test8  src]# cd httpd-2.4.46/
    httpd-2.4.46]# ./configure --prefix=/usr/local/src --enable-ssl
    checking for APR... no
    configure: error: APR not found.  Please read the documentation.
    
    httpd-2.4.46]# yum search apr*
    httpd-2.4.46]# yum -y install apr-util-devel.x86_64 apr-util.x86_64
    
    httpd-2.4.46]# ./configure --prefix=/usr/local/src --enable-ssl
    checking for pcre-config... false
    configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
    
    httpd-2.4.46]# yum search pcre*
    httpd-2.4.46]# yum -y install pcre.x86_64 pcre2-devel.x86_64 pcre-devel.x86_64
    httpd-2.4.46]# ./configure --prefix=/apps/http24 --enable-ssl
    configure: WARNING: OpenSSL version is too old
    no
    checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
    httpd-2.4.46]# yum install -y openssl-devel.x86_64
     Server Version: 2.4.46
        Install prefix: /usr/local/src
        C compiler:     gcc
        CFLAGS:           -pthread
        CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE
        LDFLAGS:
        LIBS:
        C preprocessor: gcc -E
    httpd-2.4.46]# make && make install
    make[4]: Leaving directory '/usr/local/src/httpd-2.4.46/modules/mappers'
    make[3]: Leaving directory '/usr/local/src/httpd-2.4.46/modules/mappers'
    make[2]: Leaving directory '/usr/local/src/httpd-2.4.46/modules'
    make[2]: Entering directory '/usr/local/src/httpd-2.4.46/support'
    make[2]: Leaving directory '/usr/local/src/httpd-2.4.46/support'
    
    make[1]: Leaving directory '/usr/local/src/httpd-2.4.46'
    
    make[1]: Leaving directory '/usr/local/src/httpd-2.4.46'
    httpd-2.4.46]# echo $?
    0
    
    
    3、创建一个2G的文件系统,块大小为2048byte,预留1%可用空间,文件系统 ext4,卷标为TEST,要求此分区开机后自动挂载至/test目录,且默认有acl挂载选项
    ~]# echo -e "n\np\n1\n\n+2G\nw\n"|fdisk /dev/sdb 
    #创建ext4文件系统 设置块大小2048 预留管理员空间1%
    ~]# mkfs.ext4 -m1 -b2048 /dev/sdb1
    mke2fs 1.45.4 (23-Sep-2019)
    /dev/sdb1 contains a ext4 file system
        created on Thu Nov 19 20:26:21 2020
    Proceed anyway? (y,N) y
    Creating filesystem with 1048576 2k blocks and 131072 inodes
    Filesystem UUID: a61d4e9c-56a7-48fd-897f-39f0ca2a5908
    Superblock backups stored on blocks:
        16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816
    
    Allocating group tables: done
    Writing inode tables: done
    Creating journal (16384 blocks): done
    Writing superblocks and filesystem accounting information: done
    #设置卷标为TEST
    ~]# tune2fs -L TEST /dev/sdb1
    tune2fs 1.45.4 (23-Sep-2019)
    #验证
    ~]# tune2fs -l /dev/sdb1
    tune2fs 1.45.4 (23-Sep-2019)
    Filesystem volume name:   TEST                                  #卷标
    Last mounted on:          <not available>
    Filesystem UUID:          a61d4e9c-56a7-48fd-897f-39f0ca2a5908
    Filesystem magic number:  0xEF53
    Filesystem revision #:    1 (dynamic)
    Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
    Filesystem flags:         signed_directory_hash
    Default mount options:    user_xattr acl
    Filesystem state:         clean
    Errors behavior:          Continue
    Filesystem OS type:       Linux
    Inode count:              131072
    Block count:              1048576
    Reserved block count:     10485             #预留了1%
    Free blocks:              1011035
    Free inodes:              131061
    First block:              0
    Block size:               2048          #果然是2048字节
    Fragment size:            2048
    Group descriptor size:    64
    Reserved GDT blocks:      512
    Blocks per group:         16384
    Fragments per group:      16384
    Inodes per group:         2048
    Inode blocks per group:   256
    Flex block group size:    16
    Filesystem created:       Thu Nov 19 20:27:35 2020
    Last mount time:          n/a
    Last write time:          Thu Nov 19 20:28:50 2020
    Mount count:              0
    Maximum mount count:      -1
    Last checked:             Thu Nov 19 20:27:35 2020
    Check interval:           0 (<none>)
    Lifetime writes:          1058 kB
    Reserved blocks uid:      0 (user root)
    Reserved blocks gid:      0 (group root)
    First inode:              11
    Inode size:           256
    Required extra isize:     32
    Desired extra isize:      32
    Journal inode:            8
    Default directory hash:   half_md4
    Directory Hash Seed:      a2e6b435-0fcf-497e-bb7e-61da08147a2a
    Journal backup:           inode blocks
    Checksum type:            crc32c
    Checksum:                 0xb2aef5d6
    
    #开始挂载
    #创建挂载目录
    ~]# mkdir /test
    #挂载 并设置具备acl权限
    ~]# mount -o remount,acl /dev/sdb1 /test
    ~]# blkid /dev/sdb1
    /dev/sdb1: LABEL="TEST" UUID="a61d4e9c-56a7-48fd-897f-39f0ca2a5908" TYPE="ext4" PARTUUID="461250dd-01"
    cat >>/etc/fstab <<EOF
    UUID=a61d4e9c-56a7-48fd-897f-39f0ca2a5908 /test ext4 defaults 0 0
    EOF
    
    
    
    4、创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录
    #创建分区/dev/sdb1 ID为8e逻辑卷LVM分区 19G 和sdc的1G
    fdisk /dev/sdb 
    
    ~]# lsblk
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda      8:0    0  200G  0 disk
    ├─sda1   8:1    0    1G  0 part /boot
    ├─sda2   8:2    0  100G  0 part /
    ├─sda3   8:3    0    2G  0 part [SWAP]
    ├─sda4   8:4    0    1K  0 part
    └─sda5   8:5    0   50G  0 part /data
    sdb      8:16   0   20G  0 disk
    └─sdb1   8:17   0   19G  0 part
    sdc      8:32   0    1G  0 disk
    
    #创建总共20G的pv
    ~]# pvcreate /dev/sdb1 /dev/sdc
      Physical volume "/dev/sdb1" successfully created.
      Physical volume "/dev/sdc" successfully created.
    root@test8  ~]# pvs
      PV         VG Fmt  Attr PSize  PFree
      /dev/sdb1     lvm2 ---  19.00g 19.00g
      /dev/sdc      lvm2 ---   1.00g  1.00g
    root@test8  ~]# pvdisplay
      "/dev/sdb1" is a new physical volume of "19.00 GiB"
      --- NEW Physical volume ---
      PV Name               /dev/sdb1
      VG Name
      PV Size               19.00 GiB
      Allocatable           NO
      PE Size               0
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               PMXohr-Srmd-pFEf-zS0b-qvXy-ekgg-rggCEl
    
      "/dev/sdc" is a new physical volume of "1.00 GiB"
      --- NEW Physical volume ---
      PV Name               /dev/sdc
      VG Name
      PV Size               1.00 GiB
      Allocatable           NO
      PE Size               0
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               BEIxwP-ktC3-DumP-Y2iX-GOpk-yjvy-eOWTws
    
    #创建名为testvg的VG;要求PE大小为16MB
     ~]# vgcreate -s 16M testvg /dev/sdb1 /dev/sdc
      Volume group "testvg" successfully created
      
    ~]# vgdisplay
      --- Volume group ---
      VG Name               testvg
      System ID
      Format                lvm2
      Metadata Areas        2
      Metadata Sequence No  1
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                0
      Open LV               0
      Max PV                0
      Cur PV                2
      Act PV                2
      VG Size               <19.97 GiB
      PE Size               16.00 MiB
      Total PE              1278
      Alloc PE / Size       0 / 0
      Free  PE / Size       1278 / <19.97 GiB
      VG UUID               9DduV6-hgQT-dmkn-utZh-4APf-GHiI-tvN7fb
    
    #创建大小5G的逻辑卷 饼挂载/users目录
    ~]# lvcreate -n testlv -L +5G testvg
    WARNING: ext4 signature detected on /dev/testvg/testlv at offset 1080. Wipe it? [y/n]: y
      Wiping ext4 signature on /dev/testvg/testlv.
      Logical volume "testlv" created.
    #格式化 创建xfs文件系统
    ~]# mkfs.xfs /dev/mapper/testvg-testlv
    meta-data=/dev/mapper/testvg-testlv isize=512    agcount=4, agsize=327680 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=1, sparse=1, rmapbt=0
             =                       reflink=1
    data     =                       bsize=4096   blocks=1310720, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
    log      =internal log           bsize=4096   blocks=2560, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    
    #挂载
    ~]# mount /dev/mapper/testvg-testlv /user
    

    相关文章

      网友评论

          本文标题:第四周-第六周作业

          本文链接:https://www.haomeiwen.com/subject/atfsiktx.html