• 文件属性下


    第1章 回顾昨天

    1.1 文件的属性 ls -lhi

    2095112 -rw-r--r-- 1 root root 296K 11-13 06:03 log2012.log

    第一列:inode  inode 的值是:2095112 

    第二列:文件种类和权限;

    第三列:硬链接个数;

    第四列:属主;             

    第五列:所归属的组;

    第六列:文件或目录的大小;

    第七列和第八列:最后访问或修改时间;

    第九列:文件名或目录名

    1.2 inode和block

    含义

    inode 索引节点号 inode空间 文件属性 block的位置

    block 实际存放数据的位置

    特点

    inode

    创建一个文件要占用一个inode和至少一个block

    在同一个分区中(文件系统中),两个文件的inode号码相同了 互为硬链接

    block

    4k(centos 6.x) 1k剩余的空间浪费

    如何查看

    df -i

    ls -lhi

    ls -lh

    df -h

    1.3 系统磁盘空间满了,但是df -h看没有满还有剩余空间,问什么原因导致的?

    inode用光了.

    大量的小文件

    block满了 df -h

    inode满了

    1.4 文件的类型和权限

    查看文件的类型和权限:

    file

    1.5 用户和用户组

    分类

    如何保护皇帝/皇宫

    如何查看某一个目录的大小?

    du

    第2章 软硬链接

    2.1 硬链接

    超市的前后门,多个文件拥有相同的inode号码 硬链接

    文件的多个入口

    2.1.1 硬链接的作用

    防止你误删除文件

    2.1.2 如何创建硬链接

    ln === link

    [root@oldboyedu-40-nb oldboy]# touch oldboyedu.txt

    [root@oldboyedu-40-nb oldboy]# ll oldboyedu.txt

    -rw-r--r-- 1 root root 0 Aug 30 09:09 oldboyedu.txt

    [root@oldboyedu-40-nb oldboy]# ln oldboyedu.txt  oldboyedu-hard.txt

    [root@oldboyedu-40-nb oldboy]# ll oldboyedu.txt

    -rw-r--r-- 2 root root 0 Aug 30 09:09 oldboyedu.txt

    [root@oldboyedu-40-nb oldboy]# ls -lhi oldboyedu*

    146135 -rw-r--r-- 2 root root 0 Aug 30 09:09 oldboyedu-hard.txt

    146135 -rw-r--r-- 2 root root 0 Aug 30 09:09 oldboyedu.txt

    [root@oldboyedu-40-nb oldboy]# echo hello oldboyedu >oldboyedu.txt

    [root@oldboyedu-40-nb oldboy]# cat oldboyedu.txt

    hello oldboyedu

    [root@oldboyedu-40-nb oldboy]#

    [root@oldboyedu-40-nb oldboy]# cat oldboyedu-hard.txt

    hello oldboyedu

    2.2 软链接

    2.2.1 软链接是什么?

    快捷方式 省事

    存放的是源文件的位置

    软连接 softlink 符号链接 symbol link    symlink

    1.存放的是源文件的位置

    2.方便使用

    2.2.2 ln -s  源文件   软连接的名字

    [root@oldboyedu-40-nb oldboy]# ln -s  oldboyedu.txt oldboyedu-soft.txt

    [root@oldboyedu-40-nb oldboy]# ls -li oldboyedu*

    146135 -rw-r--r-- 2 root root 16 Aug 30 09:11 oldboyedu-hard.txt

    146136 lrwxrwxrwx 1 root root 13 Aug 30 09:22 oldboyedu-soft.txt -> oldboyedu.txt

    146135 -rw-r--r-- 2 root root 16 Aug 30 09:11 oldboyedu.txt创建软链接

    2.3 软连接与硬链接的区别

    2.3.1 软硬链接啥意思

    软:

    软连接相当于是快捷方式

    里面存放的是源文件的位置

    硬:

    在同一个分区,多个文件拥有相同的inode号码

    2.3.2 软硬链接怎么来的

    ln -s  软连接

    ln     硬链接

    2.3.3 软硬链接特点

    1.软连接可以随意创建,工作常用

    2.不能对目录创建硬链接

    3.对文件创建硬链接可以防止文件被误删除

    2.3.4 软硬链接怎么没的

    1.删除文件的硬链接,文件还是可以继续使用

    2.只有把这个文件的所有的硬链接都删除,这个文件88 就被删除

    3.只删除源文件,软连接无法使用 闪烁

    4.只删除软连接 对文件没任何影响

    2.4 练习题

    2.4.1 题目

    【讲解完软连接后再讲】在配置apache时 执行了./configure --prefix=/application/apache2.2.17 来编译apche,在make install完成后,希望用户的访问路径更简单,需要给/application/apache2.2.17目录做一个软链接/application/apache,使得内部开发或管理人员通过/application/apache就可以访问到apache的安装目录/application/apache2.2.17下的内容,请你给出实现的命令。(提示:apache为一个httpd web服务)

    ln -s /application/apache2.2.17  /application/apache

    /application/apache

    2.4.2 答:

    2.4.2.1  模拟环境:

    [root@oldboyedu-40-nb oldboy]# mkdir -p /application/apache2.2.17

    [root@oldboyedu-40-nb oldboy]# ls -l /application/

    total 4

    drwxr-xr-x 2 root root 4096 Aug 30 10:10 apache2.2.17

    2.4.2.2  创建软连接

    [root@oldboyedu-40-nb oldboy]# ln -s /application/apache2.2.17/ /application/apache

    [root@oldboyedu-40-nb oldboy]# cd /application/

    [root@oldboyedu-40-nb application]# ls -l

    total 4

    lrwxrwxrwx 1 root root   26 Aug 30 10:12 apache -> /application/apache2.2.17/

    drwxr-xr-x 2 root root 4096 Aug 30 10:10 apache2.2.17

    2.4.2.3  软件升级

    [root@oldboyedu-40-nb application]# mkdir -p /application/apache2.4.17

    [root@oldboyedu-40-nb application]# ls -l /application/

    total 8

    lrwxrwxrwx 1 root root   26 Aug 30 10:12 apache -> /application/apache2.2.17/

    drwxr-xr-x 2 root root 4096 Aug 30 10:10 apache2.2.17

    drwxr-xr-x 2 root root 4096 Aug 30 10:16 apache2.4.17

    2.4.2.4  改变软连接

    [root@oldboyedu-40-nb application]# m -f /application/apache

    [root@oldboyedu-40-nb application]# ls -l /application/

    total 8

    drwxr-xr-x 2 root root 4096 Aug 30 10:10 apache2.2.17

    drwxr-xr-x 2 root root 4096 Aug 30 10:16 apache2.4.17

    [root@oldboyedu-40-nb application]# ln -s /application/apache2.4.17/ /application/apache

    [root@oldboyedu-40-nb application]# ls -l /application/

    total 8

    lrwxrwxrwx 1 root root   26 Aug 30 10:17 apache -> /application/apache2.4.17/

    drwxr-xr-x 2 root root 4096 Aug 30 10:10 apache2.2.17

    drwxr-xr-x 2 root root 4096 Aug 30 10:16 apache2.4.17

    2.5 文件删除原理

    2.5.1 一个文件被彻底删除-条件

    1.硬链接数为0    与这个文件有关的所有硬链接都被删除  rm

    2.进程调用数为0  没有人在使用这个文件

    2.5.2 没有被彻底删除

    没有被彻底删除-硬链接数为0,进程调用数不为零

    2.5.3 查看某个文件是否有人在使用   

    lsof

    [root@oldboyedu-40-nb application]# lsof /var/log/messages

    COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME

    rsyslogd 1262 root    1w   REG    8,3     1266 400885 /var/log/messages

    2.5.4 重启对应的软件/服务

    /etc/init.d/

    /etc/init.d/rsyslog restart

    [root@oldboyedu-40-nb application]# ls -l /etc/init.d/rsyslog

    -rwxr-xr-x. 1 root root 2011 Dec 10  2014 /etc/init.d/rsyslog

    2.5.5 故障案例

    2.5.5.1  定义:

    没有被彻底删除-硬链接数为0,进程调用数不为零

    2.5.5.2  通过/var/log/messages 演示文件删除原理(进程调用)

    1.向 /var/log/message中放入大量数据

    seq 100000000 >>/var/log/messages

    2.检查一下 几百兆即可

    ll -h /var/log/messages

    -rw-------. 1 root root 849M Jan 14 09:20 /var/log/messages

    3.查看此时此刻磁盘使用情况

    df -h

    Filesystem      Size  Used Avail Use% Mounted on

    /dev/sda3       6.9G  3.9G  2.7G  59% /

    tmpfs           931M     0  931M   0% /dev/shm

    /dev/sda1       190M   38M  142M  22% /boot

    /dev/sdc         73K   14K   55K  21% /app/logs

    4.假设磁盘空间不够了 我们要删除日志 /var/log/messages

    排查:

    du -sh /*

    du -sh /su/*

    一步一步排查

    m -f /var/log/messages

    5.检查空间没有被释放

    df -h

    Filesystem      Size  Used Avail Use% Mounted on

    /dev/sda3       6.9G  3.9G  2.7G  59% /

    tmpfs           931M     0  931M   0% /dev/shm

    /dev/sda1       190M   38M  142M  22% /boot

    /dev/sdc         73K   14K   55K  21% /app/logs

    6.查看被删除(硬链接数为0)但是还被进程调用的文件

    lsof |grep delete

    rsyslogd  1168      root    1w      REG                8,3 889335632

    7.重启对应的服务

    [root@oldboy34-niubility oldboy]# /etc/init.d/rsyslog restart

    Shutting down system logger:                               [  OK  ]

    Starting system logger:                                    [  OK  ]

    [root@oldboy34-niubility oldboy]# df -h

    Filesystem      Size  Used Avail Use% Mounted on

    /dev/sda3       6.9G  3.0G  3.5G  47% /

    tmpfs           931M     0  931M   0% /dev/shm

    /dev/sda1       190M   38M  142M  22% /boot

    /dev/sdc         73K   14K   55K  21% /app/logs

    2.6 小结

    一个文件被彻底删除:

          1.硬链接数为0 

          2.进程调用数为0

       

    no space left on device  (磁盘空间不足)

          inode满了-定时任务 查找出系统目录比较大(1M)

          block 正常满了 du -sh /* 一层一层找

          block 文件没有被彻底删除-硬链接数为0,进程调用数不为零 lsof|grep delete

              #delete 表示你这个文件的硬链接数为0 进程调用数不为零

    扩展:

    找出某个文件的其他的硬链接  

    touch oldboy.txt

    ln  oldboy.txt  /tmp/oldboy-h.txt

    第3章 linux下面的三种时间戳

    mtime 修改时间          modify  文件的内容 增加 删除 修改  ******

    ctime 属性改变的时间    change  硬链接

    atime 访问时间          access  看一次文件的内容 cat

    查看oldboy.txt的时间戳

    [root@oldboyedu-40-nb ~]# stat oldboy.txt

      File: `oldboy.txt'

      Size: 18          Blocks: 8          IO Block: 4096   regular file

    Device: 803h/2051d  Inode: 130154      Links: 1

    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

    Access: 2017-08-18 03:51:51.704065822 +0800

    Modify: 2017-08-18 03:51:51.704065822 +0800

    Change: 2017-08-18 03:51:51.707065754 +0800

    修改之后:

    [root@oldboyedu-40-nb ~]# ##mtime

    [root@oldboyedu-40-nb ~]# echo oldboyedu.com >>oldboy.txt

    [root@oldboyedu-40-nb ~]# stat oldboy.txt

      File: `oldboy.txt'

      Size: 32          Blocks: 8          IO Block: 4096   regular file

    Device: 803h/2051d  Inode: 130154      Links: 1

    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

    Access: 2017-08-18 03:51:51.704065822 +0800

    Modify: 2017-08-30 11:36:12.363903190 +0800

    Change: 2017-08-30 11:36:12.363903190 +0800

    [root@oldboyedu-40-nb ~]# ##ctime

    [root@oldboyedu-40-nb ~]# stat oldboy.txt

      File: `oldboy.txt'

      Size: 32          Blocks: 8          IO Block: 4096   regular file

    Device: 803h/2051d  Inode: 130154      Links: 1

    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

    Access: 2017-08-18 03:51:51.704065822 +0800

    Modify: 2017-08-30 11:36:12.363903190 +0800

    Change: 2017-08-30 11:36:12.363903190 +0800

    [root@oldboyedu-40-nb ~]# ln oldboy.txt oldboy.txt-hard

    [root@oldboyedu-40-nb ~]# stat oldboy.txt

      File: `oldboy.txt'

      Size: 32          Blocks: 8          IO Block: 4096   regular file

    Device: 803h/2051d  Inode: 130154      Links: 2

    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

    Access: 2017-08-18 03:51:51.704065822 +0800

    Modify: 2017-08-30 11:36:12.363903190 +0800

    Change: 2017-08-30 11:38:07.699913746 +0800

    [root@oldboyedu-40-nb ~]# ##atime

    [root@oldboyedu-40-nb ~]# cat oldboy.txt

    ##

    #123

    #456

    #789

    oldboyedu.com

    [root@oldboyedu-40-nb ~]# stat oldboy.txt

      File: `oldboy.txt'

      Size: 32          Blocks: 8          IO Block: 4096   regular file

    Device: 803h/2051d  Inode: 130154      Links: 2

    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

    Access: 2017-08-30 11:38:47.815909499 +0800

    Modify: 2017-08-30 11:36:12.363903190 +0800

    Change: 2017-08-30 11:38:07.699913746 +0800

    第4章 chkconfig linux下面开机自启动软件/服务

    4.1.1 linux下面开机自启动软件在哪个目录 (假设现在是3运行级别)

    [root@oldboyedu-40-nb ~]# ls -ld /etc/rc3.d /etc/rc.d/rc3.d

    lrwxrwxrwx. 1 root root   10 Aug 10 18:36 /etc/rc3.d -> rc.d/rc3.d

    drwxr-xr-x. 2 root root 4096 Aug 29 05:25 /etc/rc.d/rc3.d

    4.1.2 /etc/rc3.d 下面的内容 假设现在是3运行级别

    软连接

    [root@oldboyedu-40-nb rc3.d]# ls -l |grep ipt

    lrwxrwxrwx  1 root root 18 Aug 29 05:25 K92iptables -> ../init.d/iptables

    运行:

    chkconfig iptables on

    chkconfig iptables off

    4.1.2.1  在/etc/rc3.d 目录下面到底发生了什么?

    [root@oldboyedu-40-nb rc3.d]# chkconfig iptables on

    [root@oldboyedu-40-nb rc3.d]# chkconfig |grep ipt

    iptables       0:off      1:off      2:on       3:on       4:on       5:on       6:off

    [root@oldboyedu-40-nb rc3.d]# ls -l /etc/rc3.d/ |grep ipt

    lrwxrwxrwx  1 root root 18 Aug 30 12:03 S08iptables -> ../init.d/iptables

     

    [root@oldboyedu-40-nb rc3.d]# chkconfig iptables off

    [root@oldboyedu-40-nb rc3.d]# chkconfig |grep ipt

    iptables       0:off      1:off      2:off      3:off      4:off      5:off      6:off

    [root@oldboyedu-40-nb rc3.d]# ls -l /etc/rc3.d/ |grep ipt

    lrwxrwxrwx  1 root root 18 Aug 30 12:04 K92iptables -> ../init.d/iptables

    运行

    chkconfig iptables on     ====== 软连接变为  S08iptables -> /etc/init.d/iptables

    chkconfig iptables off    ====== 软连接变为  K92iptables -> /etc/init.d/iptables

    iptables 开机自启动    软连接   S开头 start

    iptables 开机不自启动  软连接   K开头 kill

             

    验证

    [root@oldboyedu-40-nb rc3.d]# chkconfig iptables off

    [root@oldboyedu-40-nb rc3.d]# chkconfig iptables off

    [root@oldboyedu-40-nb rc3.d]# chkconfig |grep ipt

    iptables       0:off      1:off      2:off      3:off      4:off      5:off      6:off

    [root@oldboyedu-40-nb rc3.d]# ls -l /etc/rc3.d/ |grep ipt

    lrwxrwxrwx  1 root root 18 Aug 30 12:06 K92iptables -> ../init.d/iptables

    [root@oldboyedu-40-nb rc3.d]# m -f /etc/rc3.d/K92iptables

    [root@oldboyedu-40-nb rc3.d]# ln -s /etc/init.d/iptables  /etc/rc3.d/S08iptables

    [root@oldboyedu-40-nb rc3.d]# ls -l /etc/rc3.d/ |grep ipt

    lrwxrwxrwx  1 root root 20 Aug 30 12:07 S08iptables -> /etc/init.d/iptables

    [root@oldboyedu-40-nb rc3.d]# chkconfig |grep ipt

    iptables       0:off      1:off      2:off      3:on       4:off      5:off      6:off

    chkconfig on /off 原理 或发生了什么 (理解结论 过程了解)

    1.chkconfig 命令是在操作 /etc/rc运行级别.d  /etc/rc3.d 下面软连接

    2.

    开机自启动   chkconfig iptables on     ====== 软连接变为  S08iptables -> /etc/init.d/iptables

    开机不自启动 chkconfig iptables off    ====== 软连接变为  K92iptables -> /etc/init.d/iptables

    4.2 linux下面如何让一个软件/命令开机自启动******

    4.2.1 把命令或脚本放入到 /etc/rc.local 文件中

    4.2.2 通过chkconfig管理脚本 让他开机自启动

    4.2.3 如何让一个服务或命令通过chkconfig管理  管理的条件

    4.2.3.1  第一个里程碑-脚本必须放在/etc/init.d/目录下面

    [root@oldboyedu-40-nb rc3.d]# echo "hostname" >/etc/init.d/oldboyd

    [root@oldboyedu-40-nb rc3.d]# cat /etc/init.d/oldboyd

    hostname

    [root@oldboyedu-40-nb rc3.d]# /etc/init.d/oldboyd

    -bash: /etc/init.d/oldboyd: Permission denied

    [root@oldboyedu-40-nb rc3.d]# ls -l /etc/init.d/oldboyd

    -rw-r--r-- 1 root root 9 Aug 30 12:22 /etc/init.d/oldboyd

    4.2.3.2  第二个里程碑-给这个脚本添加上 执行权限

    #chmod +x   /etc/init.d/oldboyd

    # ls -l /etc/init.d/oldboyd

    -rwxr-xr-x 1 root root 9 Aug 30 12:22 /etc/init.d/oldboyd

    4.2.3.3  第三个里程碑-运行脚本

    /etc/init.d/oldboyd

    oldboyedu-40-nb    

    4.2.3.4  第四个里程碑-写出chkconfig格式

    chkconfig不支持 无法管理 oldboyd服务

    chkconfig: 2345 99 99

                默认在哪几个运行级别启动  开机顺序  关机顺序

    [root@oldboyedu-40-nb rc3.d]# cat /etc/init.d/oldboyd

    #chkconfig: 2345 99 99

    # description:  print hostname

    hostname

    4.2.3.5  第五个里程碑-添加到chkconfig管理

    [root@oldboyedu-40-nb rc3.d]# chkconfig --add oldboyd

    4.2.3.6  第六个里程碑-检查

    [root@oldboyedu-40-nb rc3.d]# chkconfig |grep oldboyd

    oldboyd              0:off      1:off      2:on       3:on       4:on       5:on       6:off

     

     

    chkconfig |grep oldboyd

    第5章 今天小结

    inode和block 

    怎么来的 啥意思 特点

    文件类型

                如何区分文件的类型-file

    初识linux权限

          rwx含义

          rwx对应数字

          linux权限分为3个部分

    软硬链接

          软连接与硬链接的区别

    用户和用户组

          分类

          UID GID

          用户和用户组什么意思

          文件

          /etc/passwd 用户的信息 每一列的含义

          如何保护好皇帝/皇宫

    linux中的三种时间戳

          mtime 修改时间

          ctime 属性改变的时间

          atime 访问时间

    文件删除原理

          一个文件被彻底删除:

                1.硬链接数为0 

                2.进程调用数为0

          no space left on device  (磁盘空间不足)

                inode满了-定时任务-找出系统中比较大的目录

                block 正常满了 du -sh /* 

                block 硬链接数为0,进程调用数不为零 lsof|grep delete

    linux下面如何让一个软件/命令开机自启动

  • 相关阅读:
    软件的开发流程(摘录百度百科)
    linux大全
    percona server 二进制安装下编译tpcc-mysql的坑
    Problems with MMM for mysql(译文)
    MySQL MMM 双主在Failover时挂起
    Steve Loughran:Why not raid 0,its about time and snowflakes!!!
    React-Redux 源码解析
    《图解 HTTP》读书笔记
    图解 HTTP 笔记(八)——常见 Web 攻击技术
    图解 HTTP 笔记(七)——HTTPS
  • 原文地址:https://www.cnblogs.com/Arlen723/p/7846079.html
Copyright © 2020-2023  润新知