Lvm
lsblk命令 用于列出所有可用块设备的信息,而且还能显示他们之间的依赖关系
[root@lvmserver ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 49G 0 part
├─centos-root 253:0 0 45.1G 0 lvm /
└─centos-swap 253:1 0 3.9G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
sr0 11:0 1 4.5G 0 rom
1.分区。使用fdisk命令对sdb进行分区操作,分出两个大小为5G的分区,操作如下:
d :删除分区
l :显示分区类型
n :新建分区
p :显示分区信息
q :退出不保存
t :设置分区号
w :保存修改
[root@lvmserver ~]# 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 0x2e899c68.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +5G
Partition 1 of type Linux and of size 5 GiB is set
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p):
Using default response p
Partition number (2-4, default 2):
First sector (10487808-41943039, default 10487808):
Using default value 10487808
Last sector, +sectors or +size{K,M,G} (10487808-41943039, default 41943039): +5G
Partition 2 of type Linux and of size 5 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: 0x2e899c68
Device Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 83 Linux
/dev/sdb2 10487808 20973567 5242880 83 Linux
Command (m for help): t
Partition number (1,2, default 2): 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
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: 0x2e899c68
Device Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 8e Linux LVM
/dev/sdb2 10487808 20973567 5242880 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@lvmserver ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 49G 0 part
├─centos-root 253:0 0 45.1G 0 lvm /
└─centos-swap 253:1 0 3.9G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 5G 0 part
└─sdb2 8:18 0 5G 0 part
sr0 11:0 1 4.5G 0 rom
2.对这两个分区进行创建物理卷操作
pvcreate命令 用于将物理硬盘分区初始化为物理卷,以便LVM使用。
[root@lvmserver ~]# pvcreate /dev/sdb1 /dev/sdb2
Physical volume "/dev/sdb1" successfully created.
Physical volume "/dev/sdb2" successfully created.
创建完毕后,查看物理卷的简单信息和详细信息
[root@lvmserver ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <49.00g 4.00m
/dev/sdb1 lvm2 --- 5.00g 5.00g
/dev/sdb2 lvm2 --- 5.00g 5.00g
[root@lvmserver ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <49.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 12543
Free PE 1
Allocated PE 12542
PV UUID zQtMA1-WG37-DPa8-1sEf-Ydue-MNRl-fCdAGG
"/dev/sdb1" is a new physical volume of "5.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 5.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID I76KI6-i7YN-8lpO-Q0YE-qQ5L-JGqp-vE1s1F
"/dev/sdb2" is a new physical volume of "5.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb2
VG Name
PV Size 5.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID Yg51v0-AMMv-nNv6-hPZg-1Dvd-JQOf-Fqswmp
3.创建卷组
使用刚才创建好的两个物理卷,创建名为myvg的卷组
[root@lvmserver ~]# vgcreate myvg /dev/sdb[1-2]
Volume group "myvg" successfully created
查看卷组信息
[root@lvmserver ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <49.00g 4.00m
myvg 2 0 0 wz--n- 9.99g 9.99g
[root@lvmserver ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <49.00 GiB
PE Size 4.00 MiB
Total PE 12543
Alloc PE / Size 12542 / 48.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID qk2Q1q-IJfV-nWb2-Hp6C-9eaT-7Vfc-ZZeogU
--- Volume group ---
VG Name myvg
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 9.99 GiB
PE Size 4.00 MiB
Total PE 2558
Alloc PE / Size 0 / 0
Free PE / Size 2558 / 9.99 GiB
VG UUID dAX8Ur-Zoe8-eLjM-YHho-Dlvf-bBf1-h56TuH
删除卷组,重新创建卷组,并指定大小为16m
[root@lvmserver ~]# vgremove myvg
Volume group "myvg" successfully removed
[root@lvmserver ~]# vgcreate -s 16m myvg /dev/sdb[1-2]
Volume group "myvg" successfully created
[root@lvmserver ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <49.00 GiB
PE Size 4.00 MiB
Total PE 12543
Alloc PE / Size 12542 / 48.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID qk2Q1q-IJfV-nWb2-Hp6C-9eaT-7Vfc-ZZeogU
--- Volume group ---
VG Name myvg
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 <9.97 GiB
PE Size 16.00 MiB
Total PE 638
Alloc PE / Size 0 / 0
Free PE / Size 638 / <9.97 GiB
VG UUID frolnp-NJHS-0lAK-3VX4-C5QX-fsas-W33xdR
向卷组myvg中添加一个物理卷,在/dev/sdb上再分一个/dev/sdb3分区把该分区添加到卷组myvg中
[root@lvmserver ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 49G 0 part
├─centos-root 253:0 0 45.1G 0 lvm /
└─centos-swap 253:1 0 3.9G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 5G 0 part
├─sdb2 8:18 0 5G 0 part
└─sdb3 8:19 0 5G 0 part
sr0 11:0 1 4.5G 0 rom
将创建的/dev/sdb3添加到myvg卷组中,在添加的过程中,会自动将/dev/sdb3创建为物理卷
[root@lvmserver ~]# vgextend myvg /dev/sdb3
Physical volume "/dev/sdb3" successfully created.
Volume group "myvg" successfully extended
[root@lvmserver ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <49.00g 4.00m
myvg 3 0 0 wz--n- 14.95g 14.95g
[root@lvmserver ~]# vgdisplay myvg
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 3
Act PV 3
VG Size 14.95 GiB
PE Size 16.00 MiB
Total PE 957
Alloc PE / Size 0 / 0
Free PE / Size 957 / 14.95 GiB
VG UUID frolnp-NJHS-0lAK-3VX4-C5QX-fsas-W33xdR
4.创建逻辑卷
创建逻辑卷,名称为mylv,大小为5GB
[root@lvmserver ~]# lvcreate -L +5G -n mylv myvg
Logical volume "mylv" created.
[root@lvmserver ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- <45.12g
swap centos -wi-ao---- <3.88g
mylv myvg -wi-a----- 5.00g
扫描上一步创建的lv逻辑卷
[root@lvmserver ~]# lvscan
ACTIVE '/dev/centos/swap' [<3.88 GiB] inherit
ACTIVE '/dev/centos/root' [<45.12 GiB] inherit
ACTIVE '/dev/myvg/mylv' [5.00 GiB] inherit
使用ext4文件系统格式化逻辑卷myvg
[root@lvmserver ~]# mkfs.ext4 /dev/mapper/myvg-mylv
mke2fs 1.42.9 (28-Dec-2013)
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
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
把逻辑卷mylv挂载到/mnt下并验证
[root@lvmserver ~]# mount /dev/mapper/myvg-mylv /mnt
[root@lvmserver ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 12M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 46G 1.3G 44G 3% /
/dev/sda1 1014M 150M 865M 15% /boot
tmpfs 378M 0 378M 0% /run/user/0
/dev/mapper/myvg-mylv 4.8G 20M 4.6G 1% /mnt
对创建的LVM卷扩容至1GB
[root@lvmserver ~]# lvextend -L +1G /dev/mapper/myvg-mylv
Size of logical volume myvg/mylv changed from 5.00 GiB (320 extents) to 6.00 GiB (384 extents).
Logical volume myvg/mylv successfully resized.
[root@lvmserver ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- <45.12g
swap centos -wi-ao---- <3.88g
mylv myvg -wi-ao---- 6.00g
[root@lvmserver ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 12M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 46G 1.3G 44G 3% /
/dev/sda1 1014M 150M 865M 15% /boot
tmpfs 378M 0 378M 0% /run/user/0
/dev/mapper/myvg-mylv 4.8G 20M 4.6G 1% /mnt
可以看到LVM卷的大小变了,但是挂载信息中没有发生变化,需要对文件系统进行扩容
[root@lvmserver ~]# resize2fs /dev/mapper/myvg-mylv
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/myvg-mylv is mounted on /mnt; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mapper/myvg-mylv is now 1572864 blocks long.
[root@lvmserver ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 12M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 46G 1.3G 44G 3% /
/dev/sda1 1014M 150M 865M 15% /boot
tmpfs 378M 0 378M 0% /run/user/0
/dev/mapper/myvg-mylv 5.8G 20M 5.5G 1% /mnt
扩容逻辑卷成功
LNMP+WorePress
1.安装lnmp环境
[root@server ~]# yum install httpd mariadb-server php php-mysql -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
centos | 3.6 kB 00:00:00
Resolving Dependencies
[root@server ~]# systemctl start httpd mariadb
初始化数据库,并创建wordpress数据库
[root@server ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@server ~]# mysql -uroot -p000000
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.65-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> exit
Bye
导入wordpress安装包,安装unzip命令,解压安装包
[root@server ~]# ls
anaconda-ks.cfg wordpress-4.7.3-zh_CN.zip
[root@server ~]# yum install unzip -y
[root@server ~]# unzip wordpress-4.7.3-zh_CN.zip
[root@server ~]# ls
anaconda-ks.cfg wordpress wordpress-4.7.3-zh_CN.zip
更改权限
[root@server ~]# cd wordpress
[root@server wordpress]# cp -avf * /var/www/html/
[root@server wordpress]# cd /var/www/html/
[root@server html]# chmod -R 777 *
将文件重命名,并修改
[root@server html]# mv wp-config-sample.php wp-config.php
[root@server html]# vi wp-config.php
<?php
/**
* WordPress基础配置文件。
*
* 这个文件被安装程序用于自动生成wp-config.php配置文件,
* 您可以不使用网站,您需要手动复制这个文件,
* 并重命名为“wp-config.php”,然后填入相关信息。
*
* 本文件包含以下配置选项:
*
* * MySQL设置
* * 密钥
* * 数据库表名前缀
* * ABSPATH
*
* @link https://codex.wordpress.org/zh-cn:%E7%BC%96%E8%BE%91_wp-config.php
*
* @package WordPress
*/
// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define('DB_NAME', 'wordpress');
/** MySQL数据库用户名 */
define('DB_USER', 'root');
/** MySQL数据库密码 */
define('DB_PASSWORD', '000000');
在浏览器输入IP,进入安装页面
安装完成!