打包压缩


压缩包工具.zip       #zip压缩工具    .bz2        #bzip2压缩工具,只能压缩文件,会删除源文件.gz           #gzip压缩工具,只能压缩文件,会删除源文件tar.gz     #gzip压缩,使用tar打包tar.bz2       #使用bzip2压缩,使用tar打包

zip


zip     #打包压缩
选项:-r        #递归压缩-q     #静默输出-T     #检查压缩包是完整unzip  #解压zip格式的压缩包
选项:-d        #指定解压的目录-l      #查看压缩包的内容-t     #检查压缩包里面的内容是否完整-q       #静默输出#下载安装
[root@qls ~]# yum  install -y  zip  unzip[root@qls ~]# cp  /etc/services   ./
[root@qls ~]# ll
total 656
-rw-r--r--. 1 root root 670293 Aug 20 08:46 services
[root@qls ~]# zip  ser.zip   services adding: services (deflated 80%)
[root@qls ~]# ll
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 ~]# ll -h
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 ~]# zip -T ser
services  ser.zip
[root@qls ~]# zip -T ser.zip
test of ser.zip OK
[root@qls ~]# unzip  services
Archive:  servicesEnd-of-central-directory signature not found.  Either this file is nota zipfile, or it constitutes one disk of a multi-part archive.  In thelatter case the central directory and zipfile comment will be found onthe last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of services orservices.zip, and cannot find services.ZIP, period.
[root@qls ~]# ll
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 ~]# unzip ser.zip   -d  /opt/
Archive:  ser.zipinflating: /opt/services
[root@qls ~]# ll /opt/
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 #查看gzip格式压缩包[root@qls ~]# gzip  services
[root@qls ~]# zcat  services.gz
[root@qls ~]# gzip  -d  services.gz

bzip2


#只能压缩文件,会删除源文件[root@qls ~]# bzip2  services     #压缩
[root@qls ~]# bzcat  services.bz2  #查看压缩包的内容
[root@qls ~]# bzip2 -d services.bz2    #解压

tar


tar     #打包工具
选项z #使用gzip格式压缩j    #使用bzip2格式压缩J   #使用xz格式压缩c  #创建压缩包f #指定压缩包名v    #显示打包过程zcft #查看压缩包里面的内容tfx  #解压,根据压缩自动解压xf-C #指定解压路径P    #使用绝对路径打包h  #打包软连接X #指定排除列表--exclude    #排除--exclude-from=xxx  #排除列表[root@qls ~]# tar  zcvf  services.tar.gz  services
services[root@qls ~]# tar  zcf  etc.tar.gz  /etc[root@qls ~]# tar  xf  etc.tar.gz[root@qls ~]# tar xf  etc.tar.gz   -C  /opt/#解除压缩时,删根的操作
[root@qls ~]# cd  /
[root@qls /]# tar  zcf  root/etc.tar.gz  etc/[root@qls ~]# tar  zcPf  etc1.tar.gz  /etc[root@qls ~]# tar  jcf  etc.bz2  /etc         #使用bz2格式打包
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 ~]# tar  tf etc.tar.gz  |  grep  -E '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 ~]# ll
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 ~]# find /var/log/  -name '*.log'  | xargs  tar  log.tar.gz #错误的打包方式,不可取
[root@qls ~]# find /var/log/  -name '*.log'  -exec  tar czf  log1.tar.gz  {} \;

find跟du结合


[root@qls ~]# find  /etc  -type d  -maxdepth  1   | sed  -r  's#(.*)# du -sh \1#g'  |bash[root@qls ~]# ls  -d  /* |xargs  du -sh

练习题


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/frank5.打包opt/整个目录,并命名为opt_2019_08_19.tar.gz,给出实践步骤。tar  czf  opt_2019_08_19.tar.gz  /opt[root@qls ~]# tar  czf  opt_$(date  +%Y_%m_%d).tar.gz  /opt
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.gz6.查看打包好的opt_2019_08_19.tar.gz里的文件,给出实践步骤。tar  tf   opt_2019_08_19.tar.gz7.将打包好的opt_2019_08_19.tar.gz内容指定解压至/tmp目录,并给出实践步骤。tar  xf  opt_2019_08_19.tar.gz  -C  /tmp8.打包以当前主机名+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 ~]# ll
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 ~]# date
Tue Aug 20 10:42:19 CST 2019
[root@qls ~]# date +%F
2019-08-20
[root@qls ~]# date +%Y-%m-%d
2019-08-20
[root@qls ~]# date  +%T
10:43:01
[root@qls ~]# date  +%H:%M:%S
10:43:27
[root@qls ~]# date +%w
2
[root@qls ~]# date +%W
33
[root@qls ~]# date +%d
20
[root@qls ~]# date +%s
1566269040
[root@qls ~]# date +%y-%m-%d
19-08-20
[root@qls ~]# date -d  '-1day'
Mon Aug 19 10:46:06 CST 2019
[root@qls ~]# date -d  '-1day' +%F
2019-08-19
[root@qls ~]# date -d  '+1day' +%F
2019-08-21
[root@qls ~]# date -d  '+1year' +%F
2020-08-20
[root@qls ~]# date -d  '-1year' +%F
2018-08-20
[root@qls ~]# date -s  '2019/08/30'
Fri Aug 30 00:00:00 CST 2019
[root@qls ~]# date +%F
2019-08-30
[root@qls ~]# date -s  '10:48:00'
Fri Aug 30 10:48:00 CST 2019
[root@qls ~]# date +%T
10:48:04
[root@qls ~]# yum install -y  ntpdate
[root@qls ~]# ntpdate  ntp.aliyun.com
20 Aug 10:49:27 ntpdate[10174]: step time server 203.107.6.88 offset -863992.416377 sec
[root@qls ~]# date
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 ~]# mount  /dev/cdrom   /mnt[root@qls ~]# rpm  -ivh /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...1:tree-1.6.0-10.el7                ################################# [100%][root@qls ~]# yum install -y samba选项-e      #卸载软件包-i        #安装-v       #显示安装的过程-h      #查看安装的进度-qa     #查看软件包是否安装-qi       #显示软件包详细信息-qc       #查询软件包的配置文件-qf      #搜索命令属于哪个软件包,本地要有这个命令-U      #升级[root@qls ~]# rpm -qf  /usr/sbin/ifconfig
net-tools-2.0-0.24.20131004git.el7.x86_64[root@qls ~]# rpm -ivh https://mirrors.aliyun.com/centos/7.6.1810/os/x86_64/Packages/tree-1.6.0-10.el7.x86_64.rpm
Retrieving https://mirrors.aliyun.com/centos/7.6.1810/os/x86_64/Packages/tree-1.6.0-10.el7.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...1:tree-1.6.0-10.el7                ################################# [100%]安装低版本
[root@qls ~]# rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/7/x86_64/zabbix-agent-3.0.0-1.el7.x86_64.rpm
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...                          ################################# [100%]
Updating / installing...1:zabbix-agent-3.0.0-1.el7         ################################# [100%]升级
[root@qls ~]# rpm -Uvh  https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.0-2.el7.x86_64.rpm
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...                          ################################# [100%]
Updating / installing...1:zabbix-agent-4.0.0-2.el7         ################################# [ 50%]
Cleaning up / removing...2:zabbix-agent-3.0.0-1.el7         ################################# [100%]

yum


-y      #免交互#本地安装
[root@qls ~]# yum  localinstall  /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm install            #安装
provides        #查询命令属于哪个软件包
search          #搜寻软件包
update          #更新
check-update    #检查系统可更新的包
repolist        #查看yum源镜像仓库
list             #查看可安装的包
list installed   #查看系统中已经安装的包
clean           #清空缓存all        #清空所有packages   #清空软件包
info            #查看软件包的详细信息
history         #yum命令的历史事物
remove          #卸载软件
reinstall       #遇到配置被删除,可以重新安装[root@qls ~]# head  /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever  #缓存生成路径
keepcache=1        #开启缓存

源码编译:以nginx为例


预编译
make
make  install#下载源码包
[root@qls ~]# wget http://nginx.org/download/nginx-1.16.1.tar.gz#解压
[root@qls ~]# tar  xf nginx-1.16.1.tar.gz[root@qls ~]# cd nginx-1.16.1#安装依赖
[root@qls nginx-1.16.1]# yum  install  gcc-devel  gcc pcre  pcre-devel openssl  openssl-devel -y[root@qls nginx-1.16.1]# ./configure   --prefix=/app/nginx-1.16.1  --with-http_ssl_modulechecking 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]# yum  install  gcc-devel  gcc  -y报错
./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]# yum install  -y pcre  pcre-devel报错
./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]# yum install openssl  openssl-devel  -y [root@qls nginx-1.16.1]# echo  $?
0[root@qls nginx-1.16.1]#  make[root@qls nginx-1.16.1]# echo  $?
0[root@qls nginx-1.16.1]# make install[root@qls nginx-1.16.1]# echo  $?
0[root@qls nginx-1.16.1]# ll /app/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]# ln  -s  /app/nginx-1.16.1/  /app/nginx
[root@qls nginx-1.16.1]# ll /app/
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]# /app/nginx/sbin/nginx
[root@qls nginx-1.16.1]# ss -lntp|grep 80
LISTEN     0      128          *:80                       *:*                   users:(("nginx",pid=12928,fd=6),("nginx",pid=12927,fd=6))[root@qls nginx-1.16.1]# systemctl  status firewalld
● firewalld.service - firewalld - dynamic firewall daemonLoaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)Active: active (running) since Tue 2019-08-20 12:31:46 CST; 7min agoDocs: man:firewalld(1)Main PID: 6927 (firewalld)CGroup: /system.slice/firewalld.service└─6927 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopidAug 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]# systemctl  stop  firewalld
[root@qls nginx-1.16.1]# systemctl  disable   firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

磁盘管理


#使用fdisk进行分区,支持2TB下的分区,使用MBR分区表
1. 添加磁盘2.进行分区
[root@qls ~]# fdisk   /dev/sdb
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 actiona   toggle a bootable flagb   edit bsd disklabelc   toggle the dos compatibility flagd   delete a partitiong   create a new empty GPT partition tableG   create an IRIX (SGI) partition tablel   list known partition typesm   print this menun   add a new partitiono   create a new empty DOS partition tablep   print the partition tableq   quit without saving changess   create a new empty Sun disklabelt   change a partition's system idu   change display/entry unitsv   verify the partition tablew   write table to disk and exitx   extra functionality (experts only)Command (m for help): pDisk /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: 0xe23878a4Device Boot      Start         End      Blocks   Id  SystemCommand (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 setCommand (m for help): pDisk /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: 0xe23878a4Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10487807     5242880   83  LinuxCommand (m for help): w
The partition table has been altered!Calling ioctl() to re-read partition table.3.格式化,创建文件系统
[root@qls ~]# mkfs.xfs     /dev/sdb1
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=04.创建挂载点,并进行挂载
[root@qls ~]# mkdir   /test_f
[root@qls ~]#
[root@qls ~]#
[root@qls ~]# mount  /dev/sdb1  /test_f
[root@qls ~]# df -h
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 ~]# cp  /etc/services  /test_f/
[root@qls ~]# ll /test_f/
total 656
-rw-r--r--. 1 root root 670293 Aug 20 15:58 services[root@qls ~]# umount  /dev/sdb1
[root@qls ~]# ll /test_f/
total 0
[root@qls ~]# mkdir   /test_1
[root@qls ~]#
[root@qls ~]# mount  /dev/sdb1  /test_1
[root@qls ~]# ll /test_1
total 656
-rw-r--r--. 1 root root 670293 Aug 20 15:58 services5.永久挂载
[root@qls ~]# tail -1  /etc/fstab
/dev/sdb1                                 /test_1                 xfs     defaults        0 0

gdisk


GPT分区表,支持128分区#安装gdisk
[root@qls ~]# yum  install  gdisk  -y[root@qls ~]# gdisk  /dev/sdc
GPT fdisk (gdisk) version 0.8.10Partition table scan:MBR: not presentBSD: not presentAPM: not presentGPT: not presentCreating 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 menuCommand (? 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  Name1            2048      6442450910   3.0 TiB     8300  Linux filesystemCommand (? 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  Name1            2048      6442450910   3.0 TiB     8300  Linux filesystemCommand (? for help): wFinal 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 ~]# lsblk
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 ~]# mkfs.xfs   /dev/sdc1
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 ~]# mkdir  /gpt
[root@qls ~]#
[root@qls ~]#
[root@qls ~]# mount  /dev/sdc1  /gpt
[root@qls ~]#
[root@qls ~]#
[root@qls ~]# cp /etc/services  /gpt
[root@qls ~]#
[root@qls ~]#
[root@qls ~]# ll /gpt
total 656
-rw-r--r--. 1 root root 670293 Aug 20 16:42 services
[root@qls ~]# umount  /gpt
[root@qls ~]#
[root@qls ~]# ll /gpt
total 0
[root@qls ~]# ll /opt/
total 0
[root@qls ~]# mount   /dev/sdc1  /opt/
[root@qls ~]# ll /opt/
total 656
-rw-r--r--. 1 root root 670293 Aug 20 16:42 services
[root@qls ~]# umount /opt/
[root@qls ~]#
[root@qls ~]#
[root@qls ~]# cp /etc/hosts  /opt
[root@qls ~]#
[root@qls ~]#
[root@qls ~]# ll /opt
total 4
-rw-r--r--. 1 root root 158 Aug 20 16:43 hosts
[root@qls ~]#
[root@qls ~]#
[root@qls ~]# mount   /dev/sdc1  /opt/
[root@qls ~]# ll /opt/
total 656
-rw-r--r--. 1 root root 670293 Aug 20 16:42 services
[root@qls ~]# umount  /opt
[root@qls ~]#
[root@qls ~]#
[root@qls ~]# ll /opt
total 4
-rw-r--r--. 1 root root 158 Aug 20 16:43 hosts

磁盘的挂载方式


mount       #挂载磁盘
选项-o        #指定挂载的参数-a      #重新挂载/etc/fstab中的挂载列表-t     #指定挂载文件系统,xfs    是7系统默认的, ext4 6系统默认[root@qls ~]# blkid
/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 ~]# df -h
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 ~]# mount  UUID="9d441e76-17a1-48f9-a49b-28e3e9ea8d20"  /gptumount    #卸载磁盘
选项-l        #强制卸载出现卸载不掉的情况下1. 使用强制卸载2. 切换到其他目录进行卸载

/etc/fstab配置文件


[root@qls ~]# tail  -1  /etc/fstab
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  临时添加虚拟内存#1. 生成一个1G的大文件
[root@qls ~]# dd  </dev/zero  >/root/swap.txt  bs=100M  count=10
10+0 records in
10+0 records out
1048576000 bytes (1.0 GB) copied, 29.8756 s, 35.1 MB/s#修改权限
[root@qls ~]# chmod  600  swap.txt #2.让这个成为swap文件
[root@qls ~]# mkswap   -f  swap.txt
Setting up swapspace version 1, size = 1023996 KiB
no label, UUID=d849c5bf-b582-46f6-816e-301ab190bb3a
[root@qls ~]# file  swap.txt
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 ~]# free -mtotal        used        free      shared  buff/cache   available
Mem:           1980         106         561           9        1313        1677
Swap:          2047           0        2047#3.添加swap大小
[root@qls ~]# swapon  swap.txt
swapon: /root/swap.txt: insecure permissions 0644, 0600 suggested.
[root@qls ~]# free -mtotal        used        free      shared  buff/cache   available
Mem:           1980         106         560           9        1313        1676
Swap:          3047           0        3047[root@qls ~]# swapoff  swap.txt     #缩减swap空间
[root@qls ~]# free -mtotal        used        free      shared  buff/cache   available
Mem:           1980         106         560           9        1313        1677
Swap:          2047           0        2047[root@qls ~]# swapon -s     #检查当前swap使用那些分区
Filename                Type        Size    Used    Priority
/dev/sda2                               partition   2097148 0   -2
/root/swap.txt                          file    1023996 0   -3#禁用swap[root@qls ~]# swapoff -a
[root@qls ~]# free -mtotal        used        free      shared  buff/cache   available
Mem:           1980         106         562           9        1312        1677
Swap:             0           0           0#开启swap
[root@qls ~]# swapon -a
[root@qls ~]# free -mtotal        used        free      shared  buff/cache   available
Mem:           1980         106         562           9        1312        1677
Swap:          2047           0        2047

磁盘故障


block 慢
[root@qls ~]# cp Desktop.zip  /data/
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  -sh  /* |grep  G
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 ~]# du  -sh  /var/* |grep  G
4.9G    /var/log
[root@qls ~]# du  -sh  /var/log/* |grep  G
4.9G    /var/log/test.log#确认之后再删除[root@qls ~]# rm -f /var/log/test.logindex慢了[root@qls ~]# df -i
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 ~]# find  / -type d  -size +3M   |xargs  ls -lhd
drwxr-xr-x. 2 1001 1001 4.7M Aug 20 17:34 /root/nginx-1.16.1/conf#确认好在删除
[root@qls ~]# find  /root/nginx-1.16.1/conf  -type f  -name '*txt' |xargs   rm -f
[root@qls ~]# find  /root/nginx-1.16.1/conf  -type f  -name '*sh' |xargs   rm -f
[root@qls ~]# find  /root/nginx-1.16.1/conf  -type f  -name '*py' |xargs   rm -f
[root@qls ~]# find  /root/nginx-1.16.1/conf  -type f  -name '*log' |xargs   rm -f
[root@qls ~]#
[root@qls ~]#
[root@qls ~]# ll /root/nginx-1.16.1/conf |wc -l
10

开机启动流程


#简单说明CentOS-7系统启动过程:
​
01) 按下电源
​
02) 开机BIOS自检
​
03) MBR引导系统
​
04) GRUB菜单
​
05) 加载内核
​
06) 启动系统进程(使用systemd进行管理)
​
07) 读取运行级别
​
08) 进行系统初始化
​
09) 启动开机自动启动服务(并行启动)
​
10) 运行getty文件,进入登录页面运行级别
[root@qls ~]# ll /usr/lib/systemd/system/runlevel*.target
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 ~]# systemctl   get-default  #查看运行级别
multi-user.target
[root@qls ~]# runlevel
N 3
[root@qls ~]# systemctl   set-default  graphical.target    #切换运行级别[root@qls ~]# init  5主配置文件ll /etc/systemd/system/default.target

systemd


#systemctl管理服务的启动、停止、重启、重载、状态等常用命令
​
[root@qls ~]# systemctl start vsftpd        #启动
​
[root@qls ~]# systemctl stop vsftpd         #停止
​
[root@qls ~]# systemctl status vsftpd       #查看运行状态
​
[root@qls ~]# systemctl restart vsftpd      #重启
​
[root@qls ~]# systemctl reload  vsftpd      #重载
​
[root@qls ~]# systemctl mask  vsftpd        #禁止服务运行
​
[root@qls ~]# systemctl unmask  vsftpd      #取消禁止服务运行[root@qls ~]# systemctl enable vsftpd        #开机自启[root@qls ~]# systemctl disable  vsftpd   #关闭开机自启

单用户修改root密码

1、重新启动或开启CentOS-7系统,在选择进入系统的Grub菜单界面有提示按e时,按e进入编辑界面
2、找到Linux16这行,将磁盘改为rw读写模式,然后再在后面添加如下:
init=/bin/bash enforcing=0 #(前者作用让系统登录后加载bash解释器,后者是且关闭Selinux)
3、ctrl+x以单用户模式启动
4、在命令行执行:mount -o rw,remount /  # 重新挂载根目录,如果前面改了rw,这里可以不执行passwd root  # 设置root用户密码
5、执行 exec /sbin/init 命令重启系统

Linux-打包压缩-date-rpm-yum-磁盘管理(分区fdisk/gdisk)-systemd-修改root密码相关推荐

  1. linux学习教程-硬盘介绍和磁盘管理v11

    全套学习资料移步至公众号[学神来啦]更多学习资料添加扣扣资源群:661308959 本节所讲内容:   12.1  SAS-SATA-SSD-SCSI-IDE硬盘讲解   12.2  磁盘分区工具和挂 ...

  2. linux下的打包和解压缩命令,浅析Linux打包压缩解压缩命令大全(收藏)

    下面是小编日常收集整理的关于linux打包压缩解压缩命令大全,具体内容如下所述: tar命令 解包:tar zxvf FileName.tar 打包:tar czvf FileName.tar Dir ...

  3. linux学习笔记(6)磁盘管理

    linux学习笔记(6)磁盘管理 文章目录   6.1磁盘命名   6.2分区方式   6.3磁盘管理     6.3.1基本分区     6.3.2逻辑卷LVM     6.3.3交换分区管理Swa ...

  4. Linux操作系统6:文件系统及磁盘管理

    Linux操作系统6:文件系统及磁盘管理 一.实验目的: 二.实验内容: 三.实验结果: (1)使用 fdisk 命令进行硬盘分区 (2)用 mkfs 创建文件系统. (3)用 fsck 检查文件系统 ...

  5. linux打包命令tgz,浅析Linux打包压缩解压缩命令大全(收藏)

    下面是小编日常收集整理的关于linux打包压缩解压缩命令大全,具体内容如下所述: tar命令 解包:tar zxvf FileName.tar 打包:tar czvf FileName.tar Dir ...

  6. linux tar 打包gzip,tar linux 打包 压缩 gzip 命令说明

    参数: -c  :建立一个压缩档案的参数指令(create 的意思): -x  :解开一个压缩档案的参数指令! -t  :查看 tarfile 里面的档案! 特别注意,在参数的下达中, c/x/t 仅 ...

  7. centos图形化磁盘文件管理_CentOS7磁盘管理-分区扩容-使用gparted图形化工具或系统命令...

    centOS7磁盘管理-分区扩容-使用gparted图形化工具或系统命令 @了解centos下磁盘结构 无标题.png 解释 PE - 物理块(Physical Extent) 硬盘上有很多实际物理存 ...

  8. linux格式化fat的命令,在Linux中使用mkfs命令格式化磁盘或分区上的文件系统

    mkfs是Linux中的命令行工具,用于在您选择的特定文件系统中格式化磁盘或分区.本篇文章分享了如何在Linux中使用mkfs命令格式化磁盘或分区上的文件系统 mkfs代表" make fi ...

  9. 麒麟服务器系统磁盘管理之fdisk

    麒麟服务器系统磁盘管理之fdisk 1. 对磁盘进行分区 前提条件: 已登录服务器系统. 已挂载数据盘到服务器,且该盘未初始化. 查看新增数据盘 root@localhost 桌面]# fdisk - ...

最新文章

  1. api可以主动采集用户数据吗_数据埋点采集的那些事儿
  2. python3 正则 验证邮箱手机
  3. linux ubuntu16.04 编译opencv教程(没编过,有时间再弄,推流不用opencv也行的)
  4. PHP编程最快明白 by www.kuphp.com 案例实战zencart1.38a支付模块简化Fast and Easy Checkout配置...
  5. Managed keyedState中的ValueStateDescriptor与MapStateDescriptor
  6. 一起玩转SQL Server 2012 下的分析服务
  7. Socket 简易静态服务器 WPF MVVM模式(一)
  8. 一文了解下对小微风控策略的优雅调整
  9. commons-fileupload文件上传
  10. Improving Opencv 8: The Core Functionality :File Input and Output using XML and YAML files
  11. 书信用语“商祺”是的意思
  12. 功能对等四个原则_功能对等四原则
  13. 程序员必备开发神器【MAC篇】
  14. 重要不紧急紧急不重要
  15. 大数据在推荐系统中的作用
  16. Roundpic:超简单的在线图片圆角处理~
  17. Linux的隐匿技巧【渗透测试】
  18. python讲得比较好的老师_Python学习讲师哪个好?
  19. 高配云计算机平台,云电脑真的来了!小破本也能秒变高配
  20. Java服务端集成环信im即时通讯

热门文章

  1. [转载]matlab产生方波脉冲和周期性方波信号
  2. Android开发蓝牙与ble设备的通讯
  3. Android水波效果进度条
  4. 有种朋友,很喜欢,却不忍动情
  5. python编写一个将十进制转换为二进制的函数
  6. 基于springboot的商品物品产品众筹平台(mysql)-JAVA.VUE【数据库设计、论文、源码、开题报告】
  7. 【产品经理】百炼成钢,万锻成神。最快乐的事,兴趣和工作相结合
  8. 电脑android模拟器下载地址,它运行了电脑版怎么下载 安卓模拟器电脑版下载地址...
  9. 计算机网络诈骗犯罪的发案规律,当前网络诈骗犯罪侦查工作中存在的问题和对策演示教学(6页)-原创力文档...
  10. 佛教哲学 学习笔记-002-法体有恒-有部哲学