Post

LVM

LVM

创建LVM

1
2
3
4
5
6
7
8
9
10
11
[root@worker11 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 7.8G     0  7.8G   0% /dev
tmpfs                    7.8G     0  7.8G   0% /dev/shm
tmpfs                    7.8G  1.2M  7.8G   1% /run
tmpfs                    7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root  100G   11G   90G  11% /
/dev/sda1               1014M  180M  835M  18% /boot
/dev/sdb1                493G   20G  448G   5% /data
/dev/mapper/centos-home   47G   39M   47G   1% /home
/dev/loop0               302M  302M     0 100% /tmp/kubekey/iso

wipefs

清除分区的文件系统标识信息, 让操作系统无法再识别该分区的文件系统

清除文件系统标识信息,但不会删除实际数据

不删除数据:数据仍然保留在分区中,但文件系统无法识别,数据不可用。

准备磁盘或分区:

  • 常用于重新分区重新创建文件系统前的清理工作。
  • 避免旧的文件系统信息干扰新文件系统的操作。
1
2
[root@worker11 ~]# sudo wipefs -a /dev/sdb1
/dev/sdb1: 2 bytes were erased at offset 0x00000438 (ext4): 53 ef

pvcreate

创建物理卷 实际就是对真实的磁盘进行一个标记

  • 内部进行一个逻辑的划分, 分成一个个4M的块
1
2
[root@worker11 ~]# sudo pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.

vgcreate

多个物理卷合并成一个卷组

可以多个物理卷合并为一个卷组

  • 卷组可以包含多个物理卷,但每个物理卷只能属于一个卷组。
1
2
[root@worker11 ~]# sudo vgcreate influxdb_vg /dev/sdb1
Volume group "influxdb_vg" successfully created

lvcreate

创建逻辑卷

1
2
3
# 创建一个名为influxdb_lv的逻辑卷,其大小占用卷组中所有剩余的空间。
[root@worker11 ~]# sudo lvcreate -n influxdb_lv -l 100%FREE influxdb_vg
  Logical volume "influxdb_lv" created.

mkfs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[root@worker11 ~]# sudo mkfs.ext4 /dev/influxdb_vg/influxdb_lv
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
32768000 inodes, 131070976 blocks
6553548 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2279604224
4000 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, 1605632, 2654208,
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
	102400000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:
done
[root@worker11 ~]# sudo mkdir /mnt/influxdb_data

### mount

[root@worker11 ~]# sudo mount /dev/influxdb_vg/influxdb_lv /mnt/influxdb_data

1
2
### df

[root@worker11 ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 7.8G 0 7.8G 0% /dev tmpfs 7.8G 0 7.8G 0% /dev/shm tmpfs 7.8G 1.2M 7.8G 1% /run tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup /dev/mapper/centos-root 100G 11G 90G 11% / /dev/sda1 1014M 180M 835M 18% /boot /dev/mapper/centos-home 47G 39M 47G 1% /home /dev/loop0 302M 302M 0 100% /tmp/kubekey/iso /dev/mapper/influxdb_vg-influxdb_lv 493G 73M 467G 1% /mnt/influxdb_data [root@harbor ~]#

[root@harbor ~]# scp /root/influxdb2-2.0.9.x86_64.rpm 10.130.9.103:/tmp [root@harbor ~]# echo $? 0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

### install
```shell
[root@worker11 tmp]# yum localinstall influxdb2-2.0.9.x86_64.rpm
Loaded plugins: fastestmirror, langpacks
Examining influxdb2-2.0.9.x86_64.rpm: influxdb2-2.0.9-1.x86_64
Marking influxdb2-2.0.9.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package influxdb2.x86_64 0:2.0.9-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================
 Package                      Arch                      Version                       Repository                                  Size
=======================================================================================================================================
Installing:
 influxdb2                    x86_64                    2.0.9-1                       /influxdb2-2.0.9.x86_64                    182 M

Transaction Summary
=======================================================================================================================================
Install  1 Package

Total size: 182 M
Installed size: 182 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : influxdb2-2.0.9-1.x86_64                                                                                            1/1



Created symlink from /etc/systemd/system/influxd.service to /usr/lib/systemd/system/influxdb.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/influxdb.service to /usr/lib/systemd/system/influxdb.service.
  Verifying  : influxdb2-2.0.9-1.x86_64                                                                                            1/1

Installed:
  influxdb2.x86_64 0:2.0.9-1

Complete!
[root@worker11 tmp]#

rsync

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
[root@worker11 scripts]# sudo rsync -av /var/lib/influxdb/ /mnt/influxdb_data/
sending incremental file list
./
influxd.bolt
influxd.pid
.cache/
.cache/snowflake/
engine/
engine/data/

sent 65,911 bytes  received 77 bytes  131,976.00 bytes/sec
total size is 65,542  speedup is 0.99
[root@worker11 scripts]# echo $?
0
[root@worker11 scripts]# vim /etc/influxdb/config.toml
[root@worker11 scripts]# ls -lt /mnt/influxdb_data/engine
total 4
drwxr-xr-x 2 influxdb influxdb 4096 Jun 20 11:39 data
[root@worker11 scripts]# cat  /etc/influxdb/config.toml
# bolt-path = "/var/lib/influxdb/influxd.bolt"
# engine-path = "/var/lib/influxdb/engine"

bolt-path = "/mnt/influxdb_data/influxd.bolt"
engine-path = "/mnt/influxdb_data/engine"
[root@worker11 scripts]# echo '/dev/influxdb_vg/influxdb_lv /mnt/influxdb_data ext4 defaults 0 0' | sudo tee -a /etc/fstab

/dev/influxdb_vg/influxdb_lv /mnt/influxdb_data ext4 defaults 0 0
[root@worker11 scripts]#
[root@worker11 scripts]# echo $?
0
[root@worker11 scripts]# systemctl restart influxdb
[root@worker11 scripts]# systemctl status influxdb
● influxdb.service - InfluxDB is an open-source, distributed, time series database
   Loaded: loaded (/usr/lib/systemd/system/influxdb.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2024-06-20 16:38:06 CST; 2s ago
     Docs: https://docs.influxdata.com/influxdb/
  Process: 37007 ExecStart=/usr/lib/influxdb/scripts/influxd-systemd-start.sh (code=exited, status=0/SUCCESS)
 Main PID: 37008 (influxd)
    Tasks: 13
   Memory: 55.1M
   CGroup: /system.slice/influxdb.service
           └─37008 /usr/bin/influxd

Jun 20 16:38:04 worker11 influxd-systemd-start.sh[37007]: ts=2024-06-20T08:38:04.602611Z lvl=info msg="Open store (start)" log_id=0puC_RZW000 service=storage-engine service=store op_name=tsdb_open op_event=start
Jun 20 16:38:04 worker11 influxd-systemd-start.sh[37007]: ts=2024-06-20T08:38:04.602724Z lvl=info msg="Open store (end)" log_id=0puC_RZW000 service=storage-engine service=store op_name=tsdb_open op_event=end op_elapsed=0.116ms
Jun 20 16:38:04 worker11 influxd-systemd-start.sh[37007]: ts=2024-06-20T08:38:04.602791Z lvl=info msg="Starting retention policy enforcement service" log_id=0puC_RZW000 service=retention check_interval=30m
Jun 20 16:38:04 worker11 influxd-systemd-start.sh[37007]: ts=2024-06-20T08:38:04.602833Z lvl=info msg="Starting precreation service" log_id=0puC_RZW000 service=shard-precreation check_interval=10m advance_period=30m
Jun 20 16:38:04 worker11 influxd-systemd-start.sh[37007]: ts=2024-06-20T08:38:04.603167Z lvl=info msg="Starting query controller" log_id=0puC_RZW000 service=storage-reads concurrency_quota=1024 initial_memory_bytes_quota_per_query=9223372036854775807...s=0 queue_size=1024
Jun 20 16:38:04 worker11 influxd-systemd-start.sh[37007]: ts=2024-06-20T08:38:04.616200Z lvl=info msg="Configuring InfluxQL statement executor (zeros indicate unlimited)." log_id=0puC_RZW000 max_select_point=0 max_select_series=0 max_select_buckets=0
Jun 20 16:38:05 worker11 influxd-systemd-start.sh[37007]: InfluxDB API at http://localhost:8086/ready unavailable after 11 attempts...
Jun 20 16:38:05 worker11 influxd-systemd-start.sh[37007]: ts=2024-06-20T08:38:05.662164Z lvl=info msg=Starting log_id=0puC_RZW000 service=telemetry interval=8h
Jun 20 16:38:05 worker11 influxd-systemd-start.sh[37007]: ts=2024-06-20T08:38:05.662224Z lvl=info msg=Listening log_id=0puC_RZW000 service=tcp-listener transport=http addr=:8086 port=8086
Jun 20 16:38:06 worker11 systemd[1]: Started InfluxDB is an open-source, distributed, time series database.
Hint: Some lines were ellipsized, use -l to show in full.

修改数据挂载路径

1
2
3
4
[root@worker11 scripts]# cat /etc/default/influxdb2
INFLUXD_CONFIG_PATH=/etc/influxdb/config.toml

我使用rpm创建的influxdb, 怎么修改数据路径到sudo mount /dev/influxdb_vg/influxdb_lv /mnt/influxdb_data

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 卸载现有的 /dev/sdb1
sudo umount /data

# 清空 /dev/sdb1
sudo wipefs -a /dev/sdb1

# 创建物理卷
sudo pvcreate /dev/sdb1

# 创建卷组
sudo vgcreate influxdb_vg /dev/sdb1

# 创建逻辑卷
sudo lvcreate -n influxdb_lv -l 100%FREE influxdb_vg

# 格式化逻辑卷
sudo mkfs.ext4 /dev/influxdb_vg/influxdb_lv

# 挂载逻辑卷
sudo mkdir /mnt/influxdb_data
sudo mount /dev/influxdb_vg/influxdb_lv /mnt/influxdb_data

# 停止InfluxDB服务并迁移数据
sudo systemctl stop influxdb
sudo rsync -av /var/lib/influxdb/ /mnt/influxdb_data/

# 编辑配置文件
sudo nano /etc/influxdb/config.toml
# 更新bolt-path和engine-path为/mnt/influxdb_data

# 更新/etc/fstab
echo '/dev/influxdb_vg/influxdb_lv /mnt/influxdb_data ext4 defaults 0 0' | sudo tee -a /etc/fstab

# 启动InfluxDB服务
sudo systemctl start influxdb

使用LVM挂载分区

检查磁盘状态

1
sudo lsblk

清空目标磁盘

1
2
sudo wipefs -a /dev/sdb
sudo fdisk /dev/sdb

创建物理卷

1
sudo pvcreate /dev/sdb1

创建卷组

1
sudo vgcreate data_vg /dev/sdb1

创建逻辑卷 (LV)

1
sudo lvcreate -n data_lv -l 100%FREE data_vg

格式化逻辑卷

1
sudo mkfs.ext4 /dev/data_vg/data_lv

挂载逻辑卷

1
2
sudo mkdir /mnt/data
sudo mount /dev/data_vg/data_lv /mnt/data

设置开机自动挂载

1
echo '/dev/data_vg/data_lv /mnt/data ext4 defaults 0 0' | sudo tee -a /etc/fstab

扩容LVM

添加新磁盘到卷组

创建新的物理卷

1
sudo pvcreate /dev/sdc

拓展卷组

1
sudo vgextend data_vg /dev/sdc

扩展逻辑卷

扩展逻辑卷到使用卷组的所有剩余空间:

1
2
3
4
sudo lvextend -l +100%FREE /dev/data_vg/data_lv

ext4的扩容方式
sudo resize2fs /dev/data_vg/data_lv

验证

确保磁盘已正确挂载:

1
2
3
df -h
sudo lvdisplay
sudo vgdisplay
This post is licensed under CC BY 4.0 by the author.