1、创建一个10G分区,并格式为ext4文件系统;
(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;
[root@7b ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G Partition 1 of type Linux and of size 10 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@7b /]# mke2fs -t ext4 -b 2048 -m 2 -L MYDATA /dev/sdb1 [root@7b /]# mount -o nodiratime -o acl -o noexec /dev/sdb1 /data/mydata
2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;
[root@7b /]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Using default response p Partition number (2-4, default 2): First sector (20973568-41943039, default 20973568): Using default value 20973568 Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +1G Partition 2 of type Linux and of size 1 GiB is set Command (m for help): t Partition number (1,2, default 2): Hex code (type L to list all codes): 82 Changed type of partition 'XENIX root' to 'Linux swap / Solaris' [root@7b /]# partx -u /dev/sdb [root@7b /]# mkswap /dev/sdb2 Setting up swapspace version 1, size = 1048572 KiB no label, UUID=e03545ff-27c1-4b45-9c72-9738c9bec0e5 [root@7b /]# swapon /dev/sdb2 [root@7b /]# free -m total used free shared buff/cache available Mem: 977 135 705 6 136 702 Swap: 3071 0 3071 [root@7b /]#
3、写一个脚本
(1)、获取并列出当前系统上的所有磁盘设备;
(2)、显示每个磁盘设备上每个分区相关的空间使用信息;
#/bin/bash for i in $(fdisk -l | grep '^\/dev/sd[a-z]' | cut -d' ' -f1 );do echo "fdisk $i" df -h $i done
4、总结RAID的各个级别及其组合方式和性能的不同;
常用的RAID介绍如下: RAID 0:最少2块硬盘,没有冗余功能,可使用的空间N*最小硬盘空间,读与写性能都有提升,理论上读的功能提升1倍 RAID 1:最少2块硬盘,有冗余功能,读性能有提升,但写没有提升(理论上有降低),可使用的空间等于最小硬盘的空间(在两块硬盘的情况) RAID 5:最少3块硬盘,读与写性能都有提升,有冗余功能,可使用空间是N-1*最小硬盘空间 RAID-10:最少4块硬硬盘,读与写性能提升,有冗余功能,可使用空间是N*最小硬盘空间/2
5、创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128k;
[root@7b ~]# mdadm -C /dev/md0 -a yes -l 1 -c 128 -n 3 -x 1 /dev/sdb1 /dev/sdc1 /dev/sdd1
6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;
[root@7b /]# mdadm -C /dev/md0 -a yes -l 5 -n 3 /dev/sdb1 /dev/sdc1 /dev/sdd1 [root@7b /]#mke2fs -t ext4 /dev/md0
7、写一个脚本
(1) 接受一个以上文件路径作为参数;
(2) 显示每个文件拥有的行数;
(3) 总结说明本次共为几个文件统计了其行数;
[root@MiWiFi-R1CM ~]# cat file.sh #/bin/bash num=0 line=0 if [ $# -eq 0 ]; then echo "please input fileame " fi for i in $*;do line=$(wc -l $i | cut -d' ' -f 1 ) let num=$num+1 echo "file $i lines is $line" done echo files num is $num [root@MiWiFi-R1CM ~]# bash -a file.sh /etc/fstab /etc/httpd/conf.d/userdir.conf file /etc/fstab lines is 11 file /etc/httpd/conf.d/userdir.conf lines is 36 files num is 2 [root@MiWiFi-R1CM ~]#
8、写一个脚本
(1) 传递两个以上字符串当作用户名;
(2) 创建这些用户;且密码同用户名;
(3) 总结说明共创建了几个用户;
#/bin/bash usernum=0 if [ $# -le 2 ];then echo "Please input is greater than the two strings" exit 1 fi for i in $*;do if id $i &> /dev/null ;then echo "User $i already exists " continue else useradd $i > /dev/null echo "$i" | passwd --stdin $i let usernum=$usernum+1 fi done echo "usernum is $usernum
9、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和;
#/bin/bash id=0 userid=0 v=visitor for (( i=1;i<=20;i++));do if id $v$i &> /dev/null; then id=$( cat /etc/passwd | grep "$v$i" | cut -d: -f3 ) let userid=$id+$userid else useradd $v$i id=$( cat /etc/passwd | grep "$v$i" | cut -d: -f3 ) let userid=$id+$userid fi done echo "20 Users ID $userid"
10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;
[root@6a ~]# cat 100.sh #!/bin/bash line1=0 line2=0 l1=0 l2=0 for i in $*;do l1=$( grep "^$" $i | wc -l) l2=$(grep "^#" $i | wc -l ) let line1=$line1+$l1 let line2=$line2+$l2 done echo "# linenum is $line1, apace linenum is $line2" [root@6a ~]# bash 100.sh /etc/rc.d/rc.sysinit /etc/rc.d/init.d/functions /etc/fstab # linenum is 173, apace linenum is 91 [root@6a ~]#
11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;
[root@6a ~]# cat 100.sh #!/bin/bash num=0 bashnum=$(grep 'bash$' /etc/passwd | wc -l ) grep "bash$" /etc/passwd | awk -F: '{print $1,$3}' for i in `grep "bash$" /etc/passwd | awk -F: '{print $3}'`;do let num=$num+$i done echo "UUID num is $num" [root@6a ~]# bash 100.sh root 0 test 500 mysql 306 UUID num is 806 [root@6a ~]#
12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户;
[root@6a ~]# cat 100.sh #!/bin/bash num=0 for i in `cut -d: -f1 /etc/passwd`; do group=`id $i | cut -d' ' -f3 | awk -F, '{print $2}' ` if [ -n "$group" ];then echo "$i" let num=$num+1 fi done echo "user num $num" [root@6a ~]# bash 100.sh bin daemon adm postfix mysql user num 5 [root@6a ~]#
13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl;
[root@6a ~]# fdisk -l | grep '\/dev\/sd[b-c]1' /dev/sdb1 1 1306 10490413+ 8e Linux LVM /dev/sdc1 1 1306 10490413+ 8e Linux LVM [root@6a ~]# pvcreate /dev/sdb1 /dev/sdc1 Physical volume "/dev/sdb1" successfully created Physical volume "/dev/sdc1" successfully created [root@6a ~]# vgcreate -s 8m myvg /dev/sdb1 /dev/sdc [root@6a ~]#lvcreate -n mylv1 -L 5g myvg [root@6a ~]#mke2fs -t ext4 /dev/myvg/mylv1 [root@6a ~]#echo "UUID=a73ca2dd-9766-4a2f-aaed-b1e9570190f0 /users ext4 defaults,acl 0 0 " >> /etc/fstab
14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录;
[root@6a user]# useradd -b /user/ magedu [root@6a user]# tail -n 1 /etc/passwd magedu:x:501:501::/user//magedu:/bin/bash [magedu@6a /]$ cp /etc/fstab /etc/inittab /etc/issue.net ~
15、扩展mylv1至9G,确保扩展完成后原有数据完全可用;
[root@6a ~]# lvextend -L +4g /dev/myvg/mylv1 /dev/sdb1 Size of logical volume myvg/mylv1 changed from 5.00 GiB (640 extents) to 9.00 GiB (1152 extents). Logical volume mylv1 successfully resized [root@6a magedu]# resize2fs /dev/myvg/mylv1 [root@6a magedu]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 18G 3.1G 14G 19% / tmpfs 491M 38M 454M 8% /dev/shm /dev/sda1 283M 28M 240M 11% /boot /dev/mapper/myvg-mylv1 8.8G 12M 8.3G 1% /users [root@6a magedu] [root@6a ~]# ll /user/magedu/* -rw-r--r-- 1 magedu magedu 876 Jul 24 10:07 /user/magedu/fstab -rw-r--r-- 1 magedu magedu 884 Jul 24 10:07 /user/magedu/inittab -rw-r--r-- 1 magedu magedu 46 Jul 24 10:07 /user/magedu/issue.net [root@6a ~]#
16、缩减mylv1至7G,确保缩减完成后原有数据完全可用;
[root@6a /]# resize2fs /dev/myvg/mylv1 7G resize2fs 1.41.12 (17-May-2010) Please run 'e2fsck -f /dev/myvg/mylv1' first. [root@6a /]# e2fsck -f /dev/myvg/mylv1 强制检查e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/myvg/mylv1: 11/589824 files (0.0% non-contiguous), 72671/2359296 blocks [root@6a /]# resize2fs /dev/myvg/mylv1 7G 调整文件系统为7Gresize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/myvg/mylv1 to 1835008 (4k) blocks. The filesystem on /dev/myvg/mylv1 is now 1835008 blocks long. [root@6a /]# lvreduce -L 7G /dev/myvg/mylv1 再lv调整为7G WARNING: Reducing active logical volume to 7.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce mylv1? [y/n]: y Size of logical volume myvg/mylv1 changed from 9.00 GiB (1152 extents) to 7.00 GiB (896 extents). Logical volume mylv1 successfully resized [root@6a /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 18G 3.1G 14G 19% / tmpfs 491M 38M 454M 8% /dev/shm /dev/sda1 283M 28M 240M 11% /boot [root@6a /]# mount /dev/myvg/mylv1 /users [root@6a /]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert mylv1 myvg -wi-ao---- 7.00g [root@6a /]#
17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息;
[root@6a magedu]# lvcreate -L 1G -s -p r -n mylve_sn /dev/myvg/mylv1
原创文章,作者:Net20-deamon,如若转载,请注明出处:http://www.178linux.com/25726
评论列表(2条)
写得不错啊
写的很好,排版也很棒,加油