また、自作かよ。(CentOS 7 に戻っちゃう 編)-02

By | 2020年7月10日

CentOS 7のインストールとインストール後の基本設定に

ついては、それぞれ、下の記事を参考にして進めました。

サーバー構築の基本 CentOS 7系最終バージョンのCentOS 7.7をインストールする

CentOS 7のインストール後におこなうLinuxの基本設定 13ポイント

ほぼ、すんなりと進めることができました。でも、久々の

CentOS 7 で iptables に再会して、ちょっとだけホッコリしました。

インストール時に、ネットワーク設定だけは済ませておくことを

オススメします。インストール後、ただちに ssh 接続できるので

便利です。ただし、ひとつだけ失敗したことがあって、ストレージ

オプションで、「パーティションを自動構成する」を選んで

しまったため、「/home」を縮小し、「/」を拡張するのに、

スゴイ手間がかかってしまいました。しかも、その前に、

一般ユーザー“dokolife” 作ってしまってたものですから、さらに

ひと手間必要でした。でも、まだ何もデータが入ってない空の

ディレクトリだったので、作成するだけで済んだハズ。

手順については、ほぼ、ここをまるごと参考にさせていただきました。

/homeを削除して/を拡張
 [root@CentOS-7-Server ~]# df -h
 ファイルシス サイズ 使用 残り 使用% マウント位置
 devtmpfs  7.7G  0   7.7G 0%  /dev
 tmpfs    7.7G  0   7.7G 0%  /dev/shm
 tmpfs    7.7G  9.1M 7.7G 1%  /run
 tmpfs    7.7G  0   7.7G 0%  /sys/fs/cgroup
 /dev/mapper/centos_centos–7–server-root 50G 2.4G 48G 5% /
 /dev/sda2  1014M 179M 836M 18% /boot
 /dev/sda1  200M  12M 189M  6% /boot/efi
 /dev/mapper/centos_centos–7–server-home 1.8T 33M 1.8T 1% /home
 tmpfs    1.6G  0   1.6G 0% /run/user/0


 [root@CentOS-7-Server ~]# df -Th
 ファイルシス タイプ サイズ 使用 残り 使用% マウント位置
 devtmpfs  devtmpfs 7.7G 0  7.7G 0%  /dev
 tmpfs    tmpfs  7.7G 0 7.7G  0%  /dev/shm
 tmpfs    tmpfs  7.7G 9.1M 7.7G 1% /run
 tmpfs    tmpfs  7.7G 0   7.7G 0% /sys/fs/cgroup
 /dev/mapper/centos_centos–7–server-root xfs 50G 2.4G 48G 5% /
 /dev/sda2 xfs 1014M 179M 836M 18% /boot
 /dev/sda1 vfat 200M  12M 189M 6% /boot/efi
 /dev/mapper/centos_centos–7–server-home xfs 1.8T 33M 1.8T 1% /home
 tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/0


 [root@CentOS-7-Server ~]# lvdisplay
— Logical volume —
LV Path  /dev/centos_centos-7-server/swap
LV Name  swap
VG Name  centos_centos-7-server
LV UUID  Cddn7i-65dd-ddhG-1ndd-iddU-Bedd-8uddZ1
LV Write Access  read/write
LV Creation host, time centos-7-server, 2020-07-09 16:41:14 +0900
LV Status  available
# open  2
LV Size  7.81 GiB
Current LE  2000
Segments  1
Allocation  inherit
Read ahead sectors  auto
– currently set to  256
Block device  253:1

— Logical volume —
LV Path  /dev/centos_centos-7-server/home
LV Name  home
VG Name  centos_centos-7-server
LV UUID  gdd1ar-PddL-aWnB-UddK-TwdI-Pddd-i2KObd
LV Write Access read/write
LV Creation host, time centos-7-server, 2020-07-09 16:41:14 +0900
LV Status  available
# open  1
LV Size  1.76 TiB
Current LE  461824
Segments  1
Allocation  inherit
Read ahead sectors  auto
– currently set to  256
Block device  253:2

— Logical volume —
LV Path  /dev/centos_centos-7-server/root
LV Name  root
VG Name  centos_centos-7-server
LV UUID  dddlGi-3ddZ-9tLd-eddi-KddM-Um3v-ddascX
LV Write Access  read/write
LV Creation host, time centos-7-server, 2020-07-09 16:41:20 +0900
LV Status  available
# open  1
LV Size  50.00 GiB
Current LE  12800
Segments  1
Allocation  inherit
Read ahead sectors  auto
– currently set to  256
Block device  253:0

 

//アンマウント
 [root@CentOS-7-Server ~]# umount /dev/centos_centos-7-server/home

//ボリュームの利用を停止する
 [root@CentOS-7-Server ~]# lvchange -a n /dev/centos_centos-7-server/home

//論理ボリュームを確認する
 [root@CentOS-7-Server ~]# lvdisplay
— Logical volume —
LV Path  /dev/centos_centos-7-server/swap
LV Name  swap
VG Name  centos_centos-7-server
LV UUID  CPdd7i-65JS-ddhG-1nkq-iuTU-Bedd-8uCHdd
LV Write Access  read/write
LV Creation host, time centos-7-server, 2020-07-09 16:41:14 +0900
LV Status  available
# open  2
LV Size  7.81 GiB
Current LE  2000
Segments  1
Allocation  inherit
Read ahead sectors  auto
– currently set to  256
Block device  253:1

— Logical volume —
LV Path  /dev/centos_centos-7-server/home
LV Name  home
VG Name  centos_centos-7-server
LV UUID  gdd1ar-PddL-aWdd-UJ7K-TddI-P1Is-iddObd
LV Write Access  read/write
LV Creation host, time centos-7-server, 2020-07-09 16:41:14 +0900
LV Status NOT  available
LV Size  1.76 TiB
Current LE  461824
Segments  1
Allocation  inherit
Read ahead sectors  auto

— Logical volume —
LV Path  /dev/centos_centos-7-server/root
LV Name  root
VG Name  centos_centos-7-server
LV UUID  HddlGi-3cdd-9ddG-eddi-KddM-Um3v-htascX
LV Write Access  read/write
LV Creation host, time centos-7-server, 2020-07-09 16:41:20 +0900
LV Status  available
# open  1
LV Size  50.00 GiB
Current LE  12800
Segments  1
Allocation  inherit
Read ahead sectors auto
– currently set to  256
Block device  253:0

//論理ボリュームを削除する ※データも消えてしまうので注意
 [root@CentOS-7-Server ~]# lvremove /dev/centos_centos-7-server/home
Logical volume "home" successfully removed

//ボリュームグループを確認する
 [root@CentOS-7-Server ~]# vgdisplay
— Volume group —
VG Name  centos_centos-7-server
System ID
Format  lvm2
Metadata Areas  1
Metadata Sequence No 5
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  <1.82 TiB
PE Size  4.00 MiB
Total PE  476625
Alloc PE / Size  14800 / 57.81 GiB
Free PE / Size  461825 / 1.76 TiB
VG UUID  lddVcc-tddd-l3Co-lvcG-ddV7-jo3W-1vWddF


論理ボリューム「home」を作成

//論理ボリュームを作成
 [root@CentOS-7-Server ~]# lvcreate -L 16G -n home centos_centos-7-server
 WARNING: xfs signature detected on /dev/centos_centos-7-server/home at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/centos_centos-7-server/home.
Logical volume "home" created.

//ファイルシステムを作成
 [root@CentOS-7-Server ~]# mkfs.xfs /dev/centos_centos-7-server/home
 meta-data=/dev/centos_centos-7-server/home isize=512 agcount=4, agsize=1048576 blks
  =  sectsz=4096 attr=2, projid32bit=1
  =  crc=1  finobt=0, sparse=0
 data = bsize=4096 blocks=4194304, imaxpct=25
= sunit=0 swidth=0 blks
 naming =version 2  bsize=4096 ascii-ci=0 ftype=1
 log  =internal log  bsize=4096 blocks=2560, version=2
  =  sectsz=4096 sunit=1 blks, lazy-count=1
 realtime =none  extsz=4096 blocks=0, rtextents=0


//マウントする
 [root@CentOS-7-Server ~]# mount /dev/centos_centos-7-server/home

//ボリュームグループを確認する
 [root@CentOS-7-Server ~]# vgdisplay
— Volume group —
VG Name  centos_centos-7-server
System ID
Format  lvm2
Metadata Areas  1
Metadata Sequence No  6
VG Access  read/write
VG Status  resizable
MAX LV  0
Cur LV  3
Open LV  3
Max PV  0
Cur PV  1
Act PV  1
VG Size  <1.82 TiB
PE Size  4.00 MiB
Total PE  476625
Alloc PE / Size  18896 / 73.81 GiB
Free PE / Size  457729 / <1.75 TiB
VG UUID  lddVcc-tjHd-l3dd-lvcG-Vdd7-jo3W-1vWhsF


空き領域を割り当てる

//空き領域を割り当てる
 [root@CentOS-7-Server ~]# lvextend -l +100%FREE /dev/centos_centos-7-server/root
Size of logical volume centos_centos-7-server/root changed from 50.00 GiB (12800 extents) to 1.79 TiB (470529 extents).
Logical volume centos_centos-7-server/root successfully resized.

//XFSファイルシステムの拡大(これをしないとサイズは増えない)
 [root@CentOS-7-Server ~]# lvextend -l +100%FREE /dev/centos_centos-7-server/root
Size of logical volume centos_centos-7-server/root changed from 50.00 GiB (12800 extents) to 1.79 TiB (470529 extents).
Logical volume centos_centos-7-server/root successfully resized.
 [root@CentOS-7-Server ~]# xfs_growfs /dev/centos_centos-7-server/root
 meta-data=/dev/mapper/centos_centos–7–server-root isize=512 agcount=4, agsize=3276800 blks
  =  sectsz=4096 attr=2, projid32bit=1
  =  crc=1  finobt=0 spinodes=0
 data =  bsize=4096 blocks=13107200, imaxpct=25
  =  sunit=0  swidth=0 blks
 naming =version 2  bsize=4096 ascii-ci=0 ftype=1
 log  =internal  bsize=4096 blocks=6400, version=2
  =  sectsz=4096 sunit=1 blks, lazy-count=1
 realtime =none  extsz=4096 blocks=0, rtextents=0
 data blocks changed from 13107200 to 481821696

//ディスクドライブの使用状況を確認する
 [root@CentOS-7-Server ~]# df -Th
 ファイルシス  タイプ サイズ 使用 残り 使用% マウント位置
 devtmpfs   devtmpfs 7.7G  0  7.7G 0%  /dev
 tmpfs     tmpfs  7.7G  0  7.7G 0%  /dev/shm
 tmpfs     tmpfs  7.7G 9.1M  7.7G 1%  /run
 tmpfs     tmpfs  7.7G  0  7.7G  0%  /sys/fs/cgroup
 /dev/mapper/centos_centos–7–server-root xfs 1.8T 2.4G 1.8T 1% /
 /dev/sda2   xfs   1014M  179M  836M 18% /boot
 /dev/sda1   vfat  200M   12M   189M 6% /boot/efi
 tmpfs     tmpfs  1.6G  0  1.6G  0% /run/user/0
 /dev/mapper/centos_centos–7–server-home xfs 16G 33M 16G 1% /home


削除した /home ディレクトリを作成

 [root@CentOS-7-Server ~]# ls -l /home
 合計 0
 [root@CentOS-7-Server ~]# mkdir /home/dokolife
 drwxr-xr-x 2 root root 6 7月 10 18:55 dokolife
 [root@CentOS-7-Server ~]# chown dokolife. /home/dokolife
 [root@CentOS-7-Server ~]# ls -l /home
 合計 0
 drwxr-xr-x 2 dokolife wheel 6 7月 10 18:55 dokolife

以上。


# セキュリティ上の都合で微妙に編集を加えてますが、
 ホントに微妙なので、悪用しないでね♡