linux "October" - the file system and log analysis

Content Highlights:

  • inode与block

  • Hard links and soft links

  • Classification of the log file

  • User logs and logs


A, inode and block

1, inode and block Overview

  • File data includes meta-information and the actual data

  • File is stored on the hard disk, the hard disk storage unit is the smallest "sectors", each sector stores 512 bytes

  • Block (Block)

    A continuous block of eight sectors

    It is the smallest unit of file access

  • Inode (inode)

    Chinese translation of "inode", also known as i-node

    Used to store the files meta information

A file must occupy one inode, but at least occupy a block


2, inode file contains the information of the cloud

  • Number of bytes in the file

  • User ID file owner

  • Group ID documents

  • Read files, write, and execute permissions

  • Timestamp file

  • ...

You can view a file's inode information with stat command

[Root @ localhost ~] # stat aaa.txt view details of the inode aaa.txt    

image.png

Linux file system attributes three main time

  • ctime: last change file or directory (attributes) of time

  • atime: the last time a file or directory

  • mtime: last modified files or directories (content) of time

3 structure, the directory file

  • Catalog is a file

  • Directory file structure

Each has an inode number, inode number with the operating system to identify different files

Internal Linux system does not use file names, using inode number to identify the file

For the user, the file name inode number for easy identification of knowledge another name

image.png


4, inode numbers

Users open a file by file name, the process within the system

a, the system finds the inode number corresponding to the file name

B, by inode number, inode information acquired

c, according to inode information, where to find the data block file, read data

image.png


image.png

5, see the inode number of methods

  • ls -i command: View inode number corresponding to the file name

  • stat command: inode number to view the file inode information

[root@localhost opt]# ls -i aaa.txt               查看inode号码

image.png


6、inode的大小

  • inode也会消耗硬盘空间,每个inode的大小,一般是128字节或256字节

  • 格式化文件系统时确定inode的总数

  • 使用df -i命令可以查看每个硬盘分区的inode总数和已经使用的数量

[root@localhost opt]# df -i              查看每个硬盘分区的inode总数和已经使用的数量

image.png

7、inode的特殊作用

由于inode号码与文件名分离,导致一些Linux/Unix系统具有以下的现象

  • 当文件名包含特殊字符,可能无法正常删除文件,直接删除inode,也可以删除文件

[root@localhost opt]# ls -i aaa.txt               查看inode号码 

[root@localhost opt]# find ./* -inum inode号码 -delete 依据inode号码对其进行删除


image.png

  • 移动或重命名文件时,只改变文件名,不影响inode号码

  • 打开一个文件后,系统通过inode号码来识别该文件,不再考虑文件名

二、硬链接与软链接

为文件或目录建立链接文件

文件类型

  • 硬链接:ln 源文件 目标位置

一般情况下,文件名和 inode 号码是一一对应关系,每个 inode 号码对应一个文件名。 但是 Linux 系统允许多个文件名指向同一个 inode 号码。这意味着,可以用不同的文件名访 问同样的内容

  • 软链接:ln -s 源文件或目录..   链接文件或目标位置

软链接就是再创建一个独立的文件,而这个文件会让数据的读取指向它连接的那个文件 的文件名。

image.png


补充:查看文件类型

[root@localhost opt]# file [文件名称或路径]      产看指定文件类型

image.png

[root@localhost opt]# ls -l                  查看指定路径opt的目录文件列表

image.png

三、日志文件的分类

1、日志文件的功能

  • 用于记录系统,程序运行中发生的各种事件

  • 通过阅读日志,有助于诊断和解决系统故障

2、日志文件的分类

  • 内核及系统日志:有系统服务syslog统一进行管理,日志格式基本相似

  • 用户日志:记录系统用户登录及退出系统的相关信息

  • 程序日志:由各种应用程序独立管理的日志文件,记录格式不统一

3、日志保存位置

  • 默认位于:/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

image.png

4、内核及系统日志

由系统服务rsyslogd统一管理

  • 软件包:rsyslog-7.4.7-16.el7.x86_64

  • 主要程序:/sbin/rsyslogd

  • 配置文件:/etc/rsyslog.conf

日志消息级别

image.png

日志记录的一般格式

image.png

四、用户日志与程序日志

用户日志

1、保存了用户登录,退出系统等相关信息

  • 最近的用户登录时间:/var/log/lastlog

  • 用户登录,注销及系统开关机事件:/var/log/wtmp

  • 当前登录的每个用户的详细信息:/var/log/utmp

  • 与用户验证相关的安全性事件:/var/log/secure

2、分析工具

users,who,w,last,lastb

image.png

image.png

程序日志分析

1、由相应的应用程序独立进行管理

  • web服务:/var/log/httpd/(access_log,error_log)

  • 代理服务:/var/log/squid(access.log,cache.log)

  • FTP服务:/var/log/xferlog

2、分析工具

  • 文本查看,grep过滤检索,webmin管理套件中查看

  • awk,sed等文本过滤,格式化编辑工具

  • webalizer,awstats等专用日志分析工具

a、用另一台主机IP为192.168.195.129的主机去访问,访问成功

image.png

b、从目录/var/log/httpd中我们可以看到access_log日志文件,用cat查看内容,可以看到访问的主机的ip的地址信息

image.png

image.png

日志管理策略

  • 及时做好备份和归档

  • 延长日志保存期限

  • 控制日志访问权限

  • 日志中可能会包含各类敏感信息,如账户,口令等

集中管理日志

  • 将服务器的日志文件发到统一的日志文件服务器

  • 便于日志信息的统一收集,整理和分析

  • 杜绝日志信息的意外丢失,恶意篡改或删除



Guess you like

Origin blog.51cto.com/14475876/2433489