linux服务三——目录与启动过程

第1章 /etc/目录

1.1 /etc/sysconfig/network-scripts/ifcfg-ens33

linux第一块网卡的配置文件

[root@iso-all network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@iso-all network-scripts]# cat ifcfg-ens33 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=153aac6a-1d48-4244-af28-a6355ec6cef1
DEVICE=ens33
ONBOOT=yes
IPADDR=10.0.0.15
NETMASK=255.255.255.0
GATEWAY=10.0.0.2
DNS1=114.114.114.114 

1.2 /etc/resolv.conf

  dns临时配置文件

[root@iso-all ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 114.114.114.114

1.3 /etc/fstab

机自动挂载分区/磁盘,规定哪个分区/设备,挂载到哪里

[root@iso-all ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Thu Mar 21 22:05:23 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=f08b7afb-8df3-4f44-b6b3-656e505a1de8 /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0

1.4     /etc/hosts

主机名解析文件

hosts文件里存放ip地址与域名的对应关系

[root@iso-all ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.15  iso-all
10.0.0.12  cobbler

1.5 /etc/profile

配置别名 配置环境变量

[root@iso-all ~]# cat /etc/profile
# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.

pathmunge () {
    case ":${PATH}:" in
        *:"$1":*)
            ;;
        *)
            if [ "$2" = "after" ] ; then
                PATH=$PATH:$1
            else
                PATH=$1:$PATH
            fi
    esac
}


if [ -x /usr/bin/id ]; then
    if [ -z "$EUID" ]; then
        # ksh workaround
        EUID=`/usr/bin/id -u`
        UID=`/usr/bin/id -ru`
    fi
    USER="`/usr/bin/id -un`"
    LOGNAME=$USER
    MAIL="/var/spool/mail/$USER"
fi

# Path manipulation
if [ "$EUID" = "0" ]; then
    pathmunge /usr/sbin
    pathmunge /usr/local/sbin
else
    pathmunge /usr/local/sbin after
    pathmunge /usr/sbin after
fi

HOSTNAME=`/usr/bin/hostname 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
    export HISTCONTROL=ignoreboth
else
    export HISTCONTROL=ignoredups
fi

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL

# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
    umask 002
else
    umask 022
fi

for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
    if [ -r "$i" ]; then
        if [ "${-#*i}" != "$-" ]; then 
            . "$i"
        else
            . "$i" >/dev/null
        fi
    fi
done

unset i
unset -f pathmunge
View Code

1.6 /etc/bashrc

配置别名

[root@iso-all ~]# cat /etc/bashrc 
# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.

# are we an interactive shell?
if [ "$PS1" ]; then
  if [ -z "$PROMPT_COMMAND" ]; then
    case $TERM in
    xterm*|vte*)
      if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
          PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
      elif [ "${VTE_VERSION:-0}" -ge 3405 ]; then
          PROMPT_COMMAND="__vte_prompt_command"
      else
          PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
      fi
      ;;
    screen*)
      if [ -e /etc/sysconfig/bash-prompt-screen ]; then
          PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
      else
          PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
      fi
      ;;
    *)
      [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
      ;;
    esac
  fi
  # Turn on parallel history
  shopt -s histappend
  history -a
  # Turn on checkwinsize
  shopt -s checkwinsize
  [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
  # You might want to have e.g. tty in prompt (e.g. more virtual machines)
  # and console windows
  # If you want to do so, just add e.g.
  # if [ "$PS1" ]; then
  #   PS1="[\u@\h:\l \W]\\$ "
  # fi
  # to your custom modification shell script in /etc/profile.d/ directory
fi

if ! shopt -q login_shell ; then # We're not a login shell
    # Need to redefine pathmunge, it get's undefined at the end of /etc/profile
    pathmunge () {
        case ":${PATH}:" in
            *:"$1":*)
                ;;
            *)
                if [ "$2" = "after" ] ; then
                    PATH=$PATH:$1
                else
                    PATH=$1:$PATH
                fi
        esac
    }

    # By default, we want umask to get set. This sets it for non-login shell.
    # Current threshold for system reserved uid/gids is 200
    # You could check uidgid reservation validity in
    # /usr/share/doc/setup-*/uidgid file
    if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
       umask 002
    else
       umask 022
    fi

    SHELL=/bin/bash
    # Only display echos from profile.d scripts if we are no login shell
    # and interactive - otherwise just process them to set envvars
    for i in /etc/profile.d/*.sh; do
        if [ -r "$i" ]; then
            if [ "$PS1" ]; then
                . "$i"
            else
                . "$i" >/dev/null
            fi
        fi
    done

    unset i
    unset -f pathmunge
fi
# vim:ts=4:sw=4
View Code

1.6.1 .bash_profile与 .bashrc

国法:对所有用户生效          
/etc/profile   (改这一个就可以)
/etc/bashrc                   
家规 :只对当前用户生效       
.bash_profile                 
.bashrc     

1.7 /etc/inittab

系统运行级别的配置文件

       运行级别===系统不同的状态

1.7.1 不同运行级别的含义:

# Default runlevel. The runlevels used are:
#   0 - halt (Do NOT set initdefault to this)
        关机状态(禁止把运行级别设置为0)
#   1 - Single user mode
        单用户模式   (root用户密码忘了 维护)
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
        多用户模式,但是没有NFS功能
#   3 - Full multiuser mode
        工作中默认的运行级别 完全的多用户模式 命令行模式
#   4 - unused
        没有使用
#   5 - X11
        桌面模式 图形化模式
#   6 - reboot (Do NOT set initdefault to this)
        重启

1.7.2 如何临时修改运行级别

init  3   修改和查看运行级别

[root@iso-all ~]# init 3
[root@iso-all ~]# runlevel 
N 3 

1.8 /etc/rc.local

开机自动运行的程序或命令

需要在开机的时候自动运行命令或软件就可以放入到这个文件中
[root@iso-all ~]# cat /etc/rc.local 
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local

第2章 /var/目录

2.1 /var/log/messages

系统默认的日志

[root@iso-all ~]# ls -l /var/log/messages
-rw-------. 1 root root 13030 9月  20 13:01 /var/log/messages

每过一段时间,就会把 /var/log/messages  /var/log/secure  切割一下,给旧的文件加上个时间 ---日志切割(日志轮询)

2.2 /var/log/secure

用户的登录信息 什么时候 从哪里登录 是否成功

主要看failed (失败)的记录

[root@iso-all ~]# ls -l /var/log/secure*
-rw-------. 1 root root  682 9月  20 12:59 /var/log/secure
-rw-------. 1 root root 5000 8月  16 07:29 /var/log/secure-20200816
-rw-------. 1 root root 7373 8月  22 12:04 /var/log/secure-20200823
-rw-------. 1 root root 2653 9月  19 12:02 /var/log/secure-20200919
-rw-------. 1 root root 3763 9月  19 21:22 /var/log/secure-20200920

第3章 /proc目录下

/proc目录是虚拟的,能够显示内存中的信息。

3.1 /proc/cpuinfo

显示CPU信息

[root@iso-all ~]# cat /proc/cpuinfo 
processor    : 0
vendor_id    : GenuineIntel
cpu family    : 6
model        : 142
model name    : Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
stepping    : 10
microcode    : 0xb4
cpu MHz        : 1992.005
cache size    : 8192 KB
physical id    : 0
siblings    : 1
core id        : 0
cpu cores    : 1
apicid        : 0
initial apicid    : 0
fpu        : yes
fpu_exception    : yes
cpuid level    : 22
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec arat spec_ctrl intel_stibp flush_l1d arch_capabilities
bogomips    : 3984.01
clflush size    : 64
cache_alignment    : 64
address sizes    : 43 bits physical, 48 bits virtual
power management:
View Code

3.2 /proc/meminfo

显示内存信息

[root@iso-all ~]# cat /proc/meminfo 
MemTotal:         995896 kB
MemFree:          677808 kB
MemAvailable:     670988 kB
Buffers:               0 kB
Cached:            75352 kB
SwapCached:           56 kB
Active:            38460 kB
Inactive:          76092 kB
Active(anon):      22444 kB
Inactive(anon):    24380 kB
Active(file):      16016 kB
Inactive(file):    51712 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       1048572 kB
SwapFree:        1048052 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:         39176 kB
Mapped:            21192 kB
Shmem:              7624 kB
Slab:             107684 kB
SReclaimable:      61412 kB
SUnreclaim:        46272 kB
KernelStack:        3872 kB
PageTables:         3780 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     1546520 kB
Committed_AS:     220432 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      177140 kB
VmallocChunk:   34359310332 kB
HardwareCorrupted:     0 kB
AnonHugePages:      6144 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       83840 kB
DirectMap2M:      964608 kB
DirectMap1G:           0 kB
[root@iso-all ~]# 
View Code

3.3 /proc/mounts

查看系统挂载信息

[root@iso-all ~]# cat /proc/mounts 
rootfs / rootfs rw 0 0
sysfs /sys sysfs rw,seclabel,nosuid,nodev,noexec,relatime 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
devtmpfs /dev devtmpfs rw,seclabel,nosuid,size=485780k,nr_inodes=121445,mode=755 0 0
securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0
tmpfs /dev/shm tmpfs rw,seclabel,nosuid,nodev 0 0
devpts /dev/pts devpts rw,seclabel,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
tmpfs /run tmpfs rw,seclabel,nosuid,nodev,mode=755 0 0
tmpfs /sys/fs/cgroup tmpfs ro,seclabel,nosuid,nodev,noexec,mode=755 0 0
cgroup /sys/fs/cgroup/systemd cgroup rw,seclabel,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd 0 0
pstore /sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0
cgroup /sys/fs/cgroup/pids cgroup rw,seclabel,nosuid,nodev,noexec,relatime,pids 0 0
cgroup /sys/fs/cgroup/perf_event cgroup rw,seclabel,nosuid,nodev,noexec,relatime,perf_event 0 0
cgroup /sys/fs/cgroup/memory cgroup rw,seclabel,nosuid,nodev,noexec,relatime,memory 0 0
cgroup /sys/fs/cgroup/freezer cgroup rw,seclabel,nosuid,nodev,noexec,relatime,freezer 0 0
cgroup /sys/fs/cgroup/devices cgroup rw,seclabel,nosuid,nodev,noexec,relatime,devices 0 0
cgroup /sys/fs/cgroup/hugetlb cgroup rw,seclabel,nosuid,nodev,noexec,relatime,hugetlb 0 0
cgroup /sys/fs/cgroup/net_cls,net_prio cgroup rw,seclabel,nosuid,nodev,noexec,relatime,net_prio,net_cls 0 0
cgroup /sys/fs/cgroup/cpuset cgroup rw,seclabel,nosuid,nodev,noexec,relatime,cpuset 0 0
cgroup /sys/fs/cgroup/blkio cgroup rw,seclabel,nosuid,nodev,noexec,relatime,blkio 0 0
cgroup /sys/fs/cgroup/cpu,cpuacct cgroup rw,seclabel,nosuid,nodev,noexec,relatime,cpuacct,cpu 0 0
configfs /sys/kernel/config configfs rw,relatime 0 0
/dev/mapper/centos-root / xfs rw,seclabel,relatime,attr2,inode64,noquota 0 0
selinuxfs /sys/fs/selinux selinuxfs rw,relatime 0 0
debugfs /sys/kernel/debug debugfs rw,relatime 0 0
mqueue /dev/mqueue mqueue rw,seclabel,relatime 0 0
hugetlbfs /dev/hugepages hugetlbfs rw,seclabel,relatime 0 0
systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=30,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=21764 0 0
/dev/sda1 /boot xfs rw,seclabel,relatime,attr2,inode64,noquota 0 0
tmpfs /run/user/0 tmpfs rw,seclabel,nosuid,nodev,relatime,size=99592k,mode=700 0 0
binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0
View Code

3.4 /proc/loadavg

查看系统的负载信息,可用w命令代替

[root@iso-all ~]# w
 13:08:17 up 1 day,  1:22,  3 users,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty1                      六11   24:59m  0.75s  0.75s -bash
root     pts/0    10.0.0.1         六19   15:35m  0.17s  0.17s -bash
root     pts/1    10.0.0.1         12:43    1.00s  0.15s  0.04s w
[root@iso-all ~]# cat /proc/lo
loadavg  locks    
[root@iso-all ~]# cat /proc/loadavg 
0.00 0.01 0.05 2/116 53802
[root@iso-all ~]# 

第4章 linux启动过程

4.1centos6启动过程

1、开机自检bios

2、mbr引导

3、GRUB 菜单:选择不同的内核

4、加载内核

5、运行init进程

6、读取/etc/inittab配置文件

7、执行 /etc/rc.d/rc.sysinit 脚本 (系统的初始化脚本)

8、执行 /etc/rc.d/rc  (根据运行级别运行相应的软件)

9、显示登陆界面

4.1centos7启动过程

1、开机自检bios

2、mbr引导

3、GRUB 菜单:选择不同的内核

4、加载内核

5、systemed初始化阶段   #注意:systemctl 优势,可一次性控制多个服务

9、显示登陆界面

第5章 PATH环境变量作用

PATH 的作用:存放linux系统中命令的位置

[root@iso-all ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@iso-all ~]# 

5.1 运行命令的过程

1、输入命令 ls

2、系统会找ls 在哪(问PATH

3、找到了运行

4、找不到提示 command not found 或 no such file or directory

5.2 PATH修改

修改环境变量加export

export $PATH=要改的路径
posted @ 2020-09-20 22:47  辉煌-love  阅读(377)  评论(0)    收藏  举报