月度归档:2018年03月

MariaDB创建用户、数据库

目标:

用户名:sampleuser
数据库名:sampledb
密码:samplepass

命令:

# Step1: Install MariaDB

yum install mariadb
systemctl start mariadb
systemctl enable mariadb


# Step2: Initialize MariaDB

mysql_secure_installation
Set root password? [Y/n] y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y


# Step3: Create user and database

mysql -u root -p
MariaDB [(none)]>CREATE DATABASE sampledb;
MariaDB [(none)]>CREATE USER 'sampleuser'@'%' IDENTIFIED BY 'samplepass';
MariaDB [(none)]>GRANT ALL on sampledb.* to 'sampleuser'@'%';
MariaDB [(none)]>FLUSH PRIVILEGES;
MariaDB [(none)]>exit

 

编译安装python3

从官网下载源码包

wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz

解压

tar xvzf Python-3.6.4.tgz

准备编译需要的依赖

yum install -y gcc zlib zlib-devel openssl openssl-devel

配置并编译

./configure --prefix=/usr/local/python3.6    # 设置安装位置
make
make install

添加环境变量。在/etc/profile文件末尾追加

PATH=$PATH:/usr/local/python3.6/bin
export PATH

使环境变量生效

source /etc/profile

测试,执行python3命令,查看输出

 

CentOS添加环境变量

在Linux CentOS系统上安装完php和MySQL后,为了使用方便,需要将php和mysql命令加到系统命令中,如果在没有添加到环境变量之前,执行php -v命令查看当前php版本信息时时,则会提示命令不存在的错误,下面我们详细介绍一下在linux下将php和mysql加入到环境变量中的方法(假设php和mysql分别安装在/usr/local/webserver/php//usr/local/webserver/mysql/中)。

方法一:直接运行命令

export PATH=$PATH:/usr/local/webserver/php/bin
export PATH=$PATH:/usr/local/webserver/mysql/bin

使用这种方法,只会对当前会话有效,也就是说每当登出或注销系统以后,PATH 设置就会失效,只是临时生效。

方法二:执行vi ~/.bash_profile修改文件中PATH一行,将/usr/local/webserver/php/bin/usr/local/webserver/mysql/bin 加入到PATH=$PATH:$HOME/bin一行之后

这种方法只对当前登录用户生效

方法三:修改/etc/profile文件使其永久性生效,并对所有系统用户生效,在文件末尾加上如下两行代码

PATH=$PATH:/usr/local/webserver/php/bin:/usr/local/webserver/mysql/bin
export PATH

最后:执行 命令source /etc/profile或 执行点命令 ./profile使其修改生效,执行完可通过echo $PATH命令查看是否添加成功。

CentOS磁盘挂载

以下是一次完整的磁盘挂载、分区、格式化、LVM挂载等的过程

[root@centos ~]# fdisk -l

Disk /dev/sda: 128.0 GB, 128035676160 bytes, 250069680 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: 0xbfe84878

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1  4294967295  2147483647+  ee  GPT

Disk /dev/sdb: 128.0 GB, 128035676160 bytes, 250069680 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: 0x0001c0be

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     2099199     1048576   83  Linux
/dev/sdb2         2099200   250068991   123984896   8e  Linux LVM

Disk /dev/mapper/centos-root: 34.6 GB, 34615590912 bytes, 67608576 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 /dev/mapper/centos-swap: 17.2 GB, 17179869184 bytes, 33554432 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 /dev/mapper/centos-home: 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 /dev/mapper/centos-var: 53.7 GB, 53687091200 bytes, 104857600 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@centos ~]# 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
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 1
Value out of range.
Partition number (2-4, default 2): q
Partition number (2-4, default 2): ^C
[root@centos ~]# 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   
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p^H^C
[root@centos ~]# 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): m        
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   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): d
Selected partition 1
Partition 1 is deleted

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos ~]# 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
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-250069679, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-250069679, default 250069679): 
Using default value 250069679
Partition 1 of type Linux and of size 119.2 GiB is set

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos ~]# fdisk -l

Disk /dev/sda: 128.0 GB, 128035676160 bytes, 250069680 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: 0xbfe84878

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   250069679   125033816   83  Linux

Disk /dev/sdb: 128.0 GB, 128035676160 bytes, 250069680 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: 0x0001c0be

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     2099199     1048576   83  Linux
/dev/sdb2         2099200   250068991   123984896   8e  Linux LVM

Disk /dev/mapper/centos-root: 34.6 GB, 34615590912 bytes, 67608576 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 /dev/mapper/centos-swap: 17.2 GB, 17179869184 bytes, 33554432 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 /dev/mapper/centos-home: 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 /dev/mapper/centos-var: 53.7 GB, 53687091200 bytes, 104857600 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@centos ~]# l
Display all 155 possibilities? (y or n)
l.                           locate
l2ping                       lockdev
l2test                       logger
last                         login
lastb                        loginctl
lastcomm                     logname
lastlog                      logout
lchage                       logrotate
lchfn                        logsave
lchsh                        logview
ld                           look
ldattach                     losetup
ld.bfd                       lp
ldconfig                     lpadmin
ldd                          lpasswd
ld.gold                      lpc
ldns-chaos                   lpc.cups
ldns-compare-zones           lp.cups
ldnsd                        lpinfo
ldns-dane                    lpmove
ldns-dpa                     lpoptions
ldns-gen-zone                lppasswd
ldns-key2ds                  lpq
ldns-keyfetcher              lpq.cups
ldns-keygen                  lpr
ldns-mx                      lpr.cups
ldns-notify                  lprm
ldns-nsec3-hash              lprm.cups
ldns-read-zone               lprsetup.sh
ldns-resolver                lpstat
ldns-revoke                  lpstat.cups
ldns-rrsig                   ls
ldns-signzone                lsattr
ldns-test-edns               lsblk
ldns-testns                  lscgroup
ldns-update                  lscpu
ldns-verify-zone             lsinitrd
ldns-version                 lsipc
ldns-walk                    lslocks
ldns-zcat                    lslogins
ldns-zsplit                  lsmcli
--More--^C
[root@centos ~]# lsblk 
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk 
└─sda1            8:1    0 119.2G  0 part 
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos ~]# df -T
Filesystem              Type     1K-blocks    Used Available Use% Mounted on
/dev/mapper/centos-root xfs       33787784 3374740  30413044  10% /
devtmpfs                devtmpfs   8030912       0   8030912   0% /dev
tmpfs                   tmpfs      8042080       0   8042080   0% /dev/shm
tmpfs                   tmpfs      8042080    9136   8032944   1% /run
tmpfs                   tmpfs      8042080       0   8042080   0% /sys/fs/cgroup
/dev/sdb1               xfs        1038336  193472    844864  19% /boot
/dev/mapper/centos-home xfs       20961280   32956  20928324   1% /home
/dev/mapper/centos-var  xfs       52403200  315164  52088036   1% /var
tmpfs                   tmpfs      1608420      56   1608364   1% /run/user/0
[root@centos ~]# mkfs.
mkfs.btrfs   mkfs.ext2    mkfs.ext4    mkfs.minix   mkfs.vfat
mkfs.cramfs  mkfs.ext3    mkfs.fat     mkfs.msdos   mkfs.xfs
[root@centos ~]# mkfs.
mkfs.btrfs   mkfs.ext2    mkfs.ext4    mkfs.minix   mkfs.vfat
mkfs.cramfs  mkfs.ext3    mkfs.fat     mkfs.msdos   mkfs.xfs
[root@centos ~]# mkfs.xfs /dev/sda
sda   sda1  
[root@centos ~]# mkfs.xfs /dev/sda
sda   sda1  
[root@centos ~]# mkfs.xfs /dev/sda1
mkfs.xfs: /dev/sda1 appears to contain an existing filesystem (ntfs).
mkfs.xfs: Use the -f option to force overwrite.
[root@centos ~]# mkfs.xfs /dev/sda1 -f
meta-data=/dev/sda1              isize=512    agcount=4, agsize=7814614 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=31258454, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=15262, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@centos ~]# cd /
[root@centos /]# mkdir data
[root@centos /]# ll
total 28
lrwxrwxrwx.   1 root root    7 Mar  7 22:08 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 Mar  7 22:46 boot
drwxr-xr-x.   2 root root    6 Mar  8 09:43 data
drwxr-xr-x.  21 root root 3540 Mar  8 09:33 dev
drwxr-xr-x. 139 root root 8192 Mar  7 23:44 etc
drwxr-xr-x.   3 root root   19 Mar  7 22:12 home
lrwxrwxrwx.   1 root root    7 Mar  7 22:08 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 Mar  7 22:08 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 Nov  5  2016 media
drwxr-xr-x.   2 root root    6 Nov  5  2016 mnt
drwxr-xr-x.   3 root root   16 Mar  7 22:39 opt
dr-xr-xr-x. 308 root root    0 Mar  8 07:44 proc
dr-xr-x---.  19 root root 4096 Mar  8 09:23 root
drwxr-xr-x.  38 root root 1140 Mar  8 09:23 run
lrwxrwxrwx.   1 root root    8 Mar  7 22:08 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 Nov  5  2016 srv
dr-xr-xr-x.  13 root root    0 Mar  7 23:44 sys
drwxrwxrwt.  23 root root 4096 Mar  8 09:43 tmp
drwxr-xr-x.  13 root root  155 Mar  7 22:08 usr
drwxr-xr-x.  21 root root 4096 Mar  7 22:39 var
[root@centos /]# mount /dev/sda1 /data
[root@centos /]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        33G  3.3G   30G  10% /
devtmpfs                devtmpfs  7.7G     0  7.7G   0% /dev
tmpfs                   tmpfs     7.7G     0  7.7G   0% /dev/shm
tmpfs                   tmpfs     7.7G  9.0M  7.7G   1% /run
tmpfs                   tmpfs     7.7G     0  7.7G   0% /sys/fs/cgroup
/dev/sdb1               xfs      1014M  189M  826M  19% /boot
/dev/mapper/centos-home xfs        20G   33M   20G   1% /home
/dev/mapper/centos-var  xfs        50G  308M   50G   1% /var
tmpfs                   tmpfs     1.6G   56K  1.6G   1% /run/user/0
/dev/sda1               xfs       120G   33M  120G   1% /data
[root@centos /]# cd /etc/fstab^C
[root@centos /]# vi /etc/fstab 
[root@centos /]# 
[root@centos /]# lsblk 
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk 
└─sda1            8:1    0 119.2G  0 part /data
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos /]# fdisk -l

Disk /dev/sda: 128.0 GB, 128035676160 bytes, 250069680 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: 0xbfe84878

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   250069679   125033816   83  Linux

Disk /dev/sdb: 128.0 GB, 128035676160 bytes, 250069680 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: 0x0001c0be

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     2099199     1048576   83  Linux
/dev/sdb2         2099200   250068991   123984896   8e  Linux LVM

Disk /dev/mapper/centos-root: 34.6 GB, 34615590912 bytes, 67608576 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 /dev/mapper/centos-swap: 17.2 GB, 17179869184 bytes, 33554432 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 /dev/mapper/centos-home: 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 /dev/mapper/centos-var: 53.7 GB, 53687091200 bytes, 104857600 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@centos /]# fdisk -l

Disk /dev/sda: 128.0 GB, 128035676160 bytes, 250069680 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: 0xbfe84878

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   250069679   125033816   83  Linux

Disk /dev/sdb: 128.0 GB, 128035676160 bytes, 250069680 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: 0x0001c0be

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     2099199     1048576   83  Linux
/dev/sdb2         2099200   250068991   123984896   8e  Linux LVM

Disk /dev/mapper/centos-root: 34.6 GB, 34615590912 bytes, 67608576 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 /dev/mapper/centos-swap: 17.2 GB, 17179869184 bytes, 33554432 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 /dev/mapper/centos-home: 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 /dev/mapper/centos-var: 53.7 GB, 53687091200 bytes, 104857600 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@centos /]# 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): p

Disk /dev/sda: 128.0 GB, 128035676160 bytes, 250069680 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: 0xbfe84878

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   250069679   125033816   83  Linux

Command (m for help): ^C
[root@centos /]# 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): d
Selected partition 1
Partition 1 is deleted

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@centos /]# 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): m  
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   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
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-250069679, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-250069679, default 250069679): 
Using default value 250069679
Partition 1 of type Linux and of size 119.2 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.
[root@centos /]# fdisk /dev/sda^C
[root@centos /]# lsblk 
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk 
└─sda1            8:1    0 119.2G  0 part /data
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos /]# unmount /dev/sda
bash: unmount: command not found...
[root@centos /]# yum install unmount
Loaded plugins: fastestmirror, langpacks
base                                        | 3.6 kB     00:00     
epel/x86_64/metalink                        | 7.1 kB     00:00     
extras                                      | 3.4 kB     00:00     
updates                                     | 3.4 kB     00:00     
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * epel: mirror01.idc.hinet.net
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
No package unmount available.
Error: Nothing to do
[root@centos /]# umount /dev/sda
umount: /dev/sda: not mounted
[root@centos /]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk 
└─sda1            8:1    0 119.2G  0 part /data
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos /]# umount /data
[root@centos /]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk 
└─sda1            8:1    0 119.2G  0 part 
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos /]# mkfs.xfs /dev/sda
mkfs.xfs: /dev/sda appears to contain a partition table (dos).
mkfs.xfs: Use the -f option to force overwrite.
[root@centos /]# mkfs.xfs /dev/sda -f
meta-data=/dev/sda               isize=512    agcount=4, agsize=7814678 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=31258710, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=15263, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@centos /]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk 
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos /]# mount /dev/sda /data
[root@centos /]# lsblk 
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk /data
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos /]# 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.

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

Command (m for help): d
No partition is defined yet!

Command (m for help): ^C 
[root@centos /]# umount /data
[root@centos /]# 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.

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

Command (m for help): p  

Disk /dev/sda: 128.0 GB, 128035676160 bytes, 250069680 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: 0x181824cf

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): ^C 
[root@centos /]# pvcreate /dev/sda
WARNING: xfs signature detected on /dev/sda at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/sda.
  Physical volume "/dev/sda" successfully created.
[root@centos /]# pvs
  PV         VG     Fmt  Attr PSize    PFree  
  /dev/sda          lvm2 ---   119.24g 119.24g
  /dev/sdb2  centos lvm2 a--  <118.24g      0 
[root@centos /]# vgcreate -s 4m datavg /dev/sda
  Volume group "datavg" successfully created
[root@centos /]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                4
  Open LV               4
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <118.24 GiB
  PE Size               4.00 MiB
  Total PE              30269
  Alloc PE / Size       30269 / <118.24 GiB
  Free  PE / Size       0 / 0   
  VG UUID               ykO7iD-Z2Vr-RnSN-nmdz-dDjx-AZlu-WGTO3L
   
  --- Volume group ---
  VG Name               datavg
  System ID             
  Format                lvm2
  Metadata Areas        1
  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                1
  Act PV                1
  VG Size               <119.24 GiB
  PE Size               4.00 MiB
  Total PE              30525
  Alloc PE / Size       0 / 0   
  Free  PE / Size       30525 / <119.24 GiB
  VG UUID               2Vt33P-4wry-4CHm-fzFd-ivoL-6uLe-fPk8fz
   
[root@centos /]# vgdisplay datavbg
  Volume group "datavbg" not found
  Cannot process volume group datavbg
[root@centos /]# vgdisplay datavg
  --- Volume group ---
  VG Name               datavg
  System ID             
  Format                lvm2
  Metadata Areas        1
  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                1
  Act PV                1
  VG Size               <119.24 GiB
  PE Size               4.00 MiB
  Total PE              30525
  Alloc PE / Size       0 / 0   
  Free  PE / Size       30525 / <119.24 GiB
  VG UUID               2Vt33P-4wry-4CHm-fzFd-ivoL-6uLe-fPk8fz
   
[root@centos /]# lvcreate -l 30525 -n lv_data datavg
  Logical volume "lv_data" created.
[root@centos /]# lvs
  LV      VG     Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home    centos -wi-ao----   20.00g                                                    
  root    centos -wi-ao----  <32.24g                                                    
  swap    centos -wi-ao----   16.00g                                                    
  var     centos -wi-ao----   50.00g                                                    
  lv_data datavg -wi-a----- <119.24g                                                    
[root@centos /]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   33G  3.3G   30G  10% /
devtmpfs                 7.7G     0  7.7G   0% /dev
tmpfs                    7.7G     0  7.7G   0% /dev/shm
tmpfs                    7.7G  9.0M  7.7G   1% /run
tmpfs                    7.7G     0  7.7G   0% /sys/fs/cgroup
/dev/sdb1               1014M  189M  826M  19% /boot
/dev/mapper/centos-home   20G   33M   20G   1% /home
/dev/mapper/centos-var    50G  307M   50G   1% /var
tmpfs                    1.6G   56K  1.6G   1% /run/user/0
[root@centos /]# mkfs.xfs /dev/mapper/datavg-lv_data
meta-data=/dev/mapper/datavg-lv_data isize=512    agcount=4, agsize=7814400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=31257600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=15262, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@centos /]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   33G  3.3G   30G  10% /
devtmpfs                 7.7G     0  7.7G   0% /dev
tmpfs                    7.7G     0  7.7G   0% /dev/shm
tmpfs                    7.7G  9.0M  7.7G   1% /run
tmpfs                    7.7G     0  7.7G   0% /sys/fs/cgroup
/dev/sdb1               1014M  189M  826M  19% /boot
/dev/mapper/centos-home   20G   33M   20G   1% /home
/dev/mapper/centos-var    50G  307M   50G   1% /var
tmpfs                    1.6G   56K  1.6G   1% /run/user/0
[root@centos /]# lvs
  LV      VG     Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home    centos -wi-ao----   20.00g                                                    
  root    centos -wi-ao----  <32.24g                                                    
  swap    centos -wi-ao----   16.00g                                                    
  var     centos -wi-ao----   50.00g                                                    
  lv_data datavg -wi-a----- <119.24g                                                    
[root@centos /]# mount /dev/mapper/datavg-lv_data /data
[root@centos /]# df -h
Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/centos-root      33G  3.3G   30G  10% /
devtmpfs                    7.7G     0  7.7G   0% /dev
tmpfs                       7.7G     0  7.7G   0% /dev/shm
tmpfs                       7.7G  9.0M  7.7G   1% /run
tmpfs                       7.7G     0  7.7G   0% /sys/fs/cgroup
/dev/sdb1                  1014M  189M  826M  19% /boot
/dev/mapper/centos-home      20G   33M   20G   1% /home
/dev/mapper/centos-var       50G  307M   50G   1% /var
tmpfs                       1.6G   56K  1.6G   1% /run/user/0
/dev/mapper/datavg-lv_data  120G   33M  120G   1% /data
[root@centos /]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Wed Mar  7 22:08:19 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=b118055d-ded6-4cf2-9587-31f28414e5f9 /boot                   xfs     defaults        0 0
/dev/mapper/centos-home /home                   xfs     defaults        0 0
/dev/mapper/centos-var  /var                    xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
[root@centos /]# umount /data/
[root@centos /]# df -h 
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   33G  3.3G   30G  10% /
devtmpfs                 7.7G     0  7.7G   0% /dev
tmpfs                    7.7G     0  7.7G   0% /dev/shm
tmpfs                    7.7G  9.0M  7.7G   1% /run
tmpfs                    7.7G     0  7.7G   0% /sys/fs/cgroup
/dev/sdb1               1014M  189M  826M  19% /boot
/dev/mapper/centos-home   20G   33M   20G   1% /home
/dev/mapper/centos-var    50G  307M   50G   1% /var
tmpfs                    1.6G   56K  1.6G   1% /run/user/0
[root@centos /]# lvremove /dev/mapper/
centos-home     centos-root     centos-swap     centos-var      datavg-lv_data  
[root@centos /]# lvremove /dev/mapper/
centos-home     centos-root     centos-swap     centos-var      datavg-lv_data  
[root@centos /]# lvremove /dev/mapper/datavg-lv_data 
Do you really want to remove active logical volume datavg/lv_data? [y/n]: y
  Logical volume "lv_data" successfully removed
[root@centos /]# vgremove /dev/sda
  Volume group "sda" not found
  Cannot process volume group sda
[root@centos /]# vgremove datavg
  Volume group "datavg" successfully removed
[root@centos /]# pvremove /dev/sda
  Labels on physical volume "/dev/sda" successfully wiped.

分区后,修改/etc/fstab文件保存目录挂载信息即可