[root@localhost ~]# fdisk /dev/sda
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
All primary partitions are in use
Adding logical partition 6
First sector (141940736-419430399, default 141940736):
Using default value 141940736
Last sector, +sectors or +size{K,M,G} (141940736-419430399, default 419430399): +10G
Partition 6 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.
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.
(2)mkfs創(chuàng)建文件系統(tǒng):
在祥云等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站設(shè)計(jì)、網(wǎng)站制作 網(wǎng)站設(shè)計(jì)制作按需定制,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),成都全網(wǎng)營(yíng)銷,成都外貿(mào)網(wǎng)站建設(shè),祥云網(wǎng)站建設(shè)費(fèi)用合理。[root@localhost ~]# mkfs.ext4 -b 2048 -m 20 -L MYDATA /dev/sda6/
mke2fs 1.42.9 (28-Dec-2013)
Could not stat /dev/sda6/ --- Not a directory
[root@localhost ~]# mkfs.ext4 -b 2048 -m 20 -L MYDATA /dev/sda6
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
1048576 blocks (20.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
(3)掛載至/mydata目錄,要求掛載時(shí)禁止程序自動(dòng)運(yùn)行,且不更新文件的訪問(wèn)時(shí)間戳。并設(shè)置開(kāi)機(jī)自動(dòng)掛載
[root@localhost ~]# mkdir -p /mydata
[root@localhost ~]# vim /etc/fstab
/dev/sda6 /mydata ext4 defaults,noatime,noexec 0 0
[root@localhost ~]# mount -a
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 47G 5.2G 42G 12% /
devtmpfs 523M 0 523M 0% /dev
tmpfs 538M 0 538M 0% /dev/shm
tmpfs 538M 7.8M 530M 2% /run
tmpfs 538M 0 538M 0% /sys/fs/cgroup
/dev/sda1 497M 151M 346M 31% /boot
/dev/sda3 19G 39M 19G 1% /data
tmpfs 108M 4.0K 108M 1% /run/user/42
tmpfs 108M 32K 108M 1% /run/user/1000
/dev/sr0 8.1G 8.1G 0 100% /run/media/wl/CentOS 7 x86_64
tmpfs 108M 0 108M 0% /run/user/0
/dev/sda6 9.8G 13M 7.8G 1% /mydata
[root@localhost ~]# fdisk /dev/sda
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
All primary partitions are in use
Adding logical partition 7
First sector (162914304-419430399, default 162914304):
Using default value 162914304
Last sector, +sectors or +size{K,M,G} (162914304-419430399, default 419430399): +1G
Partition 7 of type Linux and of size 1 GiB is set
Command (m for help): t
Partition number (1-7, default 7): 7
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'
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@localhost ~]# mkswap /dev/sda7
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=ba42d9ae-41a0-4829-bd14-a32834cf6ec9
[root@localhost ~]# swapon /dev/sda7
[root@localhost ~]# vim /etc/fstab
/dev/sda7 swap swap defaults 0 0
#!/bin/bash
#判斷系統(tǒng)是否存在20個(gè)用戶
id_sum=$( cat /etc/passwd | wc -l )
[ ${id_sum} -lt 20 ] && echo "用戶個(gè)數(shù)小于20" && exit 2
id1=$(head -10 /etc/passwd | tail -1 | cut -d: -f3)
id2=$(head -20 /etc/passwd | tail -1 | cut -d: -f3)
idsum=$[${id1}+${id2}]
echo "Ths sum is $idsum"
[root@localhost scripts]# bash -x idsum2.sh
++ cat /etc/passwd
++ wc -l
+ id_sum=58
+ '[' 58 -lt 20 ']'
++ head -10 /etc/passwd
++ tail -1
++ cut -d: -f3
+ id1=11
++ head -20 /etc/passwd
++ tail -1
++ cut -d: -f3
+ id2=997
+ idsum=1008
+ echo 'Ths sum is 1008'
Ths sum is 1008
#!/bin/bash
hostName=$(hostname)
[ -z "${hostName}" -o "${hostName}" == "localhost.localdomain" -o "${hostName}" == "locahost" ] && hostnamectl set-hostname www.magedu.com || echo "主機(jī)名:${hostName},不要修改"
[root@localhost scripts]# bash -x hostname.sh
++ hostname
+ hostName=localhost.localdomain
+ '[' -z localhost.localdomain -o localhost.localdomain == localhost.localdomain -o localhost.localdomain == locahost ']'
+ hostnamectl set-hostname www.magedu.com
#!/bin/bash
#腳本判斷參數(shù)用戶ID奇偶類型
[ $# -lt 1 ] && echo "At least a username " && exit 1
! id $1 && echo "No such user" && exit 2
userid=$(id -u $1)
useri=$[${userid}%2]
if [ ${useri} -eq 0 ];then
echo "$1 ID 是偶數(shù)"
else
echo "$1 ID 是奇數(shù)"
fi
root@localhost scripts]# bash -xv id.sh user3
#!/bin/bash
#腳本判斷參數(shù)用戶ID奇偶類型
[ $# -lt 1 ] && echo "At least a username " && exit 1
+ '[' 1 -lt 1 ']'
! id $1 && echo "No such user" && exit 2
+ id user3
uid=1003(user3) gid=1003(user3) groups=1003(user3)
userid=$(id -u $1)
++ id -u user3
+ userid=1003
useri=$[${userid}%2]
+ useri=1
if [ ${useri} -eq 0 ];then
echo "$1 ID 是偶數(shù)"
else
echo "$1 ID 是奇數(shù)"
fi
+ '[' 1 -eq 0 ']'
+ echo 'user3 ID 是奇數(shù)'
user3 ID 是奇數(shù)
(2)LVM 基本術(shù)語(yǔ):
(a)物理存儲(chǔ)介質(zhì)(PhysicalStorageMedia):
指系統(tǒng)上最底層的物理存儲(chǔ)設(shè)備:磁盤(pán),例如:/dev/sda、/dev/sdb等
(b)物理卷(Physical Volume, PV):
指磁盤(pán)、磁盤(pán)分區(qū)或RAID設(shè)備,使用LVM前需要先將之制作成便于識(shí)別的物理卷PV
(c)卷組(Volume Group, VG):
卷組由一個(gè)或多個(gè)物理卷PV組成,在卷組之上可創(chuàng)建一個(gè)或多個(gè)邏輯卷LV。卷組VG類似于非LVM系統(tǒng)的 物理磁盤(pán)
(d)邏輯卷(Logical Volume, LV):
建立在卷組VG之上,相當(dāng)于邏輯分區(qū),可在邏輯卷LV上進(jìn)行一系列操作(例如:格式化、掛載等)。 邏輯卷LV類似于非LVM系統(tǒng)的磁盤(pán)分區(qū)
(d)物理擴(kuò)展塊(Physical Extent, PE):
當(dāng)物理卷PV加入某一卷組VG后即被劃分為基本單元PE,PE是LVM尋址的最小單元。PE的大小是可配置的,默認(rèn)為4M。
(e)邏輯擴(kuò)展塊(Logical Extent, LE):
卷組VG將PE劃分給邏輯卷LV,在邏輯卷LV中的PE稱為L(zhǎng)E。在同一卷組VG中,PE和LE大小相同,且相互對(duì)應(yīng)。LE也是LVM的最小尋址單位。
(3)LVM基本操作:
(a)pv管理工具:
pvs:簡(jiǎn)要pv信息顯示
pvdisplay:顯示pv的詳細(xì)信息
pvcreate /dev/DEVICE: 創(chuàng)建pv
(b)vg管理工具:
vgs
vgdisplay
vgcreate [-s #[kKmMgGtTpPeE]] VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]
vgextend VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]
vgreduce VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]
先做pvmove
vgremove
(c)lv管理工具:
lvs
lvdisplay
lvcreate -L #[mMgGtT] -n NAME VolumeGroup
vremove /dev/VG_NAME/LV_NAME
(d)擴(kuò)展邏輯卷:
# lvextend -L [+]#[mMgGtT] /dev/VG_NAME/LV_NAME
# resize2fs /dev/VG_NAME/LV_NAME(e)縮減邏輯卷:
# umount /dev/VG_NAME/LV_NAME# e2fsck -f /dev/VG_NAME/LV_NAME
# resize2fs /dev/VG_NAME/LV_NAME #[mMgGtT]
# lvreduce -L [-]#[mMgGtT] /dev/VG_NAME/LV_NAME
# mount
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。