您好,登錄后才能下訂單哦!
Linux
文件系統在處理 Linux
系統出現的各種故障時,故障的癥狀是最易發現的,而導致這一故障的原因才是最終排除故障的關鍵。熟悉 Linux
系統中常見的日志文件,了解一般故障的分析與解決辦法,將有助于管理員快速定位故障點、“對癥下藥”、并及時解決各種系統問題。
inode
與 block
詳解文件存儲再硬盤上,硬盤最小存儲單位是“扇區”,每個扇區存儲512字節
文件數據包括元信息與實際數據
元信息包含文件屬性信息,文件打開來輸入的內容為實際數據
block
(塊)
inode
(索引節點)
inode
的內容inode
包含文件的元信息User ID
Group ID
stat
命令查看inode
信息[root@localhost mnt]# stat abc.txt //查看abc文件inode信息
文件:"abc.txt"
大小:12 塊:8 IO 塊:4096 普通文件
設備:802h/2050d Inode:18123362 硬鏈接:1
權限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
環境:unconfined_u:object_r:mnt_t:s0
最近訪問:2019-09-02 04:12:18.210370997 +0800
最近更改:2019-09-02 04:12:18.210370997 +0800
最近改動:2019-09-02 04:12:18.210370997 +0800
創建時間:-
Linux
系統文件三個主要的時間屬性ctime(change time)
:最后一次改變文件或目錄(屬性)的時間atime
(access time):最后一次訪問文件或目錄的時間mtime(modify time)
:最后一次修改文件或目錄(內容)的時間inode
都有一個號碼,操作系統用inode
號碼來識別不同的文件inode
號命來識別文件inode
號碼便于識別的別稱inode
的號碼用戶通過文件名打開文件時,系統內部的過程
inode
號碼inode
號碼,獲取inode
信息inode
信息,找到文件數據所在的block
,讀出數據inode
號碼的方法
ls -i
命令:查看文件名對應的inde
號碼[root@localhost mnt]# ls -i abc.txt //查看文件節點信息
18123362 abc.txt
inode
的大小inode也會消耗硬盤空間,每個inode的大小,一般時128字節或256字節
格式化文件系統時確定inode的總數
[root@localhost mnt]# df -i //查看分區節點信息
文件系統 Inode 已用(I) 可用(I) 已用(I)% 掛載點
/dev/sda2 10485760 121203 10364557 2% /
devtmpfs 229708 376 229332 1% /dev
tmpfs 233381 1 233380 1% /dev/shm
tmpfs 233381 560 232821 1% /run
tmpfs 233381 16 233365 1% /sys/fs/cgroup
/dev/sda5 5241856 146 5241710 1% /home
/dev/sda1 3145728 328 3145400 1% /boot
tmpfs 233381 6 233375 1% /run/user/42
tmpfs 233381 17 233364 1% /run/user/0
/dev/sr0 0 0 0 - /run/media/root/CentOS 7 x86_64
inode
的特殊作用inode
號碼與文件名分離,導致一些Linux
系統具有以下的現象
inode
,也可以刪除文件find ./* -inum [節點號] -delete
[root@localhost mnt]# ls -i
16777284 ac1.txt 18123362 ac2.txt 18123366 ac3.txt 18123370 ac4.txt 18123371 ac5.txt
[root@localhost mnt]# find ./* -inum 16777284 -delete
[root@localhost mnt]# ls -i
18123362 ac2.txt 18123366 ac3.txt 18123370 ac4.txt 18123371 ac5.txt
inode
號碼[root@localhost mnt]# ls -i
18123362 ac2.txt 18123366 ac3.txt 18123370 ac4.txt 18123371 ac5.txt
[root@localhost mnt]# mv ac2.txt /opt
[root@localhost mnt]# ls -i /opt
18123362 ac2.txt 1389838 rh
inode
號碼來識別該文件,不再考慮文件名xfs
類型文件備份和恢復xfs
文件的恢復需要我們先把文件備份到另一塊磁盤,當文件損壞時可以通過備份的文件進行恢復(這里面的備份文件是通過對文件做固定格式的壓縮來進行備份)。
xfs
類型的文件可使用 xfsdump
與 xfsrestore
工具進行備份恢復。若系統中未安裝xfsdump
與 xfsrestore
工具,可以通過yum來安裝工具。[root@localhost mnt]# yum install xfsdump -y
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
正在解決依賴關系
--> 正在檢查事務
---> 軟件包 xfsdump.x86_64.0.3.1.4-1.el7 將被 升級
---> 軟件包 xfsdump.x86_64.0.3.1.7-1.el7 將被 更新
...//省略部分內容...
命令格式
xfsdump -f 備份存放位置 要備份的路徑或設備文件
xfsdump
的備份級別有兩種
0
:表示完全備份(默認為0)1~9
:表示增量備份-f
:指定備份文件目錄-L
:指定標簽 session label-M
:指定設備標簽 media label-s
:備份單個文件,-s 后面不能直接跟路徑。 [root@localhost ~]# fdisk /dev/sdb //創建新磁盤
歡迎使用 fdisk (util-linux 2.23.2)。
更改將停留在內存中,直到您決定將更改寫入磁盤。
使用寫入命令前請三思。
Device does not contain a recognized partition table
使用磁盤標識符 0x57599cea 創建新的 DOS 磁盤標簽。
命令(輸入 m 獲取幫助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
分區號 (1-4,默認 1):
起始 扇區 (2048-41943039,默認為 2048):
將使用默認值 2048
Last 扇區, +扇區 or +size{K,M,G} (2048-41943039,默認為 41943039):
將使用默認值 41943039
分區 1 已設置為 Linux 類型,大小設為 20 GiB
命令(輸入 m 獲取幫助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盤。
[root@localhost ~]# mkfs.xfs /dev/sdb1 //格式化磁盤
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=1310656 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=5242624, 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=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]# mkdir /opt/data //創建掛載點
[root@localhost ~]# mount /dev/sdb1 /opt/data //掛載創建的磁盤
[root@localhost ~]# cp /etc/passwd /opt/data //將passwdd目錄復制到掛載的磁盤中
[root@localhost ~]# ls /opt/data //查看文件
passwd
[root@localhost ~]# xfsdump -f /mnt/xfs_dump /dev/sdb1 //使用命令備份文件
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control
============================= dump label dialog ==============================
please enter label for this dump session (timeout in 300 sec)
-> xfs_dump //輸入備份的文件名
session label entered: "xfs_dump"
--------------------------------- end dialog ---------------------------------
xfsdump: level 0 dump of localhost.localdomain:/opt/data
xfsdump: dump date: Mon Sep 2 05:27:29 2019
xfsdump: session id: 96c17954-e969-4041-9d9e-4bd59746ddab
xfsdump: session label: "xfs_dump"
xfsdump: ino map phase 1: constructing initial dump list
xfsdump: ino map phase 2: skipping (no pruning necessary)
xfsdump: ino map phase 3: skipping (only one dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 25216 bytes
xfsdump: /var/lib/xfsdump/inventory created
============================= media label dialog =============================
please enter label for media in drive 0 (timeout in 300 sec)
-> sdb1 //輸入要備份設備
media label entered: "sdb1"
--------------------------------- end dialog ---------------------------------
xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping ino map
xfsdump: dumping directories
xfsdump: dumping non-directory files
xfsdump: ending media file
xfsdump: media file size 24264 bytes
xfsdump: dump size (non-dir files) : 2592 bytes
xfsdump: dump complete: 13 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /mnt/xfs_dump OK (success)
xfsdump: Dump Status: SUCCESS //備份成功
[root@localhost ~]# rm -rf /opt/data/* //刪除磁盤中文件
[root@localhost ~]# ls /opt/data //查看文件是否刪除
[root@localhost ~]# xfsrestore -f /mnt/xfs_dump /opt/data //執行命令恢復文件
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.7 (dump format 3.0) - type ^C for status and control
xfsrestore: searching media for dump
xfsrestore: examining media file 0
xfsrestore: dump description:
xfsrestore: hostname: localhost.localdomain
xfsrestore: mount point: /opt/data
xfsrestore: volume: /dev/sdb1
xfsrestore: session time: Mon Sep 2 05:27:29 2019
xfsrestore: level: 0
xfsrestore: session label: "xfs_dump"
xfsrestore: media label: "sdb1"
xfsrestore: file system id: 2e3df4e8-dd92-46f7-84ca-f254c4e579bd
xfsrestore: session id: 96c17954-e969-4041-9d9e-4bd59746ddab
xfsrestore: media id: d27aafc8-a405-4a8f-b7f0-1a018a7026ee
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 1 directories and 1 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 0 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore: stream 0 /mnt/xfs_dump OK (success)
xfsrestore: Restore Status: SUCCESS
[root@localhost ~]# ls /opt/data //查看文件是否恢復
passwd //成功恢復文件
xfsdump
使用的限制
root
的權限才能操作XFS
文件系統xfsrestore
解析UUID
的文件系統內核及系統日志
syslog
統一進行管理,日志格式基本相似用戶日志
/var/log
目錄下內核及公共消息日志:/var/log/messages
計劃任務日志:/var/log/cron
系統引導日志:/var/log/dmesg
郵件系統日志:/var/log/maillog
/var/log/lastlog
、 /var/log/secure
、 /var/log/wtmp
、 /var/run/btmp
rsyslogd
統一管理
reyelog-7.4.7-16.el7.x86_64
/sbin/rsyslogd
/etc/rsyslog.conf
[root@localhost ~]# vim /etc/rsyslog.conf //查看日志文件配置信息
# rsyslog configuration file
# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html
#### MODULES ####
# The imjournal module bellow is now used as a message source instead of imuxsock.
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imjournal # provides access to the systemd journal
#$ModLoad imklog # reads kernel messages (the same are read from journald)
#$ModLoad immark # provides --MARK-- message capability
# Provides UDP syslog reception
#$ModLoad imudp
#$UDPServerRun 514
# Provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun 514
#### GLOBAL DIRECTIVES ####
# Where to place auxiliary files
$WorkDirectory /var/lib/rsyslog
# Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
...//省略部分內容...
[root@localhost ~]# cd /var/log //查看日志文件目錄
[root@localhost log]# ls
anaconda dmesg libvirt rhsm tallylog Xorg.0.log
audit dmesg.old maillog sa tuned Xorg.0.log.old
boot.log firewalld messages samba vmware-vgauthsvc.log.0 Xorg.1.log
btmp gdm ntpstats secure vmware-vmsvc.log Xorg.9.log
chrony glusterfs pluto speech-dispatcher vmware-vmusr.log yum.log
cron grubby_prune_debug ppp spooler wpa_supplicant.log
cups lastlog qemu-ga sssd wtmp
查看系統日志文件
[root@localhost log]# vim messages //查看系統日志文件
Aug 10 03:53:40 localhost journal: Runtime journal is using 8.0M (max allowed 91.1M, trying to leave 136.7M free of 903.6M available → current limit 91.1M).
Aug 10 03:53:40 localhost kernel: Initializing cgroup subsys cpuset
Aug 10 03:53:40 localhost kernel: Initializing cgroup subsys cpu
Aug 10 03:53:40 localhost kernel: Initializing cgroup subsys cpuacct
Aug 10 03:53:40 localhost kernel: Linux version 3.10.0-693.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ) #1 SMP Tue Aug 22 21:09:27 UTC 2017
Aug 10 03:53:40 localhost kernel: Command line: BOOT_IMAGE=/vmlinuz-3.10.0-693.el7.x86_64 root=UUID=729c9a26-dfdc-40f9-ae91-1ade55be51bb ro crashkernel=auto rhgb quiet LANG=zh_CN.UTF-8
Aug 10 03:53:40 localhost kernel: Disabled fast string operations
Aug 10 03:53:40 localhost kernel: e820: BIOS-provided physical RAM map:
Aug 10 03:53:40 localhost kernel: BIOS-e820: [mem 0x0000000000000000-0x000000000009ebff] usable
Aug 10 03:53:40 localhost kernel: BIOS-e820: [mem 0x000000000009ec00-0x000000000009ffff] reserved
Aug 10 03:53:40 localhost kernel: BIOS-e820: [mem 0x00000000000dc000-0x00000000000fffff] reserved
...//省略部分內容...
last
命令查看用戶登錄日志[root@localhost log]# last
root pts/0 192.168.144.1 Mon Sep 2 05:17 still logged in
reboot system boot 3.10.0-693.el7.x Mon Sep 2 05:17 - 05:58 (00:40)
root pts/0 192.168.144.1 Mon Sep 2 04:11 - crash (01:05)
root :0 :0 Mon Sep 2 04:11 - crash (01:05)
reboot system boot 3.10.0-693.el7.x Mon Sep 2 04:10 - 05:58 (01:47)
root pts/0 :0 Sun Aug 25 01:10 - 01:10 (00:00)
root :0 :0 Sun Aug 25 01:10 - crash (8+03:00)
...//省略部分內容...
lastb
查看用戶登錄次數日志[root@localhost log]# lastb
root :0 :0 Sun Aug 25 01:10 - 01:10 (00:00)
root :1 :1 Sat Aug 10 06:26 - 06:26 (00:00)
btmp begins Sat Aug 10 06:26:22 2019
查看程序日志文件
1、安裝httpd服務,搭建Apache網站服務;然后關閉防火墻,使宿主機可以訪問
[root@localhost ~]# yum install httpd -y //安裝httpd服務
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
正在解決依賴關系
--> 正在檢查事務
---> 軟件包 httpd.x86_64.0.2.4.6-89.el7.centos.1 將被 安裝
...//省略部分內容...
[root@localhost ~]# systemctl start httpd //開啟服務
[root@localhost ~]# systemctl stop firewalld.service //關閉防火墻
[root@localhost ~]# setenforce 0
[root@localhost ~]# cd /var/log //查看日志文件目錄,看是否生成httpd日志聞文件目錄
[root@localhost log]# ls
anaconda dmesg lastlog qemu-ga sssd wtmp
audit dmesg.old libvirt rhsm tallylog Xorg.0.log
boot.log firewalld maillog sa tuned Xorg.0.log.old
btmp gdm messages samba vmware-vgauthsvc.log.0 Xorg.1.log
chrony glusterfs ntpstats secure vmware-vmsvc.log Xorg.9.log
cron grubby_prune_debug pluto speech-dispatcher vmware-vmusr.log yum.log
cups httpd ppp spooler wpa_supplicant.log
2、通過宿主機訪問搭建的網站后,查看系統程序的日志文件
[root@localhost log]# cd httpd //進入httpd程序目錄
[root@localhost httpd]# ls
access_log error_log
[root@localhost httpd]# vim access_log //查看程序日志文件
192.168.144.1 - - [02/Sep/2019:06:12:48 +0800] "GET /noindex/css/bootstrap.min.css HTTP/1.1" 200 19341 "http://192.168.144.133/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"
192.168.144.1 - - [02/Sep/2019:06:12:48 +0800] "GET /noindex/css/open-sans.css HTTP/1.1" 200 5081 "http://192.168.144.133/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"
192.168.144.1 - - [02/Sep/2019:06:12:48 +0800] "GET /images/apache_pb.gif HTTP/1.1" 200 2326 "http://192.168.144.133/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"
192.168.144.1 - - [02/Sep/2019:06:12:48 +0800] "GET /images/poweredby.png HTTP/1.1" 200 3956 "http://192.168.144.133/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"
192.168.144.1 - - [02/Sep/2019:06:12:48 +0800] "GET /noindex/css/fonts/Light/OpenSans-Light.woff HTTP/1.1" 404 241 "http://192.168.144.133/noindex/css/open-sans.css" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"
192.168.144.1 - - [02/Sep/2019:06:12:48 +0800] "GET /noindex/css/fonts/Bold/OpenSans-Bold.woff HTTP/1.1" 404 239 "http://192.168.144.133/noindex/css/open-sans.css" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"
192.168.144.1 - - [02/Sep/2019:06:12:48 +0800] "GET /noindex/css/fonts/Bold/OpenSans-Bold.ttf HTTP/1.1" 404 238 "http://192.168.144.133/noindex/css/open-sans.css" "Mozilla/5.0 (Windows NT 10.0; Win64; x64)
將服務器的日志文件發到統一的日志文件服務器
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。