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.www58058.com/25726
寫得不錯啊
寫的很好,排版也很棒,加油