真羨慕那些一學就會的天才,本人愚鈍,慢慢學,多錯幾回就會了!node
LVM容許用戶對硬盤資源進行動態調整。linux
邏輯卷管理器是Linux系統用於對硬盤分區進行管理的一種機制,理論性較強,其建立初衷是爲了解決硬盤設備在建立分區後不易修改分區大小的缺陷。 json
經常使用命令vim
功能/命令 | 物理卷管理 | 卷組管理 | 邏輯卷管理 |
---|---|---|---|
掃描 | pvscan | vgscan | lvscan |
創建 | pvcreate | vgcreate | lvcreate |
顯示 | pvdisplay | vgdisplay | lvdisplay |
刪除 | pvremove | vgremove | lvremove |
擴展 | vgextend | lvextend | |
縮小 | vgreduce | lvreduce |
[root@localhost ~]# ls /dev/sd* /dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdc /dev/sdd
[root@localhost ~]# pvscan PV /dev/sda2 VG rhel lvm2 [<19.00 GiB / 0 free] Total: 1 [<19.00 GiB] / in use: 1 [<19.00 GiB] / in no VG: 0 [0 ] [root@localhost ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name rhel PV Size <19.00 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 4863 Free PE 0 Allocated PE 4863 PV UUID b0g3ec-ovac-UKgS-qL1j-4Tlp-5cdH-RHrDyo
[root@localhost ~]# pvcreate /dev/sd[b-d] Physical volume "/dev/sdb" successfully created. Physical volume "/dev/sdc" successfully created. Physical volume "/dev/sdd" successfully created.
[root@localhost ~]# vgcreate mmx /dev/sd[b-d] Volume group "mmx" successfully created
注意:劃分邏輯卷是4M的倍數api
[root@localhost ~]# lvcreate -n xiaoming -L 100M mmx Logical volume "xiaoming" created.
[root@localhost ~]# mkfs.ext4 /dev/mmx/xiaoming mke2fs 1.44.3 (10-July-2018) Creating filesystem with 102400 1k blocks and 25688 inodes Filesystem UUID: 420f0bea-0b7c-4adc-ab1c-abb808e9e97e Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done
[root@localhost ~]# mkdir /xiaoming [root@localhost ~]# mount /dev/mmx/xiaoming /xiaoming/ [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 3.8G 0 3.8G 0% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 9.6M 3.8G 1% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/mapper/rhel-root 17G 3.9G 14G 23% / /dev/sda1 1014M 169M 846M 17% /boot tmpfs 780M 16K 780M 1% /run/user/42 tmpfs 780M 4.0K 780M 1% /run/user/0 /dev/mapper/mmx-xiaoming 93M 1.6M 85M 2% /xiaoming
[root@localhost ~]# echo "/dev/mmx/xiaoming /xiaoming ext4 defaults 0 0" >> /etc/fstab
[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 3.8G 0 3.8G 0% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 9.6M 3.8G 1% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/mapper/rhel-root 17G 3.9G 14G 23% / /dev/mapper/mmx-xiaoming 93M 1.6M 85M 2% /xiaoming /dev/sda1 1014M 169M 846M 17% /boot tmpfs 780M 16K 780M 1% /run/user/42 tmpfs 780M 4.0K 780M 1% /run/user/0
注意,/etc/fstab文件寫錯了會致使Linux開機獲取不到IP地址等問題,開機輸入密碼以後,進入/etc/fstab目錄下刪除(修改)寫錯位置,重啓就能恢復正常bash
[root@localhost ~]# umount /xiaoming
[root@localhost ~]# lvextend -L 200M /dev/mmx/xiaoming Size of logical volume mmx/xiaoming changed from 100.00 MiB (25 extents) to 200.00 MiB (50 extents). Logical volume mmx/xiaoming successfully resized.
[root@localhost ~]# e2fsck -f /dev/mmx/xiaoming e2fsck 1.44.3 (10-July-2018) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/mmx/xiaoming: 11/25688 files (0.0% non-contiguous), 8896/102400 blocks
[root@localhost ~]# resize2fs /dev/mmx/xiaoming resize2fs 1.44.3 (10-July-2018) Resizing the filesystem on /dev/mmx/xiaoming to 204800 (1k) blocks. The filesystem on /dev/mmx/xiaoming is now 204800 (1k) blocks long.
[root@localhost ~]# tail -n 5 /etc/fstab # /dev/mapper/rhel-root / xfs defaults 0 0 UUID=f4604852-3220-4d86-9f3a-624c06ef3565 /boot xfs defaults 0 0 /dev/mapper/rhel-swap swap swap defaults 0 0 /dev/mmx/xiaoming /xiaoming ext4 defaults 0 0
[root@localhost ~]# mount -a
[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 3.8G 0 3.8G 0% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 9.6M 3.8G 1% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/mapper/rhel-root 17G 3.9G 14G 23% / /dev/sda1 1014M 169M 846M 17% /boot tmpfs 780M 16K 780M 1% /run/user/42 tmpfs 780M 4.0K 780M 1% /run/user/0 /dev/mapper/mmx-xiaoming 190M 1.6M 175M 1% /xiaoming #成功擴容 [root@localhost ~]# df -h | grep xiaoming /dev/mapper/mmx-xiaoming 190M 1.6M 175M 1% /xiaoming
[root@localhost ~]# umount /xiaoming
[root@localhost ~]# e2fsck -f /dev/mmx/xiaoming e2fsck 1.44.3 (10-July-2018) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/mmx/xiaoming: 11/49400 files (0.0% non-contiguous), 11884/204800 blocks
[root@localhost ~]# resize2fs /dev/mmx/xiaoming 100M resize2fs 1.44.3 (10-July-2018) Resizing the filesystem on /dev/mmx/xiaoming to 102400 (1k) blocks. The filesystem on /dev/mmx/xiaoming is now 102400 (1k) blocks long.
[root@localhost ~]# lvreduce -L 100M /dev/mmx/xiaoming WARNING: Reducing active logical volume to 100.00 MiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce mmx/xiaoming? [y/n]: y Size of logical volume mmx/xiaoming changed from 200.00 MiB (50 extents) to 100.00 MiB (25 extents). Logical volume mmx/xiaoming successfully resized.
[root@localhost ~]# mount -a # 縮容完畢! [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 3.8G 0 3.8G 0% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 9.6M 3.8G 1% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/mapper/rhel-root 17G 3.9G 14G 23% / /dev/sda1 1014M 169M 846M 17% /boot tmpfs 780M 16K 780M 1% /run/user/42 tmpfs 780M 4.0K 780M 1% /run/user/0 /dev/mapper/mmx-xiaoming 93M 1.6M 85M 2% /xiaoming
[root@localhost ~]# cd /xiaoming/ [root@localhost xiaoming]# ls lost+found [root@localhost xiaoming]# cp -a /etc/* /xiaoming/ [root@localhost xiaoming]# ls [root@localhost xiaoming]# ls adjtime hosts protocols aliases hosts.allow pulse alsa hosts.deny qemu-ga alternatives hp qemu-kvm anacrontab idmapd.conf radvd.conf asound.conf init.d ras at.deny inittab rc0.d audit inputrc rc1.d authselect insights-client rc2.d avahi iproute2 rc3.d bash_completion.d iscsi rc4.d bashrc issue rc5.d bindresvport.blacklist issue.d rc6.d binfmt.d issue.net rc.d bluetooth kdump.conf rc.local brlapi.key kernel rdma brltty krb5.conf redhat-access-insights ……
[root@localhost xiaoming]# vgdisplay --- Volume group --- VG Name mmx System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 3 Act PV 3 VG Size <14.99 GiB PE Size 4.00 MiB Total PE 3837 Alloc PE / Size 25 / 100.00 MiB Free PE / Size 3812 / 14.89 GiB VG UUID E6Aa0P-abRY-WLCd-o7ce-AOtR-I1d0-5qvCa6
[root@localhost xiaoming]# lvcreate -L 120M -s -n MMX /dev/mmx/xiaoming Reducing COW size 120.00 MiB down to maximum usable size 104.00 MiB. Logical volume "MMX" created.
[root@localhost xiaoming]# rm -rf * [root@localhost xiaoming]# ls
[root@localhost ~]# umount /xiaoming
[root@localhost ~]# lvconvert --merge /dev/mmx/MMX Merging of volume mmx/MMX started. mmx/xiaoming: Merged: 100.00%
[root@localhost ~]# cd /xiaoming/ # 此時發現已經恢復完成! [root@localhost xiaoming]# ls adjtime hosts protocols aliases hosts.allow pulse alsa hosts.deny qemu-ga alternatives hp qemu-kvm anacrontab idmapd.conf radvd.conf asound.conf init.d ras at.deny inittab rc0.d audit inputrc rc1.d authselect insights-client rc2.d avahi iproute2 rc3.d bash_completion.d iscsi rc4.d bashrc issue rc5.d bindresvport.blacklist issue.d rc6.d binfmt.d issue.net rc.d bluetooth kdump.conf rc.local brlapi.key kernel rdma brltty krb5.conf redhat-access-insights brltty.conf krb5.conf.d redhat-release chkconfig.d ksmtuned.conf request-key.conf chrony.conf ld.so.cache request-key.d chrony.keys ld.so.conf resolv.conf
[root@localhost ~]# umount /xiaoming [root@localhost ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Sun Jan 3 09:58:31 2021 # # 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. # # After editing this file, run 'systemctl daemon-reload' to update systemd # units generated from this file. # /dev/mapper/rhel-root / xfs defaults 0 0 UUID=f4604852-3220-4d86-9f3a-624c06ef3565 /boot xfs defaults 0 0 /dev/mapper/rhel-swap swap swap defaults 0 0
[root@localhost ~]# lvremove /dev/mmx/xiaoming Do you really want to remove active logical volume mmx/xiaoming? [y/n]: y Logical volume "xiaoming" successfully removed
[root@localhost ~]# vgremove mmx Volume group "mmx" successfully removed
[root@localhost ~]# pvremove /dev/sd[b-d] Labels on physical volume "/dev/sdb" successfully wiped. Labels on physical volume "/dev/sdc" successfully wiped. Labels on physical volume "/dev/sdd" successfully wiped.
# 均爲系統默認卷組,新建卷組已成功刪除 [root@localhost ~]# lvscan ACTIVE '/dev/rhel/swap' [2.00 GiB] inherit ACTIVE '/dev/rhel/root' [<17.00 GiB] inherit [root@localhost ~]# vgscan Reading all physical volumes. This may take a while... Found volume group "rhel" using metadata type lvm2 [root@localhost ~]# pvscan PV /dev/sda2 VG rhel lvm2 [<19.00 GiB / 0 free] Total: 1 [<19.00 GiB] / in use: 1 [<19.00 GiB] / in no VG: 0 [0 ]
重啓網卡方式(方式1不行就是用方式2)markdown
一、[root@localhost ~]# nmcli connection reload ens160網絡
二、[root@localhost ~]#nmcli connection up ens160app
其中ens160 [網卡名稱]ide
幾種經常使用編輯網卡方式:
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens160 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=dhcp DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens160 UUID=8beb0ae2-2d58-4788-83fd-41c86a16805a DEVICE=ens160 ONBOOT=yes
設備類型:TYPE=Ethernet
地址分配模式:BOOTPROTO=static
網卡名稱:NAME=ens160
是否啓動:ONBOOT=yes
IP地址:IPADDR=192.168.10.10
子網掩碼:NETMASK=255.255.255.0
網關地址:GATEWAY=192.168.10.1
DNS地址:DNS1=192.168.10.1
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens160 TYPE=Ethernet BOOTPROTO=static NAME=ens160 ONBOOT=yes IPADDR=192.168.0.15 NETMASK=255.255.255.0 GATEWAY=192.168.0.1 DNS1=192.168.0.1
[root@localhost ~]# nmcli connection reload ens160 [root@localhost ~]# nmcli connection up ens160 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6) [root@localhost ~]# ifconfig ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.15 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::20c:29ff:feba:9553 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:ba:95:53 txqueuelen 1000 (Ethernet) RX packets 2340 bytes 227911 (222.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1232 bytes 153389 (149.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# nmtui
[root@localhost ~]# nmcli connection reload ens160 [root@localhost ~]# nmcli connection up ens160 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6) [root@localhost ~]# ifconfig ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.15 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::20c:29ff:feba:9553 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:ba:95:53 txqueuelen 1000 (Ethernet) RX packets 2340 bytes 227911 (222.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1232 bytes 153389 (149.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# nm-connection-editor
[root@localhost ~]# nmcli connection up ens160 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7) [root@localhost ~]# ifconfig ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.15 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::20c:29ff:feba:9553 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:ba:95:53 txqueuelen 1000 (Ethernet) RX packets 4575 bytes 2999323 (2.8 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2712 bytes 347846 (339.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
紅帽8軟件數量不少,須要設置兩個yum源,分別是BaseOS和AppStream
紅帽8之前只須要定義一個yum源
[root@localhost ~]# cd /media/cdrom/ [root@localhost cdrom]# ls AppStream extra_files.json media.repo BaseOS GPL RPM-GPG-KEY-redhat-beta EFI images RPM-GPG-KEY-redhat-release EULA isolinux TRANS.TBL
光盤掛載方式
[root@localhost ~]# mkdir -p /media/cdrom [root@localhost ~]# mount /dev/cdrom /media/cdrom/ mount: /media/cdrom: WARNING: device write-protected, mounted read-only.
[root@localhost ~]# echo "/dev/cdrom /media/cdrom iso9660 defaults 0 0" >> /etc/fstab
[root@localhost cdrom]# ls AppStream extra_files.json media.repo BaseOS GPL RPM-GPG-KEY-redhat-beta EFI images RPM-GPG-KEY-redhat-release EULA isolinux TRANS.TBL
[root@localhost yum.repos.d]# cat mmx.repo [BaseOS] name=BaseOS baseurl=file:///media/cdrom/BaseOS enabled=1 gpgcheck=0 [AppStream] name=AppStream baseurl=file:///media/cdrom/AppStream enabled=1 gpgcheck=0
[root@localhost yum.repos.d]# dnf install httpd -y Updating Subscription Management repositories. Unable to read consumer identity This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. AppStream 16 MB/s | 5.3 MB 00:00 BaseOS 27 MB/s | 2.2 MB 00:00 Last metadata expiration check: 0:00:01 ago on Mon 19 Jul 2021 05:55:06 AM CST. Dependencies resolved. ========================================================================================= Package Arch Version Repository Size ========================================================================================= Installing: httpd x86_64 2.4.37-10.module+el8+2764+7127e69e AppStream 1.4 M Installing dependencies: apr x86_64 1.6.3-9.el8 AppStream 125 k apr-util x86_64 1.6.1-6.el8 AppStream 105 k httpd-filesystem noarch 2.4.37-10.module+el8+2764+7127e69e AppStream 34 k httpd-tools x86_64 2.4.37-10.module+el8+2764+7127e69e AppStream 101 k mod_http2 x86_64 1.11.3-1.module+el8+2443+605475b7 AppStream 156 k redhat-logos-httpd noarch 80.7-1.el8 BaseOS 25 k Installing weak dependencies: apr-util-bdb x86_64 1.6.1-6.el8 AppStream 25 k apr-util-openssl x86_64 1.6.1-6.el8 AppStream 27 k Enabling module streams: httpd 2.4 Transaction Summary ========================================================================================= Install 9 Packages Total size: 2.0 M Installed size: 5.4 M Downloading Packages: Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : apr-1.6.3-9.el8.x86_64 1/9 Running scriptlet: apr-1.6.3-9.el8.x86_64 1/9 Installing : apr-util-bdb-1.6.1-6.el8.x86_64 2/9 Installing : apr-util-openssl-1.6.1-6.el8.x86_64 3/9 Installing : apr-util-1.6.1-6.el8.x86_64 4/9 Running scriptlet: apr-util-1.6.1-6.el8.x86_64 4/9 Installing : httpd-tools-2.4.37-10.module+el8+2764+7127e69e.x86_64 5/9 Installing : redhat-logos-httpd-80.7-1.el8.noarch 6/9 Running scriptlet: httpd-filesystem-2.4.37-10.module+el8+2764+7127e69e.noarch 7/9 Installing : httpd-filesystem-2.4.37-10.module+el8+2764+7127e69e.noarch 7/9 Installing : mod_http2-1.11.3-1.module+el8+2443+605475b7.x86_64 8/9 Installing : httpd-2.4.37-10.module+el8+2764+7127e69e.x86_64 9/9 Running scriptlet: httpd-2.4.37-10.module+el8+2764+7127e69e.x86_64 9/9 Verifying : apr-1.6.3-9.el8.x86_64 1/9 Verifying : apr-util-1.6.1-6.el8.x86_64 2/9 Verifying : apr-util-bdb-1.6.1-6.el8.x86_64 3/9 Verifying : apr-util-openssl-1.6.1-6.el8.x86_64 4/9 Verifying : httpd-2.4.37-10.module+el8+2764+7127e69e.x86_64 5/9 Verifying : httpd-filesystem-2.4.37-10.module+el8+2764+7127e69e.noarch 6/9 Verifying : httpd-tools-2.4.37-10.module+el8+2764+7127e69e.x86_64 7/9 Verifying : mod_http2-1.11.3-1.module+el8+2443+605475b7.x86_64 8/9 Verifying : redhat-logos-httpd-80.7-1.el8.noarch 9/9 Installed products updated. Installed: httpd-2.4.37-10.module+el8+2764+7127e69e.x86_64 apr-util-bdb-1.6.1-6.el8.x86_64 apr-util-openssl-1.6.1-6.el8.x86_64 apr-1.6.3-9.el8.x86_64 apr-util-1.6.1-6.el8.x86_64 httpd-filesystem-2.4.37-10.module+el8+2764+7127e69e.noarch httpd-tools-2.4.37-10.module+el8+2764+7127e69e.x86_64 mod_http2-1.11.3-1.module+el8+2443+605475b7.x86_64 redhat-logos-httpd-80.7-1.el8.noarch Complete!
防火牆策略能夠基於流量的源目地址、端口號、協議、應用等信息來定製,而後防火牆使用預先定製的策略規則監控出入的流量,若流量與某一條策略規則相匹配,則執行相應的處理,反之則丟棄。