Content of this week's job:
1, create a 10G partition, and the format of the Ext4 file system;
(1) The block size is required to 2048, the reserved space percentage is 2, the volume label is MyData, the default Mount property contains ACLs;
[Email protected]:~# FDISK/DEV/SDA
Command (M for help): P
disk/dev/sda:1000.2 GB, 1000204886016 bytes
255 heads, Sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * MB = bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk identifier:0x0001404d
Device Boot Start End Blocks Id System
/DEV/SDA1 * 2048 1886507007 943252480 Linux
/dev/sda2 1886509054 1953523711 33507329 5 Extended
/dev/sda5 1886509056 1953523711 33507328, Linux Swap/solaris
Command (M for help): N
Partition Type:
P Primary (1 primary, 1 extended, 2 free)
L Logical (numbered from 5)
Select (default P):
Select (default p): P
Partition code (1-4, default 1): 1
Start sector (2048-83886079, default = 2048):
The default value of 2048 will be used
Last sector, + sector or +size{k,m,g} (2048-83886079, default = 83886079): +10g
Partition 3 has been set to Linux type, size set to ten GiB
Command (enter M for help): W
The partition table has been altered!
Calling IOCTL () to re-read partition table.
The disk is being synchronized.
# mkfs.ext4-b 2048-m 2-l mydata/dev/sdb1
MKE2FS 1.42.9 (28-dec-2013)
File System label =mydata
OS Type:linux
Block size =2048 (log=1)
Chunked size =2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 5242880 blocks
104857 blocks (2.00%) reserved for the Super user
First block of data =0
Maximum filesystem blocks=273678336
Groups block
16384 blocks per group, 16384 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104,
2048000, 3981312
Allocating group tables: complete
Writing Inode table: complete
Creating Journal (32768 blocks): complete
Writing Superblocks and FileSystem accounting information: Complete
# Tune2fs-o ACL/DEV/SDB1
TUNE2FS 1.42.9 (28-dec-2013)
(2) Mount to the/data/mydata directory, require the mount to prohibit the program to run automatically, and do not update the file access time stamp;
# mkdir-p/data/mydata
# Mount-o Noatime,noexec/dev/sdb1/data/mydata
2, create a swap partition of size 1G, and create a good file system, and enable it;
# MKSWAP/DEV/SDB2
Setting swap space version 1, size = 1048572 KiB
No label, Uuid=a5c89d64-5fda-4ebd-9b00-92231cd57bae
# SWAPON/DEV/SDB2
3. Write a script
(1), obtain and list all disk devices on the current system;
(2), display the space usage information about each partition on each disk device;
#!/bin/bash#fdisk-l | Grep-o "/dev/sd[[:alnum:]]\{2\}" Echo df-h
4. Summarize the different levels of RAID and its combination mode and performance;
Raid:redundant Arrays of inexpensive disks redundant array of inexpensive disks primarily to improve I/O capability and fault tolerance
Common level is divided into raid-0,radi-1,raid-2 ... RAID-5,RAID-6, combination mode raid10,raid01
Specific implementation and performance differences are described below:
5, the creation of a size of 10G RAID1, requires a free disk, and chunk size of 128k;
# mdadm-c/dev/md1-a yes-c 128-x 1-l 1-n 2/dev/sdb{1,2,3}
6, the creation of a size of 4G RAID5 device, chunk size of 256k, format Ext4 file system, required to automatically mount to the/backup directory, and do not update the access timestamp, and support ACL function;
# mdadm-c/dev/md5-n 3-l 5-a yes/dev/sdb{1,2,3}-C 256
# MKFS.EXT4/DEV/MD5
# echo "/dev/md5/backup ext4 noatime,acl 0 0" &>>/etc/fstab
7. Write a script
(1) Accept more than one file path as a parameter;
(2) show the number of rows owned by each file;
(3) A summary of the total number of documents for several statistics of their lines;
#!/bin/bash#if [$#-eq 0];then echo "Please input in least-file." Exit 2fi for I in $*;d o if [-e $i];then echo "$i Total lines: $ (cat $i | WC-L) "echo" File total:$# "else echo" No such file "Fidone echo" The file number is: "$#
8. Write a script
(1) Pass more than two strings as user name;
(2) Create these users, and the password with the user name;
(3) A summary of the total creation of a number of users;
#!/bin/bash#if [ $# -lt 2 ];then echo "please input two username!" exit 1fi for i in [email protected]; do if cat /etc/passwd | grep $i & > /dev/null; then echo "user $i Already exits " else useradd $i echo $i | passwd --stdin $i &> /dev/null echo "$i added to Current system " let createdUser+=1 fidone echo "number of users created: $createdUsEr
9, write a script, create a new 20 users, visitor1-visitor20; calculate the sum of their IDs;
#!/bin/bash#declare-i sum=0u=visitorfor i in {1..20};d o useradd $U $i uid= ' id-u $U $i ' let sum+= $uidd Oneecho "User ID sum: $sum"
10. Write a script that counts the sum of the number of lines starting with # in/etc/rc.d/rc.sysinit,/etc/rc.d/init.d/functions, and/etc/fstab files, and the total number of blank lines;
#!/bin/bash#declare-i countcount1= ' Cat/etc/rc.d/rc.sysinit/etc/rc.d/init.d/functions/etc/fstab|grep "^#" |wc-l ' Count2= ' Cat/etc/rc.d/rc.sysinit/etc/rc.d/init.d/functions/etc/fstab|grep "^$" |wc-l ' Echo-e "The sum of lines is $coun T1\nthe sum of black lines is $count 2 "
11. Write a script that shows the user name, UID, and the UID of all the default shell users on the current system.
#!/bin/bash#name= ' cat/etc/passwd | grep "/bin/bash" | cut-d:-f1 ' echo-e ' The default shell is Bash user:\n$name ' namesum= ' cat/etc/passwd | grep "/bin/bash" | Cut-d:-f1 | Wc-l ' echo ' The default shell is bash user sum: $namesum "declare-i uidsum=0uid= ' cat/etc/passwd | grep "/bin/bash" | cut-d:-f3 ' for i in $uid;d o let uidsum+= $idoneecho-e "The default shell is bash Uid:\n$uid" echo "the default shell is bash UID sum: $uidsum "
12. Write a script that displays the user name of all the users on the current system with additional groups, and how many such users are in total;
#!/bin/bashdeclare-i count=0for i in ' awk-f: ' {print $} '/etc/passwd ';d o [-z ' id $i |awk-f ', ' {print $ {} ' |awk-f ' ( "{print $} ' |awk-f ') ' {print $} '] | | Echo-e "$i \ n" && let count= $count +1done
13. Create a volume group of at least two physical volumes with a size of 20G, requiring a PE size of 8M, and creating a logical volume of 5G in the volume group MYLV1, formatted as EXT4 file system, boot automatically mounts to/users directory, support ACL;
# fdisk-l/dev/sdb
# pvcreate/dev/sdb{1,2}
# Vgcreate-s 8 VG0/DEV/SDB1/DEV/SDB2
# lvcreate-l 5g-n mylv1/dev/vg0
# mke2fs-t EXT4/DEV/VG0//MYLV1
# echo "/dev/vg0/mylv1/users ext4 defaults,acl 0 0" &>>/etc/fstab
14, the new user magedu, the home directory is/users/magedu, and then su switch to this user, copy multiple files to the home directory;
# useradd-d/users/magedu magedu
# su magedu
# cp-r/tmp//users/magedu
15, expand MYLV1 to 9G, ensure that the original data is fully available after the expansion;
#lvexpand-L 9G/DEV/MYVG/MYLV1
16, reduce MYLV1 to 7G, to ensure that the original data is fully available after the completion of the reduction;
# UMOUNT/DEV/VGTEST/MYLV1
# e2fsck-f/DEV/MYVG/MYLV1
# RESIZE2FS/DEV/MYVG/MYLV1 7G
# lvreduce-l 7G/DEV/MYVG/MYLV1
# mount-a
17, the MYLV1 to create a snapshot, and through the backup data, the requirement to retain the original genera group and other information;
# lvcreate-s-L 7g-p r-n snapmylv1/dev/myvg/mylv
This article is from the "9099360" blog, please be sure to keep this source http://9109360.blog.51cto.com/9099360/1865247
Linux OPS-7th week jobs