網絡倉庫源的搭建就是在本地倉庫搭建的步驟上多了一個安裝http的過程,而後把對應的目錄掛載到http 的工做目錄下就能夠,具體實現請參考本人博客http://www.javashuo.com/article/p-zkqqiusx-bk.htmlreact
搭建好倉庫就能夠建立相應的配置文件,其客戶端配置文件格式以下(/etc/yum.repo.d/xxx.repo)linux
[my_base]
name=this is test repo
baseurl=file:///rpm/centos/$releasever/os/$basearch
gpgcheck=0
說明:其中第一行中括號裏的內容能夠任意填寫,就至關於倉庫的名字,name表示倉庫的說明信息,baseurl是倉庫的路徑,上面就是一個本地倉庫的地址,若是是基於網絡http的倉庫,就要寫http://倉庫服務器地址/repodata文件夾的父目錄,gpgcheck=0表示不開啓gpg驗證。apache
在客戶端配置好repo文件後,能夠查看咱們搭建的倉庫信息centos
yum clean all ##清除緩存
yum repolist ##列出倉庫信息
2、編譯安裝http2.4,實現能夠正常訪問,並將編譯步驟和結果提交。瀏覽器
編譯安裝,首先安裝好編譯環境包,好比:「development tools」,而後下載好源碼包解壓,而後進入到解壓後的目錄,而後查看README或者INSTALL說明文檔,而後在解壓後的目錄下運行./configure --help查看編譯選項說明,而後根據本身的需求定製編譯選項,檢查當前系統是否知足指定編譯參數的環境,好比編譯依賴的庫是否存在呀,編譯依賴的包是否存在呀等等,而後make && make install 如編譯安裝http2.4步驟以下:緩存
一、yum安裝 「development tools」 包組bash
[root@localhost ~]# yum groupinstall "development tools" -y
二、建立一個系統用戶用於httpd的啓動服務器
[root@localhost ~]useradd -r -u 80 -d /data/www/ -s /sbin/nologin httpd
[root@localhost ~]# getent passwd httpd
httpd:x:80:80::/data/www/:/sbin/nologin
三、下載源碼包
[root@localhost ~]# wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.41.tar.gz
--2019-11-05 20:11:40-- http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.41.tar.gz
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, 2402:f000:1:408:8100::1
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9267917 (8.8M) [application/octet-stream]
Saving to: ‘httpd-2.4.41.tar.gz’
100%[======================================>] 9,267,917 2.82MB/s in 3.1s
2019-11-05 20:11:43 (2.82 MB/s) - ‘httpd-2.4.41.tar.gz’ saved [9267917/9267917]
[root@localhost ~]# ll
total 9052
-rw-r--r--. 1 root root 9267917 Aug 13 07:37 httpd-2.4.41.tar.gz
四、解壓源碼包
[root@localhost ~]# tar xf httpd-2.4.41.tar.gz
[root@localhost ~]# ls
httpd-2.4.41 httpd-2.4.41.tar.gz
五、進入到解壓後的目錄
[root@localhost ~]# cd httpd-2.4.41/
六、查看README文件
Installation
------------
Please see the file called INSTALL. Platform specific notes can be
found in README.platforms.
說明:它上面說安裝就去看INSTALL文件
七、查看INSTALL文件
Quick Start - Unix
------------------
For complete installation documentation, see [ht]docs/manual/install.html or
http://httpd.apache.org/docs/2.4/install.html
$ ./configure --prefix=PREFIX
$ make
$ make install
$ PREFIX/bin/apachectl start
說明:INSTALL文件說快速安裝就用以上命令就能夠快速運行服務,固然快速安裝,咱們要指定安裝軟件的位置,不少選項都是默認的值。
For a short impression of what possibilities you have, here is a
typical example which configures Apache for the installation tree
/sw/pkg/apache with a particular compiler and flags plus the two
additional modules mod_rewrite and mod_speling for later loading
through the DSO mechanism:
$ CC="pgcc" CFLAGS="-O2" \
./configure --prefix=/sw/pkg/apache \
--enable-rewrite=shared \
--enable-speling=shared
The easiest way to find all of the configuration flags for Apache 2.4
is to run ./configure --help.
說明:INSTALL還告訴咱們,若是咱們須要編譯安裝額外的模塊,咱們用像它給咱們舉的例子這樣用選項來指定。固然要查看更多選項信息,咱們能夠運行./configure --help來查看
八、查看./configure 選項幫助
[root@localhost httpd-2.4.41]# ./configure --help
`configure' configures this package to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
-q, --quiet, --silent do not print `checking ...' messages
--cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for `--cache-file=config.cache'
-n, --no-create do not create output files
--srcdir=DIR find the sources in DIR [configure dir or `..']
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local/apache2]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
By default, `make install' will install all the files in
`/usr/local/apache2/bin', `/usr/local/apache2/lib' etc. You can specify
an installation prefix other than `/usr/local/apache2' using `--prefix',
for instance `--prefix=$HOME'.
For better control, use the options below.
Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system admin executables [EPREFIX/sbin]
--libexecdir=DIR program executables [EPREFIX/libexec]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
--datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
--datadir=DIR read-only architecture-independent data [DATAROOTDIR]
--infodir=DIR info documentation [DATAROOTDIR/info]
--localedir=DIR locale-dependent data [DATAROOTDIR/locale]
--mandir=DIR man documentation [DATAROOTDIR/man]
--docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE]
--htmldir=DIR html documentation [DOCDIR]
--dvidir=DIR dvi documentation [DOCDIR]
--pdfdir=DIR pdf documentation [DOCDIR]
--psdir=DIR ps documentation [DOCDIR]
...省略部分顯示
說明:咱們能夠看到.configure 的編譯選項有不少,每一個選項都表明着不一樣的功能和含義。
九、指定本身須要的功能選項,運行./configure +功能選項 檢查系統都有指定功能說依賴的庫和包。
[root@localhost httpd-2.4.41]# ./configure --prefix=/application/httpd_2.4 --sysconfdir=/etc/httpd24 --enable-ssl --disable-status
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... no
configure: error: APR not found. Please read the documentation.
[root@localhost httpd-2.4.41]#
說明:咱們指定httpd 安裝到/application/httpd_2.4目錄裏 ,系統配置文件存放在/etc/httpd24目錄下 ,開啓ssl功能,關閉進程/線程監控。configure抱錯,找不到APR,請閱讀文檔
十、安裝依賴包
yum install apr-devel apr-util-devel pcre-devel openssl-devel
說明:安裝依賴能夠在第一步就能夠作。在咱們熟悉軟件的狀況下能夠提早安裝好它說依賴的包。
十一、安裝完依賴包後,咱們在來用./configure +咱們指定的選項 來檢查咱們當前系統是否符合編譯選項功能
config.status: creating build/config_vars.sh
config.status: creating include/ap_config_auto.h
config.status: executing default commands
configure: summary of build options:
Server Version: 2.4.41
Install prefix: /application/httpd_2.4
C compiler: gcc -std=gnu99
CFLAGS: -pthread
CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE
LDFLAGS:
LIBS:
C preprocessor: gcc -E
[root@localhost httpd-2.4.41]#
說明:安裝依賴後,咱們再次運行./configure +咱們指定的編譯選項,沒有發現有ERROR的字樣,說明咱們指定的編譯選項在當前系統環境是能夠編譯的
十二、編譯
usr/lib64/apr-1/build/libtool --silent --mode=link gcc -std=gnu99 -pthread -o mod_rewrite.la -rpath /application/httpd_2.4/modules -module -avoid-version mod_rewrite.lo
make[4]: 離開目錄「/root/httpd-2.4.41/modules/mappers」
make[3]: 離開目錄「/root/httpd-2.4.41/modules/mappers」
make[2]: 離開目錄「/root/httpd-2.4.41/modules」
make[2]: 進入目錄「/root/httpd-2.4.41/support」
make[2]: 離開目錄「/root/httpd-2.4.41/support」
make[1]: 離開目錄「/root/httpd-2.4.41」
[root@localhost httpd-2.4.41]#
說明:在咱們執行make命令後,會出現一大片編譯顯示的信息,最後若是沒有出現ERROR,說明咱們的編譯時沒有問題的
1三、安裝
Installing configuration files
mkdir /etc/httpd24
mkdir /etc/httpd24/extra
mkdir /etc/httpd24/original
mkdir /etc/httpd24/original/extra
Installing HTML documents
mkdir /application/httpd_2.4/htdocs
Installing error documents
mkdir /application/httpd_2.4/error
Installing icons
mkdir /application/httpd_2.4/icons
mkdir /application/httpd_2.4/logs
Installing CGIs
mkdir /application/httpd_2.4/cgi-bin
Installing header files
mkdir /application/httpd_2.4/include
Installing build system files
mkdir /application/httpd_2.4/build
Installing man pages and online manual
mkdir /application/httpd_2.4/man
mkdir /application/httpd_2.4/man/man1
mkdir /application/httpd_2.4/man/man8
mkdir /application/httpd_2.4/manual
make[1]: 離開目錄「/root/httpd-2.4.41」
[root@localhost httpd-2.4.41]#
說明:咱們經過執行make install 能夠了解到,安裝就是把咱們編譯好的庫和二進制文件複製到相應的目錄下的過程
1四、添加PATH環境變量,並加載環境變量
[root@localhost httpd-2.4.41]# ll /application/httpd_2.4/bin/
總用量 1176
-rwxr-xr-x 1 root root 73808 11月 6 05:20 ab
-rwxr-xr-x 1 root 40 3449 11月 6 05:13 apachectl
-rwxr-xr-x 1 root 40 23519 11月 6 05:13 apxs
-rwxr-xr-x 1 root root 8736 11月 6 05:20 checkgid
-rwxr-xr-x 1 root 40 8925 11月 6 05:13 dbmmanage
-rw-r--r-- 1 root 40 1081 11月 6 05:13 envvars
-rw-r--r-- 1 root 40 1081 11月 6 05:13 envvars-std
-rwxr-xr-x 1 root root 13848 11月 6 05:20 fcgistarter
-rwxr-xr-x 1 root root 40984 11月 6 05:20 htcacheclean
-rwxr-xr-x 1 root root 28096 11月 6 05:20 htdbm
-rwxr-xr-x 1 root root 18208 11月 6 05:20 htdigest
-rwxr-xr-x 1 root root 23456 11月 6 05:20 htpasswd
-rwxr-xr-x 1 root root 867296 11月 6 05:20 httpd
-rwxr-xr-x 1 root root 13800 11月 6 05:20 httxt2dbm
-rwxr-xr-x 1 root root 14440 11月 6 05:20 logresolve
-rwxr-xr-x 1 root root 27432 11月 6 05:20 rotatelogs
[root@localhost httpd-2.4.41]# echo 'export PATH=/application/httpd_2.4/bin/:$PATH' >/etc/profile.d/http24.sh
[root@localhost httpd-2.4.41]# . /etc/profile.d/http24.sh
[root@localhost httpd-2.4.41]# echo $PATH
/application/httpd_2.4/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost httpd-2.4.41]#
1五、啓動服務(啓動服務前,把/etc/httpd24/httpd.conf裏的User 更改成咱們以前創建的用戶httpd)
[root@localhost httpd-2.4.41]# apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using ::1. Set the 'ServerName' directive globally to suppress this message
[root@localhost httpd-2.4.41]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 80 :::3306 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 32 :::21 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
[root@localhost httpd-2.4.41]# ps axu |grep httpd
root 41401 0.0 0.1 72852 2956 ? Ss 05:28 0:00 /application/httpd_2.4/bin/httpd -k start
httpd 41583 0.0 0.3 427352 6256 ? Sl 05:39 0:00 /application/httpd_2.4/bin/httpd -k start
httpd 41584 0.0 0.3 361816 6264 ? Sl 05:39 0:00 /application/httpd_2.4/bin/httpd -k start
httpd 41585 0.0 0.3 361816 6264 ? Sl 05:39 0:00 /application/httpd_2.4/bin/httpd -k start
root 41668 0.0 0.0 112724 984 pts/0 R+ 05:40 0:00 grep --color=auto httpd
說明:能夠看到80端口已經處於監聽狀態,httpd進程也相應起來了,何況是以咱們指定的系統用戶運行的。
1六、用瀏覽器訪問咱們的服務器
3、建立一個2G的文件系統,塊大小爲2048byte,預留1%可用空間,文件系統 ext4,卷標爲test,要求此分區開機後自動掛載至/test目錄,且默認有acl掛載選項
一、分區
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 200M 0 part /boot
├─sda2 8:2 0 3G 0 part [SWAP]
└─sda3 8:3 0 16.8G 0 part /
sdb 8:16 0 40G 0 disk
sr0 11:0 1 1024M 0 rom
[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7a888819.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4):
Value out of range.
Partition number (1-4): 1
First cylinder (1-5221, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-5221, default 5221): +2G
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7a888819
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
二、建立文件系統
[root@localhost ~]# mkfs.ext4 -b 2048 -m 1 -L "test" /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=test
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
131560 inodes, 1052240 blocks
10522 blocks (1.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=538968064
65 block groups
16384 blocks per group, 16384 fragments per group
2024 inodes per group
Superblock backups stored on blocks:
16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
說明:centos6本身手動建立的文件系統默認沒有ACL功能,須要用tune2fs -o acl /dev/sdb1來添加默認掛載選項具備acl功能
三、添加默認掛載選項具備acl功能
[root@localhost ~]# tune2fs -l /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name: test
Last mounted on: <not available>
Filesystem UUID: be76ff36-e949-4434-9925-af60ce4e155a
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: (none)
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 131560
Block count: 1052240
Reserved block count: 10522
Free blocks: 998252
Free inodes: 131549
First block: 0
Block size: 2048
Fragment size: 2048
Reserved GDT blocks: 512
Blocks per group: 16384
Fragments per group: 16384
Inodes per group: 2024
Inode blocks per group: 253
Flex block group size: 16
Filesystem created: Tue Oct 22 02:45:40 2019
Last mount time: n/a
Last write time: Tue Oct 22 02:45:40 2019
Mount count: 0
Maximum mount count: 39
Last checked: Tue Oct 22 02:45:40 2019
Check interval: 15552000 (6 months)
Next check after: Sun Apr 19 02:45:40 2020
Lifetime writes: 97 MB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 28
Desired extra isize: 28
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: 2c750580-3dd9-4af4-a1e9-581761cd9559
Journal backup: inode blocks
[root@localhost ~]# tune2fs -o acl /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
[root@localhost ~]# tune2fs -l /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name: test
Last mounted on: <not available>
Filesystem UUID: be76ff36-e949-4434-9925-af60ce4e155a
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 131560
Block count: 1052240
Reserved block count: 10522
Free blocks: 998252
Free inodes: 131549
First block: 0
Block size: 2048
Fragment size: 2048
Reserved GDT blocks: 512
Blocks per group: 16384
Fragments per group: 16384
Inodes per group: 2024
Inode blocks per group: 253
Flex block group size: 16
Filesystem created: Tue Oct 22 02:45:40 2019
Last mount time: n/a
Last write time: Tue Oct 22 02:46:53 2019
Mount count: 0
Maximum mount count: 39
Last checked: Tue Oct 22 02:45:40 2019
Check interval: 15552000 (6 months)
Next check after: Sun Apr 19 02:45:40 2020
Lifetime writes: 97 MB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 28
Desired extra isize: 28
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: 2c750580-3dd9-4af4-a1e9-581761cd9559
Journal backup: inode blocks
[root@localhost ~]#
說明:能夠看到Default mount options: acl 表示:具備了acl掛載選項,塊大小爲2048,Block count: 1052240和Reserved block count: 10522的比例是100:1,Filesystem volume name: test 表示卷標名爲test
四、查看/dev/sdb1的卷標
[root@localhost ~]# e2label /dev/sdb1
test
五、設置開機掛載至/test目錄
[root@localhost ~]# mkdir /test
[root@localhost ~]# echo '/dev/sdb1 /test ext4 defaults,acl 0 0 ' >> /etc/fstab
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 17187708 1915396 14392544 12% /
tmpfs 953456 0 953456 0% /dev/shm
/dev/sda1 194241 40472 143529 22% /boot
[root@localhost ~]# mount -a
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 17187708 1915396 14392544 12% /
tmpfs 953456 0 953456 0% /dev/shm
/dev/sda1 194241 40472 143529 22% /boot
/dev/sdb1 2005740 9236 1975460 1% /test
[root@localhost ~]# mount
/dev/sda3 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sdb1 on /test type ext4 (rw,acl)
[root@localhost ~]#
說明:能夠看到/dev/sdb1的文件系統類型是ext4,而且以讀寫,acl掛載至/test
4、建立一個至少有兩個PV組成的大小爲20G的名爲testvg的VG;要求PE大小 爲16MB, 然後在卷組中建立大小爲5G的邏輯卷testlv;掛載至/users目錄
一、建立分區並分別指定大小爲10G,並把分區類型改成Linux LVM類型
[root@localhost ~]# fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7a888819
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 83 Linux
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (263-5221, default 263):
Using default value 263
Last cylinder, +cylinders or +size{K,M,G} (263-5221, default 5221): +10G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (1569-5221, default 1569):
Using default value 1569
Last cylinder, +cylinders or +size{K,M,G} (1569-5221, default 5221): +10G
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7a888819
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 83 Linux
/dev/sdb2 263 1568 10490445 83 Linux
/dev/sdb3 1569 2874 10490445 83 Linux
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): L
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx
5 Extended 42 SFS 86 NTFS volume set da Non-FS data
6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt
9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access
a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT
1e Hidden W95 FAT1
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7a888819
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 83 Linux
/dev/sdb2 263 1568 10490445 8e Linux LVM
/dev/sdb3 1569 2874 10490445 8e Linux LVM
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 ~]#
說明:能夠看到/dev/sdb1和/dev/sdb2的分區類型爲Linux LVM
二、建立pv
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 200M 0 part /boot
├─sda2 8:2 0 3G 0 part [SWAP]
└─sda3 8:3 0 16.8G 0 part /
sdb 8:16 0 40G 0 disk
└─sdb1 8:17 0 2G 0 part /test
sr0 11:0 1 1024M 0 rom
[root@localhost ~]# partx -a /dev/sdb
BLKPG: Device or resource busy
error adding partition 1
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 200M 0 part /boot
├─sda2 8:2 0 3G 0 part [SWAP]
└─sda3 8:3 0 16.8G 0 part /
sdb 8:16 0 40G 0 disk
├─sdb1 8:17 0 2G 0 part /test
├─sdb2 8:18 0 10G 0 part
└─sdb3 8:19 0 10G 0 part
sr0 11:0 1 1024M 0 rom
[root@localhost ~]# pvcreate /dev/sdb2 /dev/sdb3
Physical volume "/dev/sdb2" successfully created
Physical volume "/dev/sdb3" successfully created
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb2 lvm2 --- 10.00g 10.00g
/dev/sdb3 lvm2 --- 10.00g 10.00g
[root@localhost ~]# pvdisplay
"/dev/sdb2" is a new physical volume of "10.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb2
VG Name
PV Size 10.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID Yxsoub-DQJt-5g3T-uSca-839U-vmVV-A2t8Gl
"/dev/sdb3" is a new physical volume of "10.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb3
VG Name
PV Size 10.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID ChnbDg-DaSx-BhKz-a427-qEjc-VneO-A6V2jl
[root@localhost ~]#
說明:在咱們分區後,用lsblk可能會出現分區表不一樣步的現象,咱們能夠用partx -a /dev/sdb命令來通知內核同步,這樣咱們就能夠看到咱們以前的分區,而後用pvcreate命令 來建立pv,用pvs或者pvdisplay來查看咱們建立的物理卷的信息
三、建立vg(卷組),並設置pe大小爲16m
root@localhost ~]# vgcreate "testvg" -s 16m /dev/sdb{2,3}
Volume group "testvg" successfully created
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
testvg 2 0 0 wz--n- 20.00g 20.00g
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name testvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 20.00 GiB
PE Size 16.00 MiB
Total PE 1280
Alloc PE / Size 0 / 0
Free PE / Size 1280 / 20.00 GiB
VG UUID XgjjlR-jg4D-iOpA-W65s-S4WF-Qq8r-UaBjPW
說明:能夠看到咱們已經很順利的建立了testvg,大小爲20G,pe的大小是16m,pe是邏輯卷中最小分配單位,相似磁盤的block大小,只有建立了VG 才能夠看到pe的大小,若不指定默認爲4m
四、建立大小爲5G的邏輯卷testlv
[root@localhost ~]# lvs
[root@localhost ~]# lvdisplay
[root@localhost ~]# lvcreate -n "testlv" -L 5G testvg
Logical volume "testlv" created.
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testlv testvg -wi-a----- 5.00g
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/testvg/testlv
LV Name testlv
VG Name testvg
LV UUID RPUlTS-fVfA-etlO-Rzqz-KzMD-6xS1-dszf8F
LV Write Access read/write
LV Creation host, time localhost, 2019-10-22 03:55:08 +0800
LV Status available
# open 0
LV Size 5.00 GiB
Current LE 320
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
[root@localhost ~]#
說明:lvcreate -n 表示指定要建立的邏輯卷名稱,-L 表示指定邏輯卷的大小,固然還有-l 指定邏輯卷大小的方式,小l指定的是pe的個數。最後指定在那個卷組裏分配,建立好的lvs 它的真正路徑在/dev/dm-0,由於dm-0沒有實質的意義,就是咱們看到名字不知道這個邏輯卷究竟是那個卷組裏建立的,因此係統就給咱們作了一個軟鏈接,/dev/testvg/testlv,咱們一看這個名字這個邏輯卷是從testvg裏分配的。
五、在建立好的lvs上建立文件系統
root@localhost ~]# mkfs.ext4 /dev/testvg/testlv
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
六、掛載建立好文件系統的lvs
[root@localhost ~]# mount /dev/testvg/testlv /users/
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 ext4 17G 1.9G 14G 12% /
tmpfs tmpfs 932M 0 932M 0% /dev/shm
/dev/sda1 ext4 190M 40M 141M 22% /boot
/dev/sdb1 ext4 2.0G 9.1M 1.9G 1% /test
/dev/mapper/testvg-testlv
ext4 4.8G 10M 4.6G 1% /users
[root@localhost ~]#
說明:若要開機自動掛載須要在/etc/fstab文件中加上 /dev/testvg/testlv /users ext4 defaults 0 0 這條記錄就能夠實現開機自動掛載。