Linux OPS Practice case-December 20, 2015-December 31 (first time)

Source: Internet
Author: User
Tags uuid egrep

1, the creation of a 10G file system, the type of EXT4, requires the boot can be automatically mounted to a separate data/data directory;

Sure it's mbr/gpt[[email protected] ~]# lsblkname        .     MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTsda                8:0    0    20G  0 disk ├─sda1             8:1    0    2M  0 part ├─sda2             8:2    0     1G  0 part /boot└─sda3             8:3    0 18.9G  0 part    ├─centos-root 253:0    0   10g  0 lvm  /   ├─centos-swap 253:1 &Nbsp;  0    1g  0 lvm  [swap]  └─centos-home  253:2    0  7.9G  0 lvm  /homesr0               11:0    1  1024m  0 rom  [[email protected] ~]# parted /dev/sda  printmodel: vmware, vmware virtual s  (SCSI) Disk /dev/sda: 21.5gbsector  size  (logical/physical):  512b/512bpartition table: gptdisk flags: pmbr_ Bootnumber  start   end     size    file  system  Name  Flags 1      1049kB   3146kb  2097kb                      bios_grub 2      3146kb  1077mb  1074mb   xfs 3      1077mb  21.3gb  20.3gb                       lvm //partition a specified capacity disk [[email protected] ~]# gdisk /dev/sdagpt fdisk  (Gdisk)   Version 0.8.6partition table scan:  mbr: protective  bsd: not  present  apm: not present  gpt: presentfound valid gpt  with protective mbr; using gpt. command  ( for help): npartition number  (4-128, default 4):  First  sector  (34-41943006, default = 41662464)  or {+-}size{kmgtp}: last  sector  (41662464-41943006, default = 41943006)  OR&NBSp {+-}size{kmgtp}: +10g current type is  ' Linux filesystem ' Hex code or  GUID  (l to show codes, enter = 8300):  changed type of  partition to  ' Linux filesystem ' command  (?  for help):  pdisk /dev/ Sda: 41943040 sectors, 20.0 giblogical sector size: 512 bytesdisk  identifier  (GUID):  974d2867-3522-4343-84a3-a2b26850627epartition table holds up  to 128 entriesfirst usable sector is 34, last usable sector  is 41943006partitions will be aligned on 2048-sector boundariestotal  free space is 180157 sectors  (88.0 MIB) number  start  ( Sector)     End  (sector)   size       code   Name   1            2048             6143   2.0 MiB      EF02     2             6144         2103295   1024.0 mib   0700     3         2103296         41662463   18.9 GiB     8E00     4        41662464         41764863   10 GiB    8300   linux filesystem//write to disk partition table command  (?  for help):  wfinal checks complete .  about to write gpt data. this will overwrite existingpartitions!! do you want to proceed?  (y/n): yok; writing new guid  partition table  (GPT)  to /dev/sda. Warning: the kernel is still using the old partition table. The new table will be used at the next reboot. the operation has completed successfully.//Update disk partition table [[email protected] ~]#  Partprobe -s/dev/sda: gpt partitions 1 2 3 4[[email protected] ~] # lsblk /dev/sdaname            maj:min  RM  SIZE RO TYPE MOUNTPOINTsda                8:0    0   20G  0  disk ├─sda1            8:1    0     2M  0 part ├─sda2             8:2    0    1g  0 part /boot├─sda3             8:3    0  18.9g  0 part │ ├─centos-root 253:0    0    10g  0 lvm  /│ ├─centos-swap 253:1    0     1g  0 lvm  [swap]│ └─centos-home 253:2    0   7.9G  0 lvm  /home└─sda4             8:4    0   10g   0 part // Formatted as EXT4[[EMAIL PROTECTEd] ~]# mkfs.ext4 /dev/sda4mke2fs 1.42.9  (28-dec-2013) Filesystem label=OS  type: linuxblock size=1024  (log=0) fragment size=1024  (log=0) Stride=0 blocks,  Stripe width=0 blocks12824 inodes, 51200 blocks2560 blocks  (5%)  reserved for the super userFirst data block=1Maximum filesystem  Blocks=336855047 block groups8192 blocks per group, 8192 fragments per  group1832 inodes per groupSuperblock backups stored on blocks:          8193, 24577, 40961allocating group tables:  done                             Writing inode tables:  Done                             Creating journal  (4096 blocks):  donewriting  superblocks and filesystem accounting information: done//Mount to/data[[email  PROTECTED] ~]# MKDIR /DATA[[EMAIL PROTECTED] ~]# BLKID /DEV/SDA4/DEV/SDA4:  uuid= "d25d227a-4372-4ef1-950b-a14c7bb7e993"  type= "Ext4"  partlabel= "Linux filesystem"  partuuid= "f9e0bbae-55e5-4968-8157-c78a6229688e"  [[email protected] ~]# mount  Uuid= "d25d227a-4372-4ef1-950b-a14c7bb7e993"  /data[[email protected] ~]# df / datafilesystem     1k-blocks  used available use% mounted  on/dev/sda4          45478  1038      40856   3% /data 


2, display the ' Netstat-tan ' command results with ' LISTEN ' followed by 0, one or more blank characters end of the line;

0 x [[email protected] ~]# netstat -tan | grep -e  "LISTEN[^[:space:]]" 1 or more [[email protected] ~]# netstat -tan | grep -e  "LISTEN[[:space: ]]+ "tcp        0      0  192.168.122.1:53        0.0.0.0:*                LISTEN     tcp         0      0 0.0.0.0:22               0.0.0.0:*                LISTEN     tcp         0      0 127.0.0.1:631            0.0.0.0:*                LISTEN     tcp        0       0 127.0.0.1:25             0.0.0.0:*                listen     tcp6       0       0 :::22                    :::*                      LISTEN     tcp6        0      0 ::1:631                  :::*                      LISTEN     tcp6        0      0 ::1:25                   :::*                      listen

3, add user Nginx, Zabbix, Tomcat, Nologin and Hadoop users (nologin user's shell is/sbin/nologin), and then find the/etc/passwd file in the same user name and shell name of the row;

add user [[email protected] ~]# useradd nginx[[email protected] ~]# useradd zabbix[[email protected] ~]# useradd Tomcat[[emai L protected] ~]# useradd nologin-s/sbin/nologin[[email protected] ~]# useradd hadoop//find the row in the/etc/passwd file that has the same user name as its shell name [ [Email protected] ~]# grep "^ ([[: Alnum:]]\{1,\}):. *\l$"/etc/passwd


4, find a word in the/etc/rc.d/init.d/functions file (the middle of the word can be underlined) followed by a set of parentheses line;

[[email protected] ~]# grep-n "[[: Alpha:]] ()"/etc/rc.d/init.d/functions


5, use echo to output a path, and then egrep find its path base name; Further use Egrep to remove its directory name (note that the directory name, not the directory path);

[Email protected] ~]# echo "/home/hi" | GREP-E-O "[^/]+/?$] | Cut-d "/"-f1[[email protected] ~]$ echo "/home/hi" | Egrep-o "^/[[:alnum:]]+"


6. Find all files that are not root, bin or hadoop under the/usr directory;

[Email protected] hi]# find/etc root bin Hadoop [[email protected] ~]$ find/etc-not-user hi-a-not-user bin-a-not -user Hadoop

7, one day the system was invaded, hackers in your system to leave the Trojan file:

You now need to find all the files on the current system that are not owned by the master or group and have been visited in the last week;

In addition, it is necessary to find all files of more than 20k and type ordinary files in/etc directory;

[[email protected] hi]# find/etc-mtime-7[[email protected] ~]$ find/etc-size 20k-type F


8, create the directory/test/data, let a group of ordinary users have write permissions to it, and all the files created by the group is the directory belongs to the group; In addition, each user can only delete their own files.

[Email protected] hi]# mkdir-p/test/data [[email protected] hi]# chown root.tomcat/test/data[[email protected] hi]# US Ermod-g Tomcat Nginx[[email protected] hi]# usermod-g tomcat hadoop[[email protected] hi]# Chmod-g+ws,o+t/test/data


Linux OPS Practice case-December 20, 2015-December 31 (first time)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.