Linux系统相关 - zhongjiajie/zhongjiajie.github.com GitHub Wiki

Linux系统相关

linux文件夹与全称对应表

shell命令 对应的全称
/bin BINaries 下面的是一些二进制程序文件
/dev DEVices 下面的是一些硬件驱动
/etc ETCetera 目录存放着各种系统配置文件, 类似于windows下的system
/lib LIBrary
/proc PROCesses
/sbin Superuser BINaries
/tmp TeMPorary
/usr Unix Shared Resources
/var VARiable
/boot boot 下面的是开机启动文件

linux文件扩展名对应的含义

shell命令 对应的全称
.*rc(eg: .bashrc .xinitrc) Resource configuration
.a Archive,static library
.so Shared object,dynamically linked library
.o Object file,complied result of C/C++ source file

时间和时区

操作系统通过如下内容确定时间:时间数值、时间标准、时区和夏令时调节(中国已经废止).

  • 时钟分类: Linux时钟分为系统时钟(System Clock)和硬件时钟(Real Time Clock,简称 RTC)
    • 硬件时钟: 由主板电池供电的时钟,可以在BIOS进行设置,仅能保存年月日时分秒这些
  • 时间标准: 时间有两个标准,localtime以及UTC.UTC是与时区无关的全球时间标准,localtime标准则依赖于当前时区

如何设置时间

How to Set Time, Timezone and Synchronize System Clock Using timedatectl Command

  • 硬件时间: timedatectl set-local-rtc 1将硬件时间设成localtime,timedatectl set-local-rtc 0将硬件时间设成UTC
  • 设置系统时间: timedatectl set-time "2012-10-30 18:17:16"

硬盘

LVM

LVM利用Linux内核的device-mapper来实现存储系统的虚拟化(系统分区独立于底层硬件)。 通过LVM,你可以实现存储空间的抽象化并在上面建立虚拟分区(virtual partitions),可以更简便地扩大和缩小分区,可以增删分区时无需担心某个硬盘上没有足够的连续空间, without getting caught up in the problems of fdisking a disk that is in use (and wondering whether the kernel is using the old or new partition table) and without having to move other partition out of the way. LVM是用来方便管理的,不会提供额外的安全保证。 However, it sits nicely with the other two technologies we are using.

LVM的基本组成块(building blocks)如下:

物理卷Physical volume (PV):可以在上面建立卷组的媒介,可以是硬盘分区,也可以是硬盘本身或者回环文件(loopback file)。物理卷包括一个特殊的header,其余部分被切割为一块块物理区域(physical extents)。 Think of physical volumes as big building blocks which can be used to build your hard drive.

卷组Volume group (VG):将一组物理卷收集为一个管理单元。Group of physical volumes that are used as storage volume (as one disk). They contain logical volumes. Think of volume groups as hard drives.

逻辑卷Logical volume (LV):虚拟分区,由物理区域(physical extents)组成。A "virtual/logical partition" that resides in a volume group and is composed of physical extents. Think of logical volumes as normal partitions.

物理区域Physical extent (PE):硬盘可供指派给逻辑卷的最小单位(通常为4MB)。A small part of a disk (usually 4MB) that can be assigned to a logical Volume. Think of physical extents as parts of disks that can be allocated to any partition.

硬盘扩容

  • 创建LVM,扩展LVM
  • 修改/etc/fstab增加挂载的LVM盘到挂载点,以便重启服务器的时候自动挂载盘,详见

/etc/fstab 设置开机硬盘自动挂载

如果将磁盘信息写入/etc/fstab文件中就不需要每次开机都进行手动的磁盘挂载了,使用cat /etcfstab可以查看相关的挂载方式,一般为六列:

  • 第一列: 分区的label和uuid
  • 第二列: 设备的挂载点(mount point),就是你要挂载到哪个目录下
  • 第三列: 磁盘文件系统(filesystem)的格式,包括ext2、ext3、reiserfs、nfs、vfat等
  • 第四列: parameters,文件系统的参数
  • 第五列: 能否dump备份命令作用,dump是一个用来作为备份的命令.{0:不做dump备份, 1:每天dump备份, 2:不定日期的进行dump操作}
  • 第六列: 是否检验扇区,开机的过程中系统默认会以fsck检验我们系统是否为完整{0:不要检测, 1:最早检测, 2:检测完1后检测}

网络

  • 开启了服务后,用nmap查看对口开启,本地能telnet通,远端不能telnet端口号,显示no route to host局域网no route to host 解决

其他

crontab

  • crontab配置方便的网站这里
  • crontab日志的路径一般为/var/log/cron*

NTP服务器

Linux的时间是从1970-01-01开始计算秒数的,这个是软体时间。BIOS内部芯片也有一个时间,叫做硬体时间,但是有BIOS芯片本身的原因,导致时间存在差异,此时就需要一个机制用于时间的同步,NTP(Network Time Protocol)服务器就是做这件事的。

TMP

  • 通过命令链接在后台运行的进程1: jobs看看有什么进程,fg %进程号接入进程,ps:要在同一个terminal里面
  • Linux关机顺序:
    • who: 查看有没有其他用户登录
    • sync: 为了加快对磁盘文件的读写速度,位于内存中的文件数据不会立即同步到磁盘上,因此关机之前需要先进行 sync 同步操作
    • shutdown: shutdown [-krhc] 时间 [信息]

⚠️ **GitHub.com Fallback** ⚠️