Linux 基础入门 09
一、REHL8 WEB控制臺管理系統
登錄一臺服務器有哪些方法:
本地登錄、VNC、XSHELL、web控制臺登錄
1.1 什么是web控制臺
web控制臺是一個基于web的紅帽企業版Linux8界面,用于管理和監控本地系統及位于網絡環境中的linux服務器
RHEL的web控制臺是交互式服務器管理界面,可以直接通過瀏覽器與真實的linux操作系統進行直接交互。
1.2 web控制臺可以做什么
(1)監控基本系統功能,例如硬件信息,時間配置,性能配置等
(2)檢查系統日志文件
(3)管理網絡接口和配置防火墻
(4)管理虛擬機
(5)管理用戶帳戶
(6)監視和配置系統服務
(7)管理軟件包
(8)配置SELinux
(9)更新軟件
(10)訪問終端
1.3 操作步驟
服務器開機,有網絡,可以連接公網
先檢查自己的服務器是否默認安裝了這個服務 cockpit
[root@wentan ~]# yum list | grep cockpit #RHEL8 默認已經安裝了cocpit這個服務 cockpit.x86_64 185-2.el8 @anaconda cockpit-bridge.x86_64 185-2.el8 @anaconda cockpit-packagekit.noarch 184.1-1.el8 @AppStream cockpit-storaged.noarch 184.1-1.el8 @AppStream cockpit-system.noarch 185-2.el8 @anaconda cockpit-ws.x86_64 185-2.el8 @anaconda subscription-manager-cockpit.noarch 1.23.8-35.el8 @anaconda cockpit.x86_64 251.1-1.el8 base cockpit-bridge.x86_64 251.1-1.el8 base cockpit-composer.noarch 31.1-1.el8 AppStream cockpit-doc.noarch 251.1-1.el8 base cockpit-machines.noarch 251.1-1.el8 AppStream cockpit-packagekit.noarch 251.1-1.el8 AppStream cockpit-pcp.x86_64 251.1-1.el8 AppStream cockpit-podman.noarch 33-1.module_el8.5.0+890+6b136101 AppStream cockpit-session-recording.noarch 7-2.el8 AppStream cockpit-storaged.noarch 251.1-1.el8 AppStream cockpit-system.noarch 251.1-1.el8 base cockpit-ws.x86_64 251.1-1.el8 base subscription-manager-cockpit.noarch 1.28.21-3.el8 base #檢查cockpit是否開機自動啟動,發現cockpit.socket 是disable狀態 [root@wentan ~]# systemctl list-unit-files | grep cockpit cockpit-motd.service static cockpit.service static cockpit.socket disabled #啟動cockpit這個服務 [root@wentan ~]# systemctl start cockpit.socket [root@wentan ~]# systemctl enable cockpit.socket Created symlink /etc/systemd/system/sockets.target.wants/cockpit.socket → /usr/lib/systemd/system/cockpit.socket.#啟動cockpit.service服務 [root@wentan ~]# systemctl start cockpit.service [root@wentan ~]# systemctl status cockpit.service ● cockpit.service - Cockpit Web ServiceLoaded: loaded (/usr/lib/systemd/system/cockpit.service; static; vendor preset:>Active: active (running) since Wed 2022-01-19 10:41:40 CST; 17s agoDocs: man:cockpit-ws(8)Process: 8226 ExecStartPre=/usr/sbin/remotectl certificate --ensure --user=root >Main PID: 8230 (cockpit-ws)Tasks: 2 (limit: 23861)Memory: 2.8MCGroup: /system.slice/cockpit.service└─8230 /usr/libexec/cockpit-ws防火墻策略:
可以關閉系統防火墻或者選擇防火墻放行
RHEL8系統默認已經放行了cockpit服務
firewall-cmd --add-service=cockpit --permanent firewall-cmd --reload #重載以生效這個規則最后RHEL系統的web控制臺的地址為服務器ip地址的9090端口
192.168.253.128:9090 (服務器地址)
輸入用戶密碼登錄
二、日志系統 RSYSLOG
使用了日志消息類型和優先級來確定到底如何處理
日志系統的配置文件: /etc/rsyslog.conf
2.1 日志消息的類型:
| lpr | 打印相關的日志 |
| auth | 認證相關的日志 |
| user | 用戶相關的日志 |
| cron | 計劃任務相關的日志 |
| kern | 內核相關的日志 |
| 郵件相關的日志 | |
| daemon | 系統服務相關的日志 |
| authpri | 授權相關的日志 |
| security | 安全相關的日志 |
2.2 日志消息的優先級
從高到低 8個標準
| none | 無 | 不記錄任何信息 |
| EMERG | 級別 0 | 緊急,系統本身已經無法再運行必須馬上拯救 |
| ALERT | 級別 1 | 警報,系統出現了重大錯誤必須馬上處理的情況 |
| CRIT | 級別 2 | 嚴重,系統出現了嚴重的情況 |
| ERROR | 級別 3 | 錯誤,系統出現了錯誤的情況 |
| WARNING | 級別 4 | 警告,系統出現了需要警告的情況 |
| NOTICE | 級別 5 | 注意,系統出現了需要注意的情況 |
| INFO | 級別 6 | 信息,系統出現了一些情況 |
| DEBUG | 級別 7 | 調試,系統出現了程序或服務調試的情況 |
2.3 日志信息里的內容
(1)會記錄日志發生的時間
(2)發送該日志消息的主機
(3)發送該日志消息的程序,哪個PID
(4)日志消息的主內容
三、ISCSI 實驗
首先需要兩臺虛擬機,恢復初始化狀態
一臺命名為SAN-server 一臺命名為SAN-client
安裝yum 源,關閉防火墻,同時ISCSI需要額外安裝一塊硬盤
3.1 服務端配置
#服務端 [root@wentan ~]# hostnamectl set-hostname SAN-server [root@wentan ~]# bash #接下來需要安裝ISCSI的工具 [root@SAN-server ~]# yum install -y targetcli [root@SAN-server ~]# systemctl enable target Created symlink /etc/systemd/system/multi-user.target.wants/target.service → /usr/lib/systemd/system/target.service. [root@SAN-server ~]# systemctl start target#分區選擇一塊共享給SAN客戶 [root@SAN-server ~]# fdisk /dev/nvme0n2Welcome to fdisk (util-linux 2.32.1). 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. Created a new DOS disklabel with disk identifier 0x31fc34c5.Command (m for help): n Partition typep primary (0 primary, 0 extended, 4 free)e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-41943039, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +10GCreated a new partition 1 of type 'Linux' and of size 10 GiB.Command (m for help): p Disk /dev/nvme0n2: 20 GiB, 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 Disklabel type: dos Disk identifier: 0x31fc34c5Device Boot Start End Sectors Size Id Type /dev/nvme0n2p1 2048 20973567 20971520 10G 83 LinuxCommand (m for help): mHelp:DOS (MBR)a toggle a bootable flagb edit nested BSD disklabelc toggle the dos compatibility flagGenericd delete a partitionF list free unpartitioned spacel list known partition typesn add a new partitionp print the partition tablet change a partition typev verify the partition tablei print information about a partitionMiscm print this menuu change display/entry unitsx extra functionality (experts only)ScriptI load disk layout from sfdisk script fileO dump disk layout to sfdisk script fileSave & Exitw write table to disk and exitq quit without saving changesCreate a new labelg create a new empty GPT partition tableG create a new empty SGI (IRIX) partition tableo create a new empty DOS partition tables create a new empty Sun partition tableCommand (m for help): t Selected partition 1 Hex code (type L to list all codes): l0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-3 XENIX usr 3c PartitionMagic 84 OS/2 hidden or c6 DRDOS/sec (FAT-4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx 5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data 6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility 8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt 9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi ea Rufus alignmente W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD eb BeOS fs f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ee GPT 10 OPUS 55 EZ-Drive a7 NeXTSTEP ef EFI (FAT-12/16/ 11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f0 Linux/PA-RISC b 12 Compaq diagnost 5c Priam Edisk a9 NetBSD f1 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f4 SpeedStor 16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ f2 DOS secondary 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fb VMware VMFS 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fc VMware VMKCORE 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fd Linux raid auto 1c Hidden W95 FAT3 75 PC/IX bc Acronis FAT32 L fe LANstep 1e Hidden W95 FAT1 80 Old Minix be Solaris boot ff BBT Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM'.Command (m for help): p Disk /dev/nvme0n2: 20 GiB, 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 Disklabel type: dos Disk identifier: 0x31fc34c5Device Boot Start End Sectors Size Id Type /dev/nvme0n2p1 2048 20973567 20971520 10G 8e Linux LVMCommand (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.[root@SAN-server ~]# pvcreate /dev/nvme0n2p1Physical volume "/dev/nvme0n2p1" successfully created. [root@SAN-server ~]# vgcreate iscsi_vg /dev/nvme0n2p1 Volume group "iscsi_vg" successfully created [root@SAN-server ~]# lvcreate -n iscsi_store -l 100%VG iscsi_vgLogical volume "iscsi_store" created.#接下來通過targetcli 工具來做SAN網絡共享 [root@SAN-server ~]# targetcli Warning: Could not load preferences file /root/.targetcli/prefs.bin. targetcli shell version 2.1.53 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'./> backstores/block create name=iscsi_store dev=/dev/iscsi_vg/iscsi_store Created block storage object iscsi_store using /dev/iscsi_vg/iscsi_store./> iscsi/ create iqn.2022-01.com.example:iscsi.server Created target iqn.2022-01.com.example:iscsi.server. Created TPG 1. Global pref auto_add_default_portal=true Created default portal listening on all IPs (0.0.0.0), port 3260./> cd iscsi/iqn.2022-01.com.example:iscsi.server/ /iscsi/iqn.20...:iscsi.server> cd tpg1/ /iscsi/iqn.20...i.server/tpg1> luns/ create /backstores/block/iscsi_store Created LUN 0./iscsi/iqn.20...i.server/tpg1> acls/ create iqn.2022-01.com.example:iscsi.client Created Node ACL for iqn.2022-01.com.example:iscsi.client Created mapped LUN 0./iscsi/iqn.20...i.server/tpg1> portals/ create 192.168.253.128 3260 Using default IP port 3260 Could not create NetworkPortal in configFS/iscsi/iqn.20...i.server/tpg1> set attribute authentication=0 Parameter authentication is now '0'. /iscsi/iqn.20...i.server/tpg1> set attribute generate_node_acls=0 Parameter generate_node_acls is now '0'./iscsi/iqn.20...i.server/tpg1> cd .. /iscsi/iqn.20...:iscsi.server> cd .. /iscsi> cd .. /> saveconfig Configuration saved to /etc/target/saveconfig.json /> exit Global pref auto_save_on_exit=true Last 10 configs saved in /etc/target/backup/. Configuration saved to /etc/target/saveconfig.json[root@SAN-server ~]# targetcli targetcli shell version 2.1.53 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'./> ls o- / ........................................................................ [...]o- backstores ............................................................. [...]| o- block ................................................. [Storage Objects: 1]| | o- iscsi_store ... [/dev/iscsi_vg/iscsi_store (10.0GiB) write-thru activated]| | o- alua .................................................. [ALUA Groups: 1]| | o- default_tg_pt_gp ...................... [ALUA state: Active/optimized]| o- fileio ................................................ [Storage Objects: 0]| o- pscsi ................................................. [Storage Objects: 0]| o- ramdisk ............................................... [Storage Objects: 0]o- iscsi ........................................................... [Targets: 1]| o- iqn.2022-01.com.example:iscsi.server ............................. [TPGs: 1]| o- tpg1 .............................................. [no-gen-acls, no-auth]| o- acls ......................................................... [ACLs: 1]| | o- iqn.2022-01.com.example:iscsi.client ................ [Mapped LUNs: 1]| | o- mapped_lun0 .......................... [lun0 block/iscsi_store (rw)]| o- luns ......................................................... [LUNs: 1]| | o- lun0 [block/iscsi_store (/dev/iscsi_vg/iscsi_store) (default_tg_pt_gp)]| o- portals ................................................... [Portals: 1]| o- 0.0.0.0:3260 .................................................... [OK]o- loopback ........................................................ [Targets: 0] /> exit3.2 客戶端配置
#客戶端 [root@wentan ~]# hostnamectl set-hostname SAN-client [root@wentan ~]# bash #安裝iscsi看客戶端初始化工具 [root@SAN-client ~]# yum install -y iscsi-initiator-utils[root@SAN-client ~]# vim /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.2022-01.com.example:iscsi.client#接下來允許iscsi服務,開啟iscsi服務 [root@SAN-client ~]# systemctl enable iscsi iscsid.service Created symlink /etc/systemd/system/remote-fs.target.wants/iscsi.service → /usr/lib/systemd/system/iscsi.service. Created symlink /etc/systemd/system/multi-user.target.wants/iscsid.service → /usr/lib/systemd/system/iscsid.service. [root@SAN-client ~]# systemctl start iscsi iscsid.service #接下來通過iscsi的發現機制 來發現對方ip地址是否有共享給我的存儲 [root@SAN-client ~]# iscsiadm -m discovery -t st -p 192.168.253.128 192.168.253.128:3260,1 iqn.2022-01.com.example:iscsi.server#選擇自動的掛上SAN [root@SAN-client ~]# iscsiadm -m node -l Logging in to [iface: default, target: iqn.2022-01.com.example:iscsi.server, portal: 192.168.253.128,3260] Login to [iface: default, target: iqn.2022-01.com.example:iscsi.server, portal: 192.168.253.128,3260] successful.#接下來發現這塊設備,發現名字為sda 大小為10G [root@SAN-client ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 10G 0 disk sr0 11:0 1 1024M 0 rom nvme0n1 259:0 0 25G 0 disk ├─nvme0n1p1 259:1 0 1G 0 part /boot └─nvme0n1p2 259:2 0 24G 0 part ├─rhel-root 253:0 0 22G 0 lvm /└─rhel-swap 253:1 0 2G 0 lvm [SWAP]#我們需要對這塊硬盤做分區 [root@SAN-client ~]# fdisk /dev/sda Welcome to fdisk (util-linux 2.32.1). 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. Created a new DOS disklabel with disk identifier 0x80e3c182.Command (m for help): n Partition typep primary (0 primary, 0 extended, 4 free)e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-20963327, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-20963327, default 20963327): +5GCreated a new partition 1 of type 'Linux' and of size 5 GiB.Command (m for help): p Disk /dev/sda: 10 GiB, 10733223936 bytes, 20963328 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 1048576 bytes Disklabel type: dos Disk identifier: 0x80e3c182Device Boot Start End Sectors Size Id Type /dev/sda1 2048 10487807 10485760 5G 83 LinuxCommand (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.#把分區做成文件系統 ext4格式 [root@SAN-client ~]# mkfs.ext4 /dev/sda1 mke2fs 1.44.3 (10-July-2018) Creating filesystem with 1310720 4k blocks and 327680 inodes Filesystem UUID: ac62797b-da6c-4bf3-a09b-7808b6081ebf Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done#編輯自動掛載列表 [root@SAN-client ~]# vim /etc/fstab /dev/sda1 /SAN ext4 defaults 0 0 [root@SAN-client ~]# mkdir /SAN [root@SAN-client ~]# mount -a [root@SAN-client ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs tmpfs 1.9G 10M 1.9G 1% /run tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/mapper/rhel-root xfs 22G 4.2G 18G 19% / /dev/nvme0n1p1 xfs 1014M 169M 846M 17% /boot tmpfs tmpfs 376M 16K 376M 1% /run/user/42 tmpfs tmpfs 376M 4.6M 372M 2% /run/user/1000 tmpfs tmpfs 376M 4.0K 376M 1% /run/user/0 /dev/sda1 ext4 4.9G 20M 4.6G 1% /SAN#到這里就全都成功了四、歸檔和(解)壓縮
歸檔和壓縮的區別
歸檔就是把多個文件歸到一起,他不是壓縮,并不能壓縮大小
4.1 歸檔
tar -cvf 歸檔文件夾名 歸檔文件1 歸檔文件2 tar -cvf txt 123.txt 12.txt 解檔:tar -xvf 文檔名4.2 壓縮
gzip bzip兩種壓縮方法
Gzip:壓縮速度快 壓縮效率高 tar -zvcf
Bzip:壓縮速率慢 壓縮比例高 節省空間 tar -jvcf
[root@SAN-server dwt]# tar -zvcf gd.tar.gz test.pdf 222.txt 321.txt test.pdf 222.txt 321.txt [root@SAN-server dwt]# tar -jvcf gd.tar.bz test.pdf 222.txt 321.txt test.pdf 222.txt 321.txt [root@SAN-server dwt]# ll total 7796 -rw-r--r--. 1 root root 13 Jan 15 11:23 222.txt -rwxrw-r-x+ 1 root wentan 240 Jan 11 11:43 321.txt drwxr-xr-x. 2 root root 6 Jan 11 11:04 back drwxr-xr-x. 2 root root 22 Jan 8 15:21 etc -rw-r--r--. 1 root root 2642757 Jan 19 16:00 gd.tar.bz -rw-r--r--. 1 root root 2631479 Jan 19 15:59 gd.tar.gz drwxr-xr-x. 2 root root 6 Jan 19 15:54 test -rw-r--r--. 1 root root 2692317 Jan 19 15:51 test.pdf4.3 解壓縮
Gzip: tar -zvxf 壓縮包名
Bzip: tar -jvxf 壓縮包名
[root@SAN-server dwt]# ll total 5156 drwxr-xr-x. 2 root root 6 Jan 11 11:04 back drwxr-xr-x. 2 root root 22 Jan 8 15:21 etc -rw-r--r--. 1 root root 2642757 Jan 19 16:00 gd.tar.bz -rw-r--r--. 1 root root 2631479 Jan 19 15:59 gd.tar.gz drwxr-xr-x. 2 root root 6 Jan 19 15:54 test [root@SAN-server dwt]# tar -zvxf gd.tar.gz test.pdf 222.txt 321.txt [root@SAN-server dwt]# ll total 7796 -rw-r--r--. 1 root root 13 Jan 15 11:23 222.txt -rwxrw-r-x. 1 root wentan 240 Jan 11 11:43 321.txt drwxr-xr-x. 2 root root 6 Jan 11 11:04 back drwxr-xr-x. 2 root root 22 Jan 8 15:21 etc -rw-r--r--. 1 root root 2642757 Jan 19 16:00 gd.tar.bz -rw-r--r--. 1 root root 2631479 Jan 19 15:59 gd.tar.gz drwxr-xr-x. 2 root root 6 Jan 19 15:54 test -rw-r--r--. 1 root root 2692317 Jan 19 15:51 test.pdf不管是壓縮還是歸檔都是:
壓縮命令+ 壓縮后文件包的名+ 需要壓縮的文件(可以好多個)
建議GZIP文件是以tar.gz結尾
BZIP文件是以tar.bz結尾
五、Linux內核
內核就是操作系統的核心部分
5.1 redhat內核的功能:
1.系統初始化:檢測硬件資源并啟動系統
2.進程調度 : 決定進程什么時候運行,以及運行多久
3.內存管理: 給運行的進程分配內存
4.安全:支持權限,支持selinux ,支持防火墻 支持iptables
5.支持標準網絡,文件系統
具體可以參考kernel-doc
5.2 內核的組成
多個內核版本可以共存的
內核的組成如下
/boot/vmlinuz-4.18.0-80.el8.x86_64 啟動時用到的內核
/boot/initramfs-4.18.0-80.el8.x86_64.img 啟動時提供必要模塊的內核
/lib/modules/版本/內核模塊
5.3 虛擬的文件系統/proc
進程信息 /proc/PID(數字)
cpu信息 /proc/cpuinfo
內存資料 /proc/meminfo
磁盤信息 /proc/partition
5.4 sysctl 配置內核參數
當前生效的內核配置參數都在 /pro/sys/
內核參數配置文件 /etc/sysctl.conf 系統啟動時讀取的參數
sysctl -a 顯示所有的內核模塊
一定要結合grep來使用
5.5 內核模塊
內核模塊: /lib/modules/內核版本
內核模塊的相關命令:
lsmod 查看內核已經加載的模塊
modinfo 模塊名 查看這個模塊的詳細信息
視頻講解在微信公眾號 問渠清源 回復關鍵詞 視頻 即可觀看
總結
以上是生活随笔為你收集整理的Linux 基础入门 09的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 工作学会9句话,升职加薪变股东
- 下一篇: 西游记中孙悟空所尊敬的神佛