打包压缩
压缩包工具
.zip
.bz2
.gz
tar.gz
tar.bz2
zip
zip
选项:
-r
-q
-T
unzip
选项:
-d
-l
-t
-q
[root@qls ~]
[root@qls ~]
[root@qls ~]
total 656
-rw-r--r--. 1 root root 670293 Aug 20 08:46 services
[root@qls ~]
adding: services (deflated 80%)
[root@qls ~]
total 792
-rw-r--r--. 1 root root 670293 Aug 20 08:46 services
-rw-r--r--. 1 root root 136227 Aug 20 08:46 ser.zip
[root@qls ~]
total 792K
-rw-r--r--. 1 root root 655K Aug 20 08:46 services
-rw-r--r--. 1 root root 134K Aug 20 08:46 ser.zip
[root@qls ~]
services ser.zip
[root@qls ~]
test of ser.zip OK
[root@qls ~]
Archive: services
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of services or
services.zip, and cannot find services.ZIP, period.
[root@qls ~]
total 792
-rw-r--r--. 1 root root 670293 Aug 20 08:46 services
-rw-r--r--. 1 root root 136227 Aug 20 08:46 ser.zip
[root@qls ~]
Archive: ser.zip
inflating: /opt/services
[root@qls ~]
total 656
-rw-r--r--. 1 root setgid 0 Aug 19 01:03 file9
-rw-r--r--. 1 root setgid 670293 Aug 20 08:46 services
gz格式,gzip
gzip
选项:
-d
-r
zcat
[root@qls ~]
[root@qls ~]
[root@qls ~]
bzip2
[root@qls ~]
[root@qls ~]
[root@qls ~]
tar
tar
选项
z
j
J
c
f
v
zcf
t
tf
x
xf
-C
P
h
X
--exclude
--exclude-from=xxx
[root@qls ~]
services
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls /]
[root@qls ~]
[root@qls ~]
tar: Removing leading `/' from member names
[root@qls ~]# tar Jcf etc.xz /etc
[root@qls ~]# tar zchf rc1.tzr.gz /etc/rc.local
[root@qls ~]# tar czf etc.tar.gz --exclude=/etc/hosts /etc
tar: Removing leading `/' from member names
[root@qls ~]# ll
total 9980
-rw-r--r--. 1 root root 10216073 Aug 20 09:52 etc.tar.gz
[root@qls ~]# tar tf etc.tar.gz | grep hosts
etc/selinux/targeted/active/modules/100/denyhosts/
etc/selinux/targeted/active/modules/100/denyhosts/cil
etc/selinux/targeted/active/modules/100/denyhosts/hll
etc/selinux/targeted/active/modules/100/denyhosts/lang_ext
etc/hosts.allow
etc/hosts.deny
[root@qls ~]# tar czf etc.tar.gz --exclude=/etc/{hosts,hostname} /etc
tar: Removing leading `/' from member names
[root@qls ~]# ll
total 9980
-rw-r--r--. 1 root root 10215980 Aug 20 09:54 etc.tar.gz
[root@qls ~]# tar tf etc.tar.gz | grep -E 'hosts|hostname'
etc/selinux/targeted/active/modules/100/denyhosts/
etc/selinux/targeted/active/modules/100/denyhosts/cil
etc/selinux/targeted/active/modules/100/denyhosts/hll
etc/selinux/targeted/active/modules/100/denyhosts/lang_ext
etc/selinux/targeted/active/modules/100/hostname/
etc/selinux/targeted/active/modules/100/hostname/cil
etc/selinux/targeted/active/modules/100/hostname/hll
etc/selinux/targeted/active/modules/100/hostname/lang_ext
etc/hosts.allow
etc/hosts.deny
etc/dbus-1/system.d/org.freedesktop.hostname1.conf
[root@qls ~]# tar czf etc.tar.gz --exclude=/etc/hosts --exclude=/etc/passwd /etc
tar: Removing leading `/' from member names
[root@qls ~]hosts|passwd'
etc/selinux/targeted/active/modules/100/denyhosts/
etc/selinux/targeted/active/modules/100/denyhosts/cil
etc/selinux/targeted/active/modules/100/denyhosts/hll
etc/selinux/targeted/active/modules/100/denyhosts/lang_ext
etc/hosts.allow
etc/hosts.deny
etc/passwd-
etc/security/opasswd
etc/pam.d/passwd
[root@qls ~]# cat paichu.list
/etc/hosts
/etc/hostname
/etc/passwd
/etc/fstab
/etc/services
[root@qls ~]# ll
total 9984
-rw-r--r--. 1 root root 10215966 Aug 20 09:55 etc.tar.gz
-rw-r--r--. 1 root root 62 Aug 20 09:56 paichu.list
[root@qls ~]# tar czf etc1.tar.gz -X paichu.list /etc
tar: Removing leading `/' from member names
[root@qls ~]# ll
total 19828
-rw-r--r--. 1 root root 10079106 Aug 20 09:58 etc1.tar.gz
-rw-r--r--. 1 root root 10215966 Aug 20 09:55 etc.tar.gz
-rw-r--r--. 1 root root 62 Aug 20 09:56 paichu.list
[root@qls ~]# tar tf etc1.tar.gz |grep -E 'hosts|hostname|passwd|fstab|services'
etc/selinux/targeted/active/modules/100/denyhosts/
etc/selinux/targeted/active/modules/100/denyhosts/cil
etc/selinux/targeted/active/modules/100/denyhosts/hll
etc/selinux/targeted/active/modules/100/denyhosts/lang_ext
etc/selinux/targeted/active/modules/100/hostname/
etc/selinux/targeted/active/modules/100/hostname/cil
etc/selinux/targeted/active/modules/100/hostname/hll
etc/selinux/targeted/active/modules/100/hostname/lang_ext
etc/selinux/targeted/active/modules/100/updfstab/
etc/selinux/targeted/active/modules/100/updfstab/cil
etc/selinux/targeted/active/modules/100/updfstab/hll
etc/selinux/targeted/active/modules/100/updfstab/lang_ext
etc/hosts.allow
etc/hosts.deny
etc/passwd-
etc/dbus-1/system.d/org.freedesktop.hostname1.conf
etc/security/opasswd
etc/pam.d/passwd
etc/firewalld/services/
[root@qls ~]# tar czf etc2.tar.gz --exclude-from=paichu.list /etc
tar: Removing leading `/' from member names
[root@qls ~]
total 29672
-rw-r--r--. 1 root root 10079106 Aug 20 09:58 etc1.tar.gz
-rw-r--r--. 1 root root 10079106 Aug 20 10:00 etc2.tar.gz
-rw-r--r--. 1 root root 10215966 Aug 20 09:55 etc.tar.gz
-rw-r--r--. 1 root root 62 Aug 20 09:56 paichu.list
tar与find的结合
[root@qls ~]
[root@qls ~]
find跟du结合
[root@qls ~]
[root@qls ~]
练习题
1.列出linux常用打包工具并写相应的压缩、解压缩参数
2.如何用gzip命令对文件进行压缩、解压缩,给出实践步骤。
gzip filename
gzip -d filename.gz
zcat filename.tar
3.如何用zip命令对文件以及目录进行压缩、解压缩,给出实践步骤。
zip filename.zip filename
zip -r dir.zip dir
unzip filename.zip
-d
4.创建一个自己名字的文件至/opt目录,给出实践步骤。
touch /opt/frank
5.打包opt/整个目录,并命名为opt_2019_08_19.tar.gz,给出实践步骤。
tar czf opt_2019_08_19.tar.gz /opt
[root@qls ~]
tar: Removing leading `/' from member names
[root@qls ~]# ll
total 40356
-rw-r--r--. 1 root root 10079106 Aug 20 09:58 etc1.tar.gz
-rw-r--r--. 1 root root 10079106 Aug 20 10:00 etc2.tar.gz
-rw-r--r--. 1 root root 10215966 Aug 20 09:55 etc.tar.gz
-rw-r--r--. 1 root root 353 Aug 20 10:05 log1.tar.gz
-rw-r--r--. 1 root root 288985 Aug 20 10:07 log2.tar.gz
-rw-r--r--. 1 root root 288985 Aug 20 10:03 log.tar.gz
-rw-r--r--. 1 root root 10352576 Aug 20 10:37 opt_2019_08_20.tar.gz
6.查看打包好的opt_2019_08_19.tar.gz里的文件,给出实践步骤。
tar tf opt_2019_08_19.tar.gz
7.将打包好的opt_2019_08_19.tar.gz内容指定解压至/tmp目录,并给出实践步骤。
tar xf opt_2019_08_19.tar.gz -C /tmp
8.打包以当前主机名+ip的命名方式的压缩包: 比如: www.oldboyedu.com_2019-08-19_10.0.0.99.tar.gz ,压缩/opt目录即可
主机名
时间
ip
[root@qls ~]# tar czf opt_$(hostname)_$(date +%F)_$(ifconfig eth0 |awk 'NR==2{print $2}').tar.gz /opt
tar: Removing leading `/' from member names
[root@qls ~]
total 50468
-rw-r--r--. 1 root root 10079106 Aug 20 09:58 etc1.tar.gz
-rw-r--r--. 1 root root 10079106 Aug 20 10:00 etc2.tar.gz
-rw-r--r--. 1 root root 10215966 Aug 20 09:55 etc.tar.gz
-rw-r--r--. 1 root root 353 Aug 20 10:05 log1.tar.gz
-rw-r--r--. 1 root root 288985 Aug 20 10:07 log2.tar.gz
-rw-r--r--. 1 root root 288985 Aug 20 10:03 log.tar.gz
-rw-r--r--. 1 root root 10352576 Aug 20 10:37 opt_2019_08_20.tar.gz
-rw-r--r--. 1 root root 10352576 Aug 20 10:41 opt_qls_2019-08-20_10.0.0.100.tar.gz
-rw-r--r--. 1 root root 62 Aug 20 09:56 paichu.list
date
[root@qls ~]
Tue Aug 20 10:42:19 CST 2019
[root@qls ~]
2019-08-20
[root@qls ~]
2019-08-20
[root@qls ~]
10:43:01
[root@qls ~]
10:43:27
[root@qls ~]
2
[root@qls ~]
33
[root@qls ~]
20
[root@qls ~]
1566269040
[root@qls ~]
19-08-20
[root@qls ~]
Mon Aug 19 10:46:06 CST 2019
[root@qls ~]
2019-08-19
[root@qls ~]
2019-08-21
[root@qls ~]
2020-08-20
[root@qls ~]
2018-08-20
[root@qls ~]
Fri Aug 30 00:00:00 CST 2019
[root@qls ~]
2019-08-30
[root@qls ~]
Fri Aug 30 10:48:00 CST 2019
[root@qls ~]
10:48:04
[root@qls ~]
[root@qls ~]
20 Aug 10:49:27 ntpdate[10174]: step time server 203.107.6.88 offset -863992.416377 sec
[root@qls ~]
Tue Aug 20 10:49:34 CST 2019
rpm包
tree-1.6.0-10.el7.x86_64.rpm
trang-20091111-14.el7.noarch.rpm
依赖性太强
[root@qls ~]
[root@qls ~]
Preparing...
Updating / installing...
1:tree-1.6.0-10.el7
[root@qls ~]
选项
-e
-i
-v
-h
-qa
-qi
-qc
-qf
-U
[root@qls ~]
net-tools-2.0-0.24.20131004git.el7.x86_64
[root@qls ~]
Retrieving https://mirrors.aliyun.com/centos/7.6.1810/os/x86_64/Packages/tree-1.6.0-10.el7.x86_64.rpm
Preparing...
Updating / installing...
1:tree-1.6.0-10.el7
安装低版本
[root@qls ~]
Retrieving https://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/7/x86_64/zabbix-agent-3.0.0-1.el7.x86_64.rpm
warning: /var/tmp/rpm-tmp.t6JBzJ: Header V4 DSA/SHA1 Signature, key ID 79ea5ed4: NOKEY
Preparing...
Updating / installing...
1:zabbix-agent-3.0.0-1.el7
升级
[root@qls ~]
Retrieving https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.0-2.el7.x86_64.rpm
warning: /var/tmp/rpm-tmp.0nJhRu: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing...
Updating / installing...
1:zabbix-agent-4.0.0-2.el7
Cleaning up / removing...
2:zabbix-agent-3.0.0-1.el7
yum
-y
[root@qls ~]
install
provides
search
update
check-update
repolist
list
list installed
clean
all
packages
info
history
remove
reinstall
[root@qls ~]
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1
源码编译:以nginx为例
预编译
make
make install
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls nginx-1.16.1]
[root@qls nginx-1.16.1]
checking for OS
+ Linux 3.10.0-957.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
解决:
[root@qls nginx-1.16.1]
报错
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
解决
[root@qls nginx-1.16.1]
报错
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
解决
[root@qls nginx-1.16.1]
[root@qls nginx-1.16.1]
0
[root@qls nginx-1.16.1]
[root@qls nginx-1.16.1]
0
[root@qls nginx-1.16.1]
[root@qls nginx-1.16.1]
0
[root@qls nginx-1.16.1]
total 4
drwxr-xr-x. 2 root root 4096 Aug 20 12:36 conf
drwxr-xr-x. 2 root root 40 Aug 20 12:36 html
drwxr-xr-x. 2 root root 6 Aug 20 12:36 logs
drwxr-xr-x. 2 root root 19 Aug 20 12:36 sbin
[root@qls nginx-1.16.1]
[root@qls nginx-1.16.1]
total 0
lrwxrwxrwx. 1 root root 18 Aug 20 12:37 nginx -> /app/nginx-1.16.1/
drwxr-xr-x. 6 root root 54 Aug 20 12:36 nginx-1.16.1
[root@qls nginx-1.16.1]
[root@qls nginx-1.16.1]
LISTEN 0 128 *:80 *:* users:(("nginx",pid=12928,fd=6),("nginx",pid=12927,fd=6))
[root@qls nginx-1.16.1]
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-08-20 12:31:46 CST; 7min ago
Docs: man:firewalld(1)
Main PID: 6927 (firewalld)
CGroup: /system.slice/firewalld.service
└─6927 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
Aug 20 12:31:44 qls systemd[1]: Starting firewalld - dynamic firewall daemon...
Aug 20 12:31:46 qls systemd[1]: Started firewalld - dynamic firewall daemon.
[root@qls nginx-1.16.1]
[root@qls nginx-1.16.1]
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
磁盘管理
1. 添加磁盘
2.进行分区
[root@qls ~]
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xe23878a4.
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xe23878a4
Device Boot Start End Blocks Id System
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +5G
Partition 1 of type Linux and of size 5 GiB is set
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xe23878a4
Device Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
3.格式化,创建文件系统
[root@qls ~]
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=327680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=1310720, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
4.创建挂载点,并进行挂载
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 48G 1.8G 46G 4% /
devtmpfs 980M 0 980M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 9.6M 981M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sda1 497M 120M 378M 25% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/sdb1 5.0G 33M 5.0G 1% /test_f
[root@qls ~]
[root@qls ~]
total 656
-rw-r--r--. 1 root root 670293 Aug 20 15:58 services
[root@qls ~]
[root@qls ~]
total 0
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
total 656
-rw-r--r--. 1 root root 670293 Aug 20 15:58 services
5.永久挂载
[root@qls ~]
/dev/sdb1 /test_1 xfs defaults 0 0
gdisk
GPT分区表,支持128分区
[root@qls ~]
[root@qls ~]
GPT fdisk (gdisk) version 0.8.10
Partition table scan:
MBR: not present
BSD: not present
APM: not present
GPT: not present
Creating new GPT entries.
Command (? for help): ?
b back up GPT data to a file
c change a partition's name
d delete a partition
i show detailed information on a partition
l list known partition types
n add a new partition
o create a new empty GUID partition table (GPT)
p print the partition table
q quit without saving changes
r recovery and transformation options (experts only)
s sort partitions
t change a partition's type code
v verify disk
w write table to disk and exit
x extra functionality (experts only)
? print this menu
Command (? for help): n
Partition number (1-128, default 1):
First sector (34-6442450910, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-6442450910, default = 6442450910) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): L
0700 Microsoft basic data 0c01 Microsoft reserved 2700 Windows RE
3000 ONIE boot 3001 ONIE config 4100 PowerPC PReP boot
4200 Windows LDM data 4201 Windows LDM metadata 7501 IBM GPFS
7f00 ChromeOS kernel 7f01 ChromeOS root 7f02 ChromeOS reserved
8200 Linux swap 8300 Linux filesystem 8301 Linux reserved
8302 Linux /home 8400 Intel Rapid Start 8e00 Linux LVM
a500 FreeBSD disklabel a501 FreeBSD boot a502 FreeBSD swap
a503 FreeBSD UFS a504 FreeBSD ZFS a505 FreeBSD Vinum/RAID
a580 Midnight BSD data a581 Midnight BSD boot a582 Midnight BSD swap
a583 Midnight BSD UFS a584 Midnight BSD ZFS a585 Midnight BSD Vinum
a800 Apple UFS a901 NetBSD swap a902 NetBSD FFS
a903 NetBSD LFS a904 NetBSD concatenated a905 NetBSD encrypted
a906 NetBSD RAID ab00 Apple boot af00 Apple HFS/HFS+
af01 Apple RAID af02 Apple RAID offline af03 Apple label
af04 AppleTV recovery af05 Apple Core Storage be00 Solaris boot
bf00 Solaris root bf01 Solaris /usr & Mac Z bf02 Solaris swap
bf03 Solaris backup bf04 Solaris /var bf05 Solaris /home
bf06 Solaris alternate se bf07 Solaris Reserved 1 bf08 Solaris Reserved 2
bf09 Solaris Reserved 3 bf0a Solaris Reserved 4 bf0b Solaris Reserved 5
c001 HP-UX data c002 HP-UX service ea00 Freedesktop $BOOT
eb00 Haiku BFS ed00 Sony system partitio ed01 Lenovo system partit
Press the <Enter> key to see more codes:
ef00 EFI System ef01 MBR partition scheme ef02 BIOS boot partition
fb00 VMWare VMFS fb01 VMWare reserved fc00 VMWare kcore crash p
fd00 Linux RAID
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
Command (? for help): p
Disk /dev/sdc: 6442450944 sectors, 3.0 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): E2A6B39D-0ACA-4E24-AFEE-10AC07DFB9C9
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 6442450910
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)
Number Start (sector) End (sector) Size Code Name
1 2048 6442450910 3.0 TiB 8300 Linux filesystem
Command (? for help): p
Disk /dev/sdc: 6442450944 sectors, 3.0 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): E2A6B39D-0ACA-4E24-AFEE-10AC07DFB9C9
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 6442450910
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)
Number Start (sector) End (sector) Size Code Name
1 2048 6442450910 3.0 TiB 8300 Linux filesystem
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdc.
The operation has completed successfully.
[root@qls ~]
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 500M 0 part /boot
├─sda2 8:2 0 2G 0 part [SWAP]
└─sda3 8:3 0 47.5G 0 part /
sdb 8:16 0 20G 0 disk
└─sdb1 8:17 0 5G 0 part /test_1
sdc 8:32 0 3T 0 disk
└─sdc1 8:33 0 3T 0 part
sr0 11:0 1 4.3G 0 rom
[root@qls ~]
meta-data=/dev/sdc1 isize=512 agcount=4, agsize=201326527 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=805306107, imaxpct=5
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=393215, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
total 656
-rw-r--r--. 1 root root 670293 Aug 20 16:42 services
[root@qls ~]
[root@qls ~]
[root@qls ~]
total 0
[root@qls ~]
total 0
[root@qls ~]
[root@qls ~]
total 656
-rw-r--r--. 1 root root 670293 Aug 20 16:42 services
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
total 4
-rw-r--r--. 1 root root 158 Aug 20 16:43 hosts
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
total 656
-rw-r--r--. 1 root root 670293 Aug 20 16:42 services
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
total 4
-rw-r--r--. 1 root root 158 Aug 20 16:43 hosts
磁盘的挂载方式
mount
选项
-o
-a
-t
[root@qls ~]
/dev/sr0: UUID="2018-11-25-23-54-16-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/sda1: UUID="ffc53ebe-1964-4fe9-b761-01b1e0a0e2af" TYPE="xfs"
ev/sda2: UUID="e2ed12e8-15c2-4061-806e-a02f7847c0d0" TYPE="swap"
▽dev/sda3: UUID="400a5819-809d-43b4-a323-30f4c3ac7bf0" TYPE="xfs"
/dev/sdb1: UUID="905bb897-c545-4ee6-b8e9-53436eadaf18" TYPE="xfs"
/dev/sdc1: UUID="9d441e76-17a1-48f9-a49b-28e3e9ea8d20" TYPE="xfs" PARTLABEL="Linux filesystem" PARTUUID="0bd340a4-52c0-46a0-9cb7-75e771d9be1b"
[root@qls ~]
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 48G 1.9G 46G 4% /
devtmpfs 980M 0 980M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 9.7M 981M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sdb1 5.0G 33M 5.0G 1% /test_1
/dev/sda1 497M 120M 378M 25% /boot
tmpfs 199M 0 199M 0% /run/user/0
[root@qls ~]
umount
选项
-l
出现卸载不掉的情况下
1. 使用强制卸载
2. 切换到其他目录进行卸载
/etc/fstab配置文件
[root@qls ~]
UUID=9d441eb-28e3e9ea8d20 /gpt xfs defaults 0 0
第一列:挂载的设备名,可以使用UUID,还可以网络地址
第二列:挂载点,挂载的入口
第三列:文件系统的类型
第四列:挂载的参数。defaults
参数 |
含义 |
async/sync |
是否同步方式运行,默认async(异步)。 |
user/nouser |
是否允许普通用户使用mount命令挂载,默认nouser。 |
exec/noexec |
是否允许可执行文件执行,默认exec。 |
suid/nosuid |
是否允许存在suid属性的文件,默认suid。 |
auto/noauto |
执行mount -a时,此文件系统是否被主动挂载,默认auto。 |
rw/ro |
是否只读或者读写模式进行挂载。默认rw。 |
defaults |
具有rw,suid,exec,auto,nouser,async等默认参数的设定。 |
第五列:是否通过dump进行备份,0 不备份 ,1 每天备份 2 不定期的备份
第六列:是否检查磁盘,0 不检查 ,1 检查,按照顺序检查,1只能给/
swap
oom
临时添加虚拟内存
[root@qls ~]
10+0 records in
10+0 records out
1048576000 bytes (1.0 GB) copied, 29.8756 s, 35.1 MB/s
[root@qls ~]
[root@qls ~]
Setting up swapspace version 1, size = 1023996 KiB
no label, UUID=d849c5bf-b582-46f6-816e-301ab190bb3a
[root@qls ~]
swap.txt: Linux/i386 swap file (new style), version 1 (4K pages), size 255999 pages, no label, UUID=d849c5bf-b582-46f6-816e-301ab190bb3a
[root@qls ~]
total used free shared buff/cache available
Mem: 1980 106 561 9 1313 1677
Swap: 2047 0 2047
[root@qls ~]
swapon: /root/swap.txt: insecure permissions 0644, 0600 suggested.
[root@qls ~]
total used free shared buff/cache available
Mem: 1980 106 560 9 1313 1676
Swap: 3047 0 3047
[root@qls ~]
[root@qls ~]
total used free shared buff/cache available
Mem: 1980 106 560 9 1313 1677
Swap: 2047 0 2047
[root@qls ~]
Filename Type Size Used Priority
/dev/sda2 partition 2097148 0 -2
/root/swap.txt file 1023996 0 -3
[root@qls ~]
[root@qls ~]
total used free shared buff/cache available
Mem: 1980 106 562 9 1312 1677
Swap: 0 0 0
[root@qls ~]
[root@qls ~]
total used free shared buff/cache available
Mem: 1980 106 562 9 1312 1677
Swap: 2047 0 2047
磁盘故障
block 慢
[root@qls ~]
cp: error writing ‘/data/Desktop.zip’: No space left on device
cp: failed to extend ‘/data/Desktop.zip’: No space left on device
[root@qls ~]
du: cannot access ‘/proc/7780/task/7780/fd/4’: No such file or directory
du: cannot access ‘/proc/7780/task/7780/fdinfo/4’: No such file or directory
du: cannot access ‘/proc/7780/fd/4’: No such file or directory
du: cannot access ‘/proc/7780/fdinfo/4’: No such file or directory
1.1G /root
1.5G /usr
5.1G /var
[root@qls ~]
4.9G /var/log
[root@qls ~]
4.9G /var/log/test.log
[root@qls ~]
index慢了
[root@qls ~]
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda3 24909312 263092 24646220 2% /
devtmpfs 250786 403 250383 1% /dev
tmpfs 253511 1 253510 1% /dev/shm
tmpfs 253511 766 252745 1% /run
tmpfs 253511 16 253495 1% /sys/fs/cgroup
/dev/sdb1 2621440 4 2621436 1% /test_1
/dev/sda1 256000 326 255674 1% /boot
tmpfs 253511 1 253510 1% /run/user/0
[root@qls ~]
drwxr-xr-x. 2 1001 1001 4.7M Aug 20 17:34 /root/nginx-1.16.1/conf
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
10
开机启动流程
01) 按下电源
02) 开机BIOS自检
03) MBR引导系统
04) GRUB菜单
05) 加载内核
06) 启动系统进程(使用systemd进行管理)
07) 读取运行级别
08) 进行系统初始化
09) 启动开机自动启动服务(并行启动)
10) 运行getty文件,进入登录页面
运行级别
[root@qls ~]
lrwxrwxrwx. 1 root root 15 Aug 14 15:11 /usr/lib/systemd/system/runlevel0.target -> poweroff.target
lrwxrwxrwx. 1 root root 13 Aug 14 15:11 /usr/lib/systemd/system/runlevel1.target -> rescue.target
lrwxrwxrwx. 1 root root 17 Aug 14 15:11 /usr/lib/systemd/system/runlevel2.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Aug 14 15:11 /usr/lib/systemd/system/runlevel3.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Aug 14 15:11 /usr/lib/systemd/system/runlevel4.target -> multi-user.target
lrwxrwxrwx. 1 root root 16 Aug 14 15:11 /usr/lib/systemd/system/runlevel5.target -> graphical.target
lrwxrwxrwx. 1 root root 13 Aug 14 15:11 /usr/lib/systemd/system/runlevel6.target -> reboot.target
System 运行级别 |
Systemd目标名称 |
作用 |
0 |
runlevel0.target,poweroff.target |
关机 |
1 |
runlevel1.target,rescue.target |
单用户模式 |
2 |
runlevel2.target,multi.target |
多用户模式 |
3 |
runlevel3.target,multi.target |
多用户模式 |
4 |
runlevel4.target,multi.target |
多用户模式 |
5 |
runlevel5.target,graphical.target |
图形界面或桌面模式 |
6 |
runlevel6.target,reboot.target |
重启 |
[root@qls ~]
multi-user.target
[root@qls ~]
N 3
[root@qls ~]
[root@qls ~]
主配置文件
ll /etc/systemd/system/default.target
systemd
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
单用户修改root密码
1、重新启动或开启CentOS-7系统,在选择进入系统的Grub菜单界面有提示按e时,按e进入编辑界面
2、找到Linux16这行,将磁盘改为rw读写模式,然后再在后面添加如下:
init=/bin/bash enforcing=0
3、ctrl+x以单用户模式启动
4、在命令行执行:
mount -o rw,remount /
passwd root
5、执行 exec /sbin/init 命令重启系统