1. [root@oldboy60service01 ~]# tree -L 1 /
/
├── alex
├── bin -> usr/bin 二進制文件族阅,命令
├── boot 引導(dǎo)系統(tǒng)啟動,引導(dǎo)程序和系統(tǒng)內(nèi)核
├── dev 存放設(shè)備文件(光盤董济,U盤幔嫂,硬盤分區(qū)...)
├── etc 存放系統(tǒng)配置文件
├── home 普通用戶家目錄
├── lib -> usr/lib 庫文件(系統(tǒng)正常運行需要的文件)
├── lib64 -> usr/lib64 64位文件
├── media 媒體文件(以前是掛載光盤)
├── mnt 臨時掛載目錄(給設(shè)備開個入口跪楞,例如光盤有了入口打開訪問)
├── opt 第三方軟件安裝目錄
├── proc 內(nèi)存信息里的進程信息(虛擬目錄)
├── root超級用戶家目錄
├── run
├── sbin -> usr/sbin root用戶使用的命令
├── srv
├── sys
├── tmp 臨時的目錄(垃圾堆)
├── usr 存放用戶軟件、命令
├── var 經(jīng)常變化的內(nèi)容(日志)
└── zhang
21 directories, 0 files
[root@oldboy60service01 ~]#
2.Linux下面的設(shè)備必須要有掛載才能使用
mount /dev/cdrom /mnt/
掛載 給光盤 設(shè)置了個入口叫/mnt
[root@oldboy60service01 dev]# cd cdrom
-bash: cd: cdrom: Not a directory
[root@oldboy60service01 dev]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@oldboy60service01 dev]# ls /mnt
CentOS_BuildTag GPL LiveOS RPM-GPG-KEY-CentOS-7
EFI images Packages RPM-GPG-KEY-CentOS-Testing-7
EULA isolinux repodata TRANS.TBL
3. /etc 目錄
1.網(wǎng)卡配置文件
/etc/sysconfig/network-scripts/ifcfg-eth0
/系統(tǒng)配置文件/system configure/網(wǎng)絡(luò)-腳本(管理網(wǎng)卡命令)/
[root@oldboy60service01 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet 網(wǎng)卡類型 以太網(wǎng)
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none 網(wǎng)卡獲取 i p 的方式 none/static 手動設(shè)置(固定)
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=eth0 網(wǎng)卡名稱
UUID=99bf4e92-6687-47ce-85be-1a6e95963074 設(shè)備標識符
DEVICE=eth0 設(shè)備名稱
ONBOOT=yes 網(wǎng)卡是否開機自啟動
IPADDR=10.0.0.200 i p 地址
PREFIX=24 子網(wǎng)掩碼
GATEWAY=10.0.0.254 默認網(wǎng)關(guān)(大樓的大門)
DNS1=10.0.0.254 域名解析
IPV6_PRIVACY=no
[root@oldboy60service01 ~]#
systemctl restart network 重啟網(wǎng)卡
- /etc/resolv.conf 配置DNS
[root@oldboy60service01 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 10.0.0.254
/etc/resolv.conf 實時生效(重啟網(wǎng)絡(luò)后堡赔,網(wǎng)卡配置覆蓋)
主要修改的是網(wǎng)卡配置文件中的即可
- /etc/hostname 配置主機名
[root@oldboy60service01 ~]# hostname 顯示當前主機名
oldboy60service01
[root@oldboy60service01 ~]# hostname oldboy60zhang更改主機名
[root@oldboy60service01 ~]# hostname
oldboy60zhang
hostname命令(臨時的识脆,重啟系統(tǒng)之后失效)
[root@oldboy60service01 ~]# vi /etc/hostname
oldboy60service01
~
~
~
"/etc/hostname" 1L, 18C
更改永久主機名,修改 vi /etc/hostname 里的內(nèi)容
Centos7改主機名命令:hostnamectl set-hostname oldboy60zhang
- /etc/hosts 主機名與IP地址對應(yīng)關(guān)系(搭建測試環(huán)境)
[root@oldboy60service01 ~]# vim /etc/hosts
[root@oldboy60service01 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.200 oldboy60service001
[root@oldboy60service01 ~]# ping oldboy60service001
PING oldboy60service001 (10.0.0.200) 56(84) bytes of data.
64 bytes from oldboy60service001 (10.0.0.200): icmp_seq=1 ttl=64 time=0.107 ms
64 bytes from oldboy60service001 (10.0.0.200): icmp_seq=5 ttl=64 time=0.272 ms
^C
--- oldboy60service001 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4002ms
rtt min/avg/max/mdev = 0.107/0.189/0.272/0.069 ms
[root@oldboy60service01 ~]#
- /etc/profile 用來配置環(huán)境變量
36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
MAIL=/var/spool/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
PWD=/root
LANG=en_US.UTF-8
SELINUX_LEVEL_REQUESTED=
HISTCONTROL=ignoredups
SHLVL=1
HOME=/root
LOGNAME=root
SSH_CONNECTION=10.0.0.1 50827 10.0.0.200 22
LESSOPEN=||/usr/bin/lesspipe.sh %s
XDG_RUNTIME_DIR=/run/user/0
_=/usr/bin/env
[root@oldboy60service01 ~]#
(1)系統(tǒng)創(chuàng)建好的善已,我們可以隨便使用的灼捂。存放系統(tǒng)信息
系統(tǒng)環(huán)境變量的特點都是大寫的,例:PWD换团、LANG...
(2)PATH 路徑(存放的是系統(tǒng)命令的位置)悉稠,配合echo使用
顯示變量里的內(nèi)容echo $PATH[root@oldboy60service01 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@oldboy60service01 ~]#
使用:分開每一個文件
/usr/local/sbin
/usr/local/bin
/usr/sbin === /sbin
/usr/bin ===/bin
/root/bin 默認是不存在的PATH=/bin修改變量內(nèi)容
[root@oldboy60service01 ~]# PATH=/bin
[root@oldboy60service01 ~]# echo $PATH
/bin
[root@oldboy60service01 ~]#
斷開后重新連接,變量失效
- /etc/bashrc 別名
alias 顯示系統(tǒng)里所有的別名
[root@oldboy60service01 ~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
[root@oldboy60service01 ~]#
/etc 國法
/etc/profile
/etc/bashrc
家規(guī)艘包,以 . (點) 開頭的文件是隱藏文件
~/.bash_profile
~/.bashrc
[root@oldboy60service01 ~]# ll
total 4
-rw-------. 1 root root 1507 Mar 26 15:37 anaconda-ks.cfg
drwxr-xr-x. 2 root root 24 Apr 7 19:15 oldboy
[root@oldboy60service01 ~]# ls -la
total 32
dr-xr-x---. 3 root root 165 Apr 8 17:50 .
dr-xr-xr-x. 19 root root 249 Apr 7 17:27 ..
-rw-------. 1 root root 1507 Mar 26 15:37 anaconda-ks.cfg
-rw-------. 1 root root 1651 Apr 7 23:20 .bash_history
-rw-r--r--. 1 root root 18 Dec 29 2013 .bash_logout
-rw-r--r--. 1 root root 176 Dec 29 2013 .bash_profile
-rw-r--r--. 1 root root 176 Dec 29 2013 .bashrc
-rw-r--r--. 1 root root 100 Dec 29 2013 .cshrc
drwxr-xr-x. 2 root root 24 Apr 7 19:15 oldboy
-rw-r--r--. 1 root root 129 Dec 29 2013 .tcshrc
-rw-------. 1 root root 623 Apr 8 17:50 .viminfo
[root@oldboy60service01 ~]#
- /etc/inittab 運行級別的配置文件
(1). CentOS 6服務(wù)器不同狀態(tài)
runlevel
0 關(guān)機狀態(tài)
1 單用戶模式(沒有網(wǎng)絡(luò)的猛,用來重新設(shè)置root密碼)
2 多用戶模式 (沒有NFS)
3 完全多用戶模式 文本模式 命令行模式
4 沒有使用
5 圖形化界面模式 桌面模式 X11
6 重啟
(2). CentOS 7服務(wù)器不同狀態(tài)
target
0 poweroff.target 關(guān)機
1 rescue.target 救援模式
2 multi-usr 多用戶模式
3 multi-usr 多用戶模式
4 multi-usr 多用戶模式
5 graphical 圖形模式
6 reboot 重啟
[root@oldboy60service01 ~]# ls -l /usr/lib/systemd/system/runlevel*.target
Mar 26 15:32 /usr/lib/systemd/system/runlevel0.target -> poweroff.target
Mar 26 15:32 /usr/lib/systemd/system/runlevel1.target -> rescue.target
Mar 26 15:32 /usr/lib/systemd/system/runlevel2.target -> multi-user.target
Mar 26 15:32 /usr/lib/systemd/system/runlevel3.target -> multi-user.target
Mar 26 15:32 /usr/lib/systemd/system/runlevel4.target -> multi-user.target
Mar 26 15:32 /usr/lib/systemd/system/runlevel5.target -> graphical.target
Mar 26 15:32 /usr/lib/systemd/system/runlevel6.target -> reboot.target
[root@oldboy60service01 ~]#
(3). 如何修改運行級別:
命令systemctl set-default
systemctl set-default graphical.target
[root@oldboy60service01 ~]# systemctl set-default graphical.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target.
[root@oldboy60service01 ~]#
(4). 查看運行級別
命令systemctl get-default
systemctl get-default
[root@oldboy60service01 ~]# systemctl get-default
multi-user.target
[root@oldboy60service01 ~]#
- /etc/fstab 開機自動掛載的列表
[root@oldboy60service01 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Mar 26 15:31:31 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
#
UUID=4dad89b5-9401-42d9-9685-0d9093647979 / xfs defaults 0 0
UUID=de6cdbf0-7d5a-475a-bb51-cde7e0627e06 /boot xfs defaults 0 0
UUID=0354a10b-4471-4fd4-94ff-d8d802206a31 swap swap defaults 0 0
- /etc/rc.local(完整路徑 /etc/rc.d/rc.local)開機運行的命令腳本
在CentOS 6中隨便可以寫
但是在CentOS 7中需要先配置耀盗,使用命令chmod +x(只需要配置一次)
[root@oldboy60service01 ~]# ls -l /etc/rc.d/rc.local
-rw-r--r--. 1 root root 473 Oct 31 07:31 /etc/rc.d/rc.local
[root@oldboy60service01 ~]# chmod +x /etc/rc.d/rc.local
[root@oldboy60service01 ~]# ls -l /etc/rc.d/rc.local
-rwxr-xr-x. 1 root root 473 Oct 31 07:31 */etc/rc.d/rc.local*
[root@oldboy60service01 ~]# vim /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
reboot
~
~
~
- /etc/init.d
在CentOS 6中用來存放服務(wù)器管理命令(腳本)
[root@oldboy60service01 ~]# ls -l /etc/init.d/
total 40
-rw-r--r--. 1 root root 18281 Aug 24 2018 functions
-rwxr-xr-x. 1 root root 4569 Aug 24 2018 netconsole
-rwxr-xr-x. 1 root root 7923 Aug 24 2018 *network*
-rw-r--r--. 1 root root 1160 Oct 31 07:31 README
在CentOS 7中是一個目錄
/usr/lib/systemd/system
-rw-r--r--. 1 root root 365 Oct 31 07:03 wpa_supplicant.service
[root@oldboy60service01 ~]# ls -l /usr/lib/systemd/system/network*
-rw-r--r--. 1 root root 464 Oct 31 07:31 /usr/lib/systemd/system/network-online.target
-rw-r--r--. 1 root root 461 Oct 31 07:31 /usr/lib/systemd/system/network-pre.target
-rw-r--r--. 1 root root 480 Oct 31 07:31 /usr/lib/systemd/system/network.target
[root@oldboy60service01 ~]#
- /etc/motd 會在用戶登錄系統(tǒng)之后顯示
[root@oldboy60service01 ~]# cat /etc/motd
佛祖保佑,永無BUG
[root@oldboy60service01 ~]#
- /etc/issue 會在用戶登錄系統(tǒng)之前顯示
[root@oldboy60service01 ~]# >/etc/issue
[root@oldboy60service01 ~]# cat /etc/issue
[root@oldboy60service01 ~]# cat /etc/issue.net
\S
Kernel \r on an \m
[root@oldboy60service01 ~]# echo oldboy >/etc/issue.net
[root@oldboy60service01 ~]# cat /etc/issue.net
oldboy
[root@oldboy60service01 ~]#
(>)大于號的作用就是:先清空文件內(nèi)容卦尊,再把信息寫入進去
4. /usr(user或unix software resource)用戶數(shù)據(jù)
/ 下的和 /usr 下的目錄類似
[root@oldboy60service01 ~]# tree -L 1 / /usr/
/
├── alex
├── bin -> usr/bin
├── boot
├── dev
├── etc
├── home
├── lib -> usr/lib
├── lib64 -> usr/lib64
├── media
├── mnt
├── opt
├── proc
├── root
├── run
├── sbin -> usr/sbin
├── srv
├── sys
├── tmp
├── usr
├── var
└── zhang
/usr/
├── bin
├── etc
├── games
├── include
├── lib
├── lib64
├── libexec
├── local
├── sbin
├── share
├── src
└── tmp -> ../var/tmp
33 directories, 0 files
[root@oldboy60service01 ~]#
/usr/local(編譯安裝的軟件)
備菜( ./configure), 炒菜(make), 上菜(make install)
LInux下面常見的安裝軟件方式
yum (yum install -y) 自動下載安裝
rpm 大型軟件需要自己解決依賴關(guān)系叛拷,自己安裝
編譯安裝:自己下載,自己安裝
rpm -ivh
-i 安裝 -v顯示 -h以人類可讀形式顯示
rpm -qa 查詢軟件是否安裝
[root@oldboy60service01 dev]# rpm -qa yum
yum-3.4.3-161.el7.centos.noarch
[root@oldboy60service01 dev]#
rpm -ql telnet(查看軟件包)
[root@oldboy60service01 dev]# rpm -ql yum
/usr/share/locale/cs/LC_MESSAGES/yum.mo
/usr/share/locale/da/LC_MESSAGES/yum.mo
/usr/share/locale/de/LC_MESSAGES/yum.mo
/usr/share/locale/el/LC_MESSAGES/yum.mo
/usr/share/locale/nl/LC_MESSAGES/yum.mo
/var/lib/yum/yumdb
[root@oldboy60service01 dev]#
5. /var系統(tǒng)日志
(1). /var/log
(2). /var/messages服務(wù)和系統(tǒng)信息
(3). /var/secure用戶登錄信息
Failed password用戶登錄系統(tǒng)密碼錯誤
6. /proc
(1). /proc/cpuinfo CPU信息
[root@oldboy60service01 ~]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 142
model name : Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
stepping : 9
microcode : 0x70
cpu MHz : 2712.000
cache size : 3072 KB
physical id : 0
siblings : 1
core id : 0
processor : 3 表示第4個核心(0 表示第一個核心)
physical id : 1 表示第2個CPU
[root@oldboy60service01 ~]# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 1 CPU核心
On-line CPU(s) list: 0 CPU編號
Thread(s) per core: 1
Core(s) per socket: 1 實際物理CPU個數(shù)(專業(yè)叫 “幾” 路)
Socket(s): 1 物理接口
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 142
Model name: Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
Stepping: 9
CPU MHz: 2712.000
CPU max MHz: 0.0000
CPU min MHz: 0.0000
BogoMIPS: 5424.00
Hypervisor vendor: VMware
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 3072K
NUMA node0 CPU(s): 0
Flags: fpu vme de pse tsc msr pae
[root@oldboy60service01 ~]#
CPU(s) : 表示CPU核心
Socket(s ) : 表示物理接口
(2). /proc/meminfo 內(nèi)存信息
[root@oldboy60service01 ~]# cat /proc/meminfo
MemTotal: 995896 kB
MemFree: 715736 kB
MemAvailable: 696088 kB
Buffers: 2076 kB
Cached: 89472 kB
SwapCached: 0 kB
[root@oldboy60service01 ~]# free -h
total used free shared buff/cache available
Mem: 972M 130M 698M 7.7M 143M 679M
Swap: 1.0G 0B 1.0G
以人類可讀的形式顯示 free -h 命令
[root@oldboy60service01 ~]# free
total used free shared buff/cache available
Mem: 995896 133292 715492 7836 147112 695856
Swap: 1048572 0 1048572
(3). /proc/loadavg平均負載猫牡,衡量系統(tǒng)繁忙程度指標
[root@oldboy60service01 ~]# cat /proc/loadavg
0.00 0.01 0.05 2/115 7726
[root@oldboy60service01 ~]#
0.00 表示1分鐘內(nèi)的負載數(shù)
0.01表示5分鐘內(nèi)的負載數(shù)
0.05表示15分鐘內(nèi)的負載數(shù)
[root@oldboy60service01 ~]# w
22:58:23 up 58 min, 2 users, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 22:00 57:59 0.03s 0.03s -bash
root pts/0 10.0.0.1 22:00 7.00s 0.08s 0.03s w
w 命令能顯示負載數(shù)
[root@oldboy60service01 ~]# uptime
23:01:22 up 1:01, 2 users, load average: 0.07, 0.03, 0.05
uptime === w 命令的第一行
如果負載接近于系統(tǒng)核心總數(shù)的時候表示忙
(4). /proc/mounts系統(tǒng)掛載信息
[root@oldboy60service01 ~]# 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
7.Linux啟動流程
(1).CentOS 6啟動流程
按下電源——開機自檢(BIOS)——MBR引導(dǎo)——GRUB菜單(選擇不同內(nèi)核胡诗,單用戶模式)——加載內(nèi)核(/boot加載到內(nèi)存)——運行INIT進程———
讀取/etc/inittab——讀取/etc/rc.sysinit初始化系統(tǒng)——根據(jù)運行級別運行/etc/rc數(shù)字.d下面的腳步/服務(wù)——啟動mingetty顯示登錄界面,運行l(wèi)ogin明哥tty
CentOS 6串行運行
(2).CentOS 7啟動流程
按下電源——開機自檢(BIOS)——MBR引導(dǎo)——GRUB菜單(救援模式)——加載內(nèi)核(systemd淌友,/etc/systemd/system/default.target讀取運行級別煌恢,/usr/lib/systemd/system/sysinit.target初始化系統(tǒng),并行.啟動服務(wù)震庭,/usr/lib/systemd/system/getty.target顯示login界面)
CentOS 7并行運行