sed -n 关闭默认打印
-r 扩展正则表达式
-e 多点编辑
-i 修改文件
-f 后面跟文件,文件内容是地址定结和命令
d: 删除模式空间匹配的行,并立即启用下一轮循环
p:打印当前模式空间内容,追加到默认输出之后
a [\]text:在指定行后面追加文本
支持使用\n实现多行追加
i [\]text:在行前面插入文本
c [\]text:替换行为单行或多行文本
w /path/somefile: 保存模式匹配的行至指定文件
r /path/somefile:读取指定文件的文本至模式空间中
匹配到的行后
=: 为模式空间中的行打印行号
!:模式空间(pattern space)中匹配行取反处理
P:打印模式空间开端至\n内容,并追加到默认输出之前
h: 把模式空间中的内容覆盖至保持空间中
H:把模式空间中的内容追加至保持空间中
g: 从保持空间取出数据覆盖至模式空间
G:从保持空间取出内容追加至模式空间
x: 把模式空间中的内容与保持空间中的内容进行互换
n: 读取匹配到的行的下一行覆盖至模式空间
N:读取匹配到的行的下一行追加至模式空间
d: 删除模式空间中的行
D:如果模式空间包含换行符,则删除直到第一个换行符的模式空间中的文本,
并不会读取新的输入行,而使用合成的模式空间重新启动循环。如果模式空间
不包含换行符,则会像发出d命令那样启动正常的新循环
sed -n ‘n;p’ FILE 保留偶数行
[root@CENTOS7 ~]#sed -n ‘n;p’ fff
2
4
6
8
10
sed ‘1!G;h;$!d’ FILE 倒序排列
[root@CENTOS7 ~]#sed ‘1!G;h;$!d’ fff
10
9
8
7
6
5
4
3
2
1
sed ‘N;D‘ FILE 只保留最后一行
[root@CENTOS7 ~]#sed ‘N;D’ fff
10
sed ‘$!N;$!D’ FILE
[root@CENTOS7 ~]#sed ‘$!N;$!D’ fff
9
10
sed ‘$!d’ FILE
[root@CENTOS7 ~]#sed ‘$!d’ fff
10
sed ‘G’ FILE 将空白行追加
[root@CENTOS7 ~]#sed ‘G’ fff
1
2
3
4
5
6
7
8
9
10
sed ‘g’ FILE 覆盖变成10个空白行
[root@CENTOS7 ~]#sed ‘g’ fff
sed ‘/^$/d;G’ FILE
[root@CENTOS7 ~]#sed ‘/^$/d;G’ fff
1
2
3
4
5
6
7
8
9
10
sed ‘n;d’ FILE
[root@CENTOS7 ~]#sed ‘n;d’ fff
1
3
5
7
9
sed -n ‘1!G;h;$p’ FILE
[root@CENTOS7 ~]#sed -n ‘1!G;h;$p’ fff
10
9
8
7
6
5
4
3
2
1
[root@CENTOS7 ~]#sed ‘n;g’ fff 从文本中覆盖能打印,从保持空间覆盖不能打印。
1
3
5
7
9
7、统计centos安装光盘中Package目录下的所有rpm文件的以.分隔倒数第二个
字段的重复次数
第一种做法
[root@CENTOS7 ~]#ls /run/media/root/CentOS\ 7\ x86_64/Packages/ | sed -r ‘s/.*\.([^.]+)\.rpm$/\1/’ | sort |uniq -c
2141 i686
3076 noarch
1 TRANS.TBL
4374 x86_64
第二种做法
[root@CENTOS7 Packages]#ls *.rpm | rev | cut -d “.” -f2 | sort | uniq -c
4374 46_68x
2141 686i
3076 hcraon
第三种做法
[root@CENTOS7 Packages]#ls *.rpm | egrep -o “[^.]+\.rpm$” | cut -d “.” -f1 |sort | uniq -c
2141 i686
3076 noarch
4374 x86_64
将文本文件的n和n+1行合并为一行,n为奇数行
第一种
[root@CENTOS7 ~]#sed ‘N;s/\n/ /’ fff
1 2
3 4
5 6
7 8
9 10
第二种
[root@CENTOS7 ~]#cat fff | xargs -n2
1 2
3 4
5 6
7 8
9 10
ldd /bin/ls ldd 查看ls调用的数据库
linux-vdso.so.1 => (0x00007ffcd42c8000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f8c1bd84000)
libcap.so.2 => /lib64/libcap.so.2 (0x00007f8c1bb7f000)
libacl.so.1 => /lib64/libacl.so.1 (0x00007f8c1b975000)
libc.so.6 => /lib64/libc.so.6 (0x00007f8c1b5b2000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f8c1b350000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f8c1b14b000)
/lib64/ld-linux-x86-64.so.2 (0x000055598db21000)
libattr.so.1 => /lib64/libattr.so.1 (0x00007f8c1af46000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f8c1ad2a000)
如果删除了/lib64/libc.so.6 如何救援
1.重启按EXC
2.CD-ROM Drive
3.Troubleshooting
4.Rescue a CentOS system
5.1continue
6.回车
7.cd /mnt/sysimage/lib64 文件夹
8.ln -s libc-2.17.so lib.so.6 用相对路径,不能用绝对路径
源代码命名方式 名字-版本号(主,次,补丁).压缩方式
rpm包命名方式:
name-VERSION-release.arch.rpm
例:bash-4.(主)2.(次)46-19(打包了多少次).el7(rhel7).x86_64.rpm
VERSION: major.minor.release
release:release.OS
常见的arch:
x86: i386, i486, i586, i686
x86_64: x64, x86_64, amd64
powerpc: ppc
跟平台无关:noarch
包:分类和拆包
Application-VERSION-ARCH.rpm: 主包
Application-devel-VERSION-ARCH.rpm 开发子包
Application-utils-VERSION-ARHC.rpm 其它子包
Application-libs-VERSION-ARHC.rpm 其它子包
包之间:可能存在依赖关系,甚至循环依赖
解决依赖包管理工具:
yum:rpm包管理器的前端工具
[root@CENTOS7 Packages]#ldconfig -p ldconfig查看所有系统调用的库
904 libs found in cache `/etc/ld.so.cache’
p11-kit-trust.so (libc6,x86-64) => /lib64/p11-kit-trust.so
libz.so.1 (libc6,x86-64) => /lib64/libz.so.1
libyelp.so.0 (libc6,x86-64) => /lib64/libyelp.so.0
libyajl.so.2 (libc6,x86-64) => /lib64/libyajl.so.2
[root@CENTOS7 Packages]#ldd /bin/cp ldd只能查看一个程序调用的库
linux-vdso.so.1 => (0x00007fff5cfab000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f2f83183000)
libacl.so.1 => /lib64/libacl.so.1 (0x00007f2f82f7a000)
libattr.so.1 => /lib64/libattr.so.1 (0x00007f2f82d74000)
libc.so.6 => /lib64/libc.so.6 (0x00007f2f829b1000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f2f8274f000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f2f8254a000)
/lib64/ld-linux-x86-64.so.2 (0x00005617a7e40000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f2f8232e000)
查看二进制程序所依赖的库文件
ldd /PATH/TO/BINARY_FILE 列如 ldd /bin/ls
管理及查看本机装载的库文件
ldconfig 加载库文件
/sbin/ldconfig -p: 显示本机已经缓存的所有可用库文件名及文件路径
映射关系
配置文件:/etc/ld.so.conf(主配置文件), /etc/ld.so.conf.d/*.conf
缓存文件:/etc/ld.so.cache
包文件组成 (每个包独有)
RPM包内的文件
RPM的元数据,如名称,版本,依赖性,描述等
安装或卸载时运行的脚本
数据库(公共):/var/lib/rpm
程序包名称及版本
依赖关系
功能说明
包安装后生成的各文件路径及校验码信息
[root@CENTOS7 Packages]#rpm -qp –scripts httpd-2.4.6-67.el7.centos.x86_64.rpm rpm -qp(-p是看文本) –script httpd
warning: httpd-2.4.6-67.el7.centos.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
preinstall scriptlet (using /bin/sh):
# Add the “apache” group and user
/usr/sbin/groupadd -g 48 -r apache 2> /dev/null || :
/usr/sbin/useradd -c “Apache” -u 48 -g apache \
-s /sbin/nologin -r -d /usr/share/httpd apache 2> /dev/null || :
postinstall scriptlet (using /bin/sh):
if [ $1 -eq 1 ] ; then
# Initial installation
systemctl preset httpd.service htcacheclean.service >/dev/null 2>&1 || :
fi
preuninstall scriptlet (using /bin/sh):
if [ $1 -eq 0 ] ; then
# Package removal, not upgrade
systemctl –no-reload disable httpd.service htcacheclean.service > /dev/null 2>&1 || :
systemctl stop httpd.service htcacheclean.service > /dev/null 2>&1 || :
fi
postuninstall scriptlet (using /bin/sh):
systemctl daemon-reload >/dev/null 2>&1 || :
# Trigger for conversion from SysV, per guidelines at:
# https://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Systemd
posttrans scriptlet (using /bin/sh):
test -f /etc/sysconfig/httpd-disable-posttrans || \
/bin/systemctl try-restart httpd.service htcacheclean.service >/dev/null 2>&1 || :
[root@CENTOS7 Packages]#file /var/lib/rpm/* 数据库文件,大多数是2进制文件。不可删除,否则无法安装或者卸载软件
/var/lib/rpm/Basenames: Berkeley DB (Btree, version 9, native byte-order)
/var/lib/rpm/Conflictname: Berkeley DB (Btree, version 9, native byte-order)
/var/lib/rpm/__db.001: Applesoft BASIC program data
/var/lib/rpm/__db.002: 386 pure executable
/var/lib/rpm/__db.003: 386 pure executable not stripped
/var/lib/rpm/Dirnames: Berkeley DB (Btree, version 9, native byte-order)
/var/lib/rpm/Group: Berkeley DB (Btree, version 9, native byte-order)
/var/lib/rpm/Installtid: Berkeley DB (Btree, version 9, native byte-order)
/var/lib/rpm/Name: Berkeley DB (Btree, version 9, native byte-order)
/var/lib/rpm/Obsoletename: Berkeley DB (Btree, version 9, native byte-order)
/var/lib/rpm/Packages: Berkeley DB (Hash, version 9, native byte-order)
/var/lib/rpm/Providename: Berkeley DB (Btree, version 9, native byte-order)
/var/lib/rpm/Requirename: Berkeley DB (Btree, version 9, native byte-order)
/var/lib/rpm/Sha1header: Berkeley DB (Btree, version 9, native byte-order)
/var/lib/rpm/Sigmd5: Berkeley DB (Btree, version 9, native byte-order)
/var/lib/rpm/Triggername: Berkeley DB (Btree, version 9, native byte-order)
获取程序包的途径:
(1) 系统发版的光盘或官方的服务器;
CentOS镜像:
https://www.centos.org/download/
http://mirrors.aliyun.com
http://mirrors.sohu.com
http://mirrors.163.com
第三方组织:
Fedora-EPEL:
Extra Packages for Enterprise Linux
Rpmforge:RHEL推荐,包很全
搜索引擎:
http://pkgs.org
http://rpmfind.net
http://rpm.pbone.net
https://sourceforge.net/
rpm包管理
rpm {-i|–install} [install-options] PACKAGE_FILE…
-v: verbose
-vv:
-h: 以#显示程序包管理执行进度
rpm -ivh PACKAGE_FILE …
[install-options]
–test: 测试安装,但不真正执行安装,即dry run模式
–nodeps:忽略依赖关系
–replacepkgs | replacefiles
–nosignature: 不检查来源合法性
–nodigest:不检查包完整性
–noscripts:不执行程序包脚本
%pre: 安装前脚本; –nopre
%post: 安装后脚本; –nopost
%preun: 卸载前脚本; –nopreun
%postun: 卸载后脚本; –nopostun
[root@centos Packages]#rpm -ivh httpd-2.2.15-59.el6.centos.x86_64.rpm 安装需要跟文件名
[root@centos Packages]#rpm -e vsftpd 卸载跟包名,就是软件的名字
[root@CENTOS7 Packages]#rpm -ql tree 查看tree包内的所有文件
/usr/bin/tree
/usr/share/doc/tree-1.6.0
/usr/share/doc/tree-1.6.0/LICENSE
/usr/share/doc/tree-1.6.0/README
/usr/share/man/man1/tree.1.gz
rm /usr/bin/tree 删除后tree命令不能使用
rpm -ivh tree-1.6.0-10.el7.x86_64.rpm 显示已经安装,因为/var/lib/rpm数据库中存放了tree的数据
rpm -ivh –replacepkgs tree-1.6.0-10.el7.x86_64.rpm 用–replacepkgs或者–force
[root@CENTOS7 Packages]#ll /var/lib/rpm 从新安装后数据库时间更新
total 81016
-rw-r–r–. 1 root root 3616768 Apr 20 10:02 Basenames
-rw-r–r–. 1 root root 16384 Mar 27 18:02 Conflictname
-rw-r–r–. 1 root root 286720 Apr 20 10:02 __db.001
-rw-r–r–. 1 root root 90112 Apr 20 10:02 __db.002
-rw-r–r–. 1 root root 1318912 Apr 20 10:02 __db.003
-rw-r–r–. 1 root root 1064960 Apr 20 10:02 Dirnames
-rw-r–r–. 1 root root 32768 Apr 20 10:02 Group
-rw-r–r–. 1 root root 20480 Apr 20 10:02 Installtid
-rw-r–r–. 1 root root 69632 Apr 20 10:02 Name
-rw-r–r–. 1 root root 32768 Mar 27 18:02 Obsoletename
-rw-r–r–. 1 root root 73494528 Apr 20 10:02 Packages
-rw-r–r–. 1 root root 2355200 Apr 20 10:02 Providename
-rw-r–r–. 1 root root 483328 Apr 20 10:02 Requirename
-rw-r–r–. 1 root root 126976 Apr 20 10:02 Sha1header
-rw-r–r–. 1 root root 73728 Apr 20 10:02 Sigmd5
-rw-r–r–. 1 root root 8192 Mar 27 18:00 Triggername
replacefiles A包中有file1,B包中也有file1,想安装B包时使用
列如
rpm –import RPM-GPG-KEY-CentOS-6 导入公钥安装rpm包时就不会有NOKEY的报错
[root@centos CentOS_6.9_Final]#rpm -ivh Packages/samba-3.6.23-41.el6.x86_64.rpm
Preparing… ########################################### [100%]
1:samba ########################################### [100%]
公钥只检查签名,不检查文件内容的完整性
rpm包升级 新版本会覆盖旧版本
rpm {-U|–upgrade} [install-options] PACKAGE_FILE …
rpm {-F|–freshen} [install-options] PACKAGE_FILE …
upgrade:安装有旧版程序包,则“升级”
如果不存在旧版程序包,则“安装”
freshen:安装有旧版程序包,则“升级”
如果不存在旧版程序包,则不执行升级操作
rpm -Uvh PACKAGE_FILE …
rpm -Fvh PACKAGE_FILE …
–oldpackage:降级
–force: 强制安装
注意:
(1) 不要对内核做升级操作;Linux支持多内核版本并存,因此,对直接安装新版
本内核
(2) 如果原程序包的配置文件安装后曾被修改,升级时,新版本的提供的同一个配
置文件并不会直接覆盖老版本的配置文件,而把新版本的文件重命名
(FILENAME.rpmnew)后保留,一般情况下2进制文件都会被覆盖
[root@centos CentOS_6.9_Final]#uname -r 查看内核版本
2.6.32-696.el6.x86_64
[root@centos CentOS_6.9_Final]#rpm -q kernel 查看内核版本
kernel-2.6.32-696.el6.x86_64
scp vsftpd-3.0.2-22.el7.x86_64.rpm 172.20.102.175:/root
[root@centos Packages]#rpm -ivh vsftpd-2.2.2-24.el6.x86_64.rpm
Preparing… ########################################### [100%]
1:vsftpd ########################################### [100%]
[root@centos Packages]#rpm -Fvh /root/vsftpd-3.0.2-22.el7.x86_64.rpm
warning: /root/vsftpd-3.0.2-22.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
libc.so.6(GLIBC_2.14)(64bit) is needed by vsftpd-3.0.2-22.el7.x86_64
libc.so.6(GLIBC_2.15)(64bit) is needed by vsftpd-3.0.2-22.el7.x86_64
无法升级因为依赖的文件版本不同,可以下载2.7-2.9升级
包查询
rpm {-q|–query} [select-options] [query-options]
[select-options]
-a: 所有包
-f: 查看指定的文件由哪个程序包安装生成
-p rpmfile:针对尚未安装的程序包文件做查询操作
–whatprovides CAPABILITY :查询指定的 CAPABILITY 由哪个包所提供
–whatrequires CAPABILITY :查询指定的 CAPABILITY 被哪个包所依赖
rpm2cpio 包文件|cpio –itv 预览包内文件
rpm2cpio 包文件|cpio –id “*.conf” 释放包内文件
[root@centos ~]#rpm -q vsftpd 查询包是否安装,后面直接跟包名,包名必须准确,不然无法查询
vsftpd-2.2.2-24.el6.x86_64
[root@centos ~]#rpm -e vsftpd
[root@centos ~]#rpm -q vsftpd || rpm -i /misc/cd/Packages/
Display all 3241 possibilities? (y or n)
[root@centos ~]#rpm -q vsftpd &> /dev/null || rpm -i /misc/cd/Packages/vsftpd-2.2.2-24.el6.x86_64.rpm
[root@centos ~]#rpm -q vsftpd
vsftpd-2.2.2-24.el6.x86_64
[root@centos ~]#rpm -qa | grep “vsf” -qa列出所有安装过的包
vsftpd-2.2.2-24.el6.x86_64
[root@centos ~]#rpm -qf /bin/ls
coreutils-8.4-46.el6.x86_64
[root@centos ~]#rpm -ql tree
/usr/bin/tree
/usr/share/doc/tree-1.5.3
/usr/share/doc/tree-1.5.3/LICENSE
/usr/share/doc/tree-1.5.3/README
/usr/share/man/man1/tree.1.gz
[root@centos ~]#rm -f /usr/bin/tree
[root@centos ~]#rpm -qf /usr/bin/tree
tree-1.5.3-3.el6.x86_64
[root@centos ~]#rpm -ivh /misc/cd/Packages/tree-1.5.3-3.el6.x86_64.rpm –force
Preparing… ########################################### [100%]
1:tree ########################################### [100%]
删除/usr/bin/tree 依然可以查询因为/var/lib/rpm数据库中可以查到
mv /var/lib/rpm/* /data
数据库被移走 导致rpm命令失效,无法查询,安装,卸载。
虽然/var/bin/rpm被移走后生成了新的文件,但是文件内容是空的。
rpm -ql 无法查询没有安装的包内的文件,如果想要查询则需要rpm -qpl 可以查询
[root@centos Packages]#rpm -ql zsh
package zsh is not installed
[root@centos Packages]#rpm -qlp zsh-4.3.11-4.el6.centos.2.x86_64.rpm
/bin/zsh
/etc/skel/.zshrc
/etc/zlogin
注意: -p 后面需要跟文件名
[root@centos Packages]#rpm -q –whatprovides bash 谁提供了bash功能
bash-4.1.2-48.el6.x86_64
root@centos Packages]#rpm -q –requires bash 依赖bash功能的库有哪些
mysql-5.1.73-8.el6_8.x86_64
initscripts-9.03.58-1.el6.centos.x86_64
dracut-004-409.el6_8.2.noarch
rsyslog-5.8.10-10.el6_6.x86_64
cronie-1.4.4-16.el6_8.2.x86_64
autofs-5.0.5-132.el6.x86_64
lvm2-2.02.143-12.el6.x86_64
rpm2cpio命令用法
[root@centos Packages]#rpm -ql tree
/usr/bin/tree
/usr/share/doc/tree-1.5.3
/usr/share/doc/tree-1.5.3/LICENSE
/usr/share/doc/tree-1.5.3/README
/usr/share/man/man1/tree.1.gz
[root@centos Packages]#rm -f /usr/bin/tree
[root@centos Packages]#tree
-bash: /usr/bin/tree: No such file or directory
[root@centos Packages]#rpm2cpio /media/CentOS_6.9_Final/Packages/tree-1.5.3-3.el6.x86_64.rpm | cpio -tv
-rwxr-xr-x 1 root root 41136 Jan 14 2015 ./usr/bin/tree
drwxr-xr-x 2 root root 0 Jan 14 2015 ./usr/share/doc/tree-1.5.3
-rw-r–r– 1 root root 18009 Aug 13 2004 ./usr/share/doc/tree-1.5.3/LICENSE
-rw-r–r– 1 root root 4167 Oct 20 2009 ./usr/share/doc/tree-1.5.3/README
-rw-r–r– 1 root root 3375 Jan 14 2015 ./usr/share/man/man1/tree.1.gz
132 blocks
[root@centos ~]#rpm2cpio /media/CentOS_6.9_Final/Packages/tree-1.5.3-3.el6.x86_64.rpm | cpio -idv ./usr/bin/tree
./usr/bin/tree
132 blocks
[root@centos ~]#mv usr/bin/tree /usr/bin/
缺点 可能导致文件所有者所属组权限发生改变
[query-options]
–changelog:查询rpm包的changelog
-c: 查询程序的配置文件
-d: 查询程序的文档
-i: information
-l: 查看指定的程序包安装后生成的所有文件
–scripts:程序包自带的脚本
–provides: 列出指定程序包所提供的CAPABILITY
-R: 查询指定的程序包所依赖的CAPABILITY
[root@centos ~]#rpm -qi bash 查询bash的信息
Name : bash Relocations: (not relocatable)
Version : 4.1.2 Vendor: CentOS
Release : 48.el6 Build Date: Thu 23 Mar 2017 08:17:20 AM CST
Install Date: Tue 27 Mar 2018 05:00:33 PM CST Build Host: c1bm.rdu2.centos.org
Group : System Environment/Shells Source RPM: bash-4.1.2-48.el6.src.rpm
Size : 3142529 License: GPLv3+
Signature : RSA/SHA1, Thu 23 Mar 2017 10:59:39 PM CST, Key ID 0946fca2c105b9de
Packager : CentOS BuildSystem <http://bugs.centos.org>
URL : http://www.gnu.org/software/bash
Summary : The GNU Bourne Again shell
Description :
The GNU Bourne Again shell (Bash) is a shell or command language
interpreter that is compatible with the Bourne shell (sh). Bash
incorporates useful features from the Korn shell (ksh) and the C shell
(csh). Most sh scripts can be run by bash without modification.
常用查询用法:
-qi PACKAGE, -qf FILE, -qc PACKAGE, -ql PACKAGE, -qd PACKAGE
-qpi PACKAGE_FILE, -qpl PACKAGE_FILE, …
-qa
包卸载:
rpm {-e|–erase} [–allmatches] [–nodeps] [–noscripts] [–notriggers]
[–test] PACKAGE_NAME …
rpm {-V|–verify} [select-options] [verify-options]
S file Size differs
M Mode differs (includes permissions and file type)
5 digest (formerly MD5 sum) differs
D Device major/minor number mismatch
L readLink(2) path mismatch
U User ownership differs
G Group ownership differs
T mTime differs
P capabilities differ
[root@centos ~]#rpm -V tree
…….T. /usr/bin/tree
[root@centos ~]#echo >> /usr/bin/tree
[root@centos ~]#rpm -V tree
S.5….T. /usr/bin/tree
[root@centos ~]#rpm -Va 检查所有
rpm -k 文件名 检查文件完整性
[root@centos Packages]#rpm -K samba-3.6.23-41.el6.x86_64.rpm
samba-3.6.23-41.el6.x86_64.rpm: rsa sha1 (md5) pgp md5 OK
[root@centos ~]#echo >> samba-3.6.23-41.el6.x86_64.rpm
[root@centos ~]#rpm -K samba-3.6.23-41.el6.x86_64.rpm
samba-3.6.23-41.el6.x86_64.rpm: rsa sha1 (MD5) PGP MD5 NOT OK
如果没有导入公钥则文件都不OK
公钥的导入地点
[root@CENTOS7 ~]#ll /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
-rw-r–r–. 1 root root 1690 Aug 30 2017 /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@CENTOS7 ~]#ll /run/media/root/CentOS\ 7\ x86_64/RPM-GPG-KEY-CentOS-7
-rw-rw-r–. 3 root root 1690 Dec 10 2015 /run/media/root/CentOS 7 x86_64/RPM-GPG-KEY-CentOS-7
导入公钥
[root@CENTOS7 ~]#rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@CENTOS7 ~]#rpm -K /run/media/root/CentOS\ 7\ x86_64/Packages/tree-1.6.0-10.el7.x86_64.rpm
/run/media/root/CentOS 7 x86_64/Packages/tree-1.6.0-10.el7.x86_64.rpm: rsa sha1 (md5) pgp md5 OK
[root@CENTOS7 ~]#rpm -qa “gpg*”
gpg-pubkey-f4a80eb5-53a7ff4b
rpm -e gpg-pubkey-f4a80eb5-53a7ff4b 删除公钥后
rpm -K /run/media/root/CentOS\ 7\ x86_64/Packages/tree-1.6.0-10.el7.x86_64.rpm
/run/media/root/CentOS 7 x86_64/Packages/tree-1.6.0-10.el7.x86_64.rpm: RSA sha1 ((MD5) PGP) md5 NOT OK (MISSING KEYS: (MD5) PGP#f4a80eb5)
rpm -e rpm –nodeps 将rpm卸载
恢复
1.reboot
2.exc
3.进入CD-ROM Drive
4.rescue installed system
5.english
6.us
7.错误是否需要联网
8.comtinue
9.mkdir /mnt/cdroom
10.mount /dev/sr0 /mnt/cdroom
11.rpm -ivh /mnt/cdroom/Packages/rpm-4.8.055.e16.x86_64.rpm –root=/mnt/sysimage
12.chroot /mnt/sysimage 切回真正的/
yum
工作原理
需要使用yum首先要有c/s结构即client/server
server中存放rpm包,meta data。megadata中存放rpm的元数据
当client需要安装rpm包时,首先要配置文件,文件内容是要访问的server路径。yum install tree 这时访问server 从metadata中查找是否有tree包,如果有这将metadata缓存到client中。然后在到server的rpm中找到tree以及tree依赖的包下载到client中安装,安装完成后默认删除下载的tree以及tree依赖的包
server 中可以有多个厂库比如cdroom,epel源。当有多个厂库时,下载时在多个厂库中查找,找到则安装,如果多个厂库都有要安装的rpm包则安装版本高的。
如果已经缓存server中的metadata。改变配置文件中的地址但是缓存的地址没有改变会导致出错
yum使用是有错误一般2种情况
1.配置文件格式写错
2.缓存出问题.可以清除缓存
yum的配置文件
vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch(x86_64)/$releasever(7) 缓存文件
keepcache=0 meta data会缓存 rpm安装完成后会删除。将keepcache该成1则不会删除rpm包
debuglevel=2 调试
logfile=/var/log/yum.log 用yum安装的日志
exactarch=1 架构
obsoletes=1 过时的
gpgcheck=1 检查rpm包完整性及签名
plugins=1 插件启用
installonly_limit=5 并行安装同时安装5个包,但是在一个机器上不可运行多个yum。
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page
.php?category=yum
distroverpkg=centos-release
interupting your command line usage, it’s much better to have something
“/etc/yum.conf” 26L, 970C written
[root@CENTOS7 ~]#cd /etc/yum.repos.d/
[root@CENTOS7 yum.repos.d]#ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@CENTOS7 yum.repos.d]#mkdir bak
[root@CENTOS7 yum.repos.d]#mv *.repo bak/
[root@CENTOS7 yum.repos.d]#ls
bak
配置yum的配置文件
[root@CENTOS7 yum.repos.d]#vim cdrom.repo
[base] 不要加空格
baseurl=file:///mnt/cdrom
gpgcheck=0
元数据存放在repodata中当配置baseurl时路径就是repodata的父路径.
配置baseurl时路径最好不要有空格,所以mkdir /mnt/cdrom,将光盘挂在到建立的文件夹上 mount /dev/sr0 /mnt/cdrom
yum install httpd 就可以解决依赖性问题
[root@CENTOS7 ~]#yum repolist 查看有几个厂库
Loaded plugins: fastestmirror, langpacks
Repository ‘base’ is missing name in configuration, using id
Loading mirror speeds from cached hostfile
repo id repo name status
base base 9,591
repolist: 9,591
[root@CENTOS7 ~]#vim /etc/yum.repos.d/cdrom.repo
[base]
name=cdrom
baseurl=file:///mnt/cdrom
gpgcheck=0
[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
gpgcheck=0
[root@CENTOS7 ~]#cd /var/cache/yum/x86_64/7
[root@CENTOS7 7]#ll
total 16
drwxr-xr-x. 4 root root 278 Apr 20 15:16 base
drwxr-xr-x. 4 root root 4096 Apr 20 15:16 epel
drwxr-xr-x. 4 root root 183 Apr 19 13:56 extras
-rw-r–r–. 1 root root 70 Apr 20 15:16 timedhosts
-rw-r–r–. 1 root root 440 Apr 19 13:57 timedhosts.txt
drwxr-xr-x. 4 root root 4096 Apr 19 13:57 updates
[root@CENTOS7 7]#du -sh /var/cache/yum/x86_64/7
482M /var/cache/yum/x86_64/7
[root@CENTOS7 7]#yum clean all 清除缓存
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base epel
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@CENTOS7 7]#du -sh . 是原来配置的文件元数据的缓存
426M .
yum list 列出厂库中的所有包带@是已经装过的包
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-CentOS-7 在配置文件中自动导入公钥
enabled=0 在配置文件中禁用厂库
[root@CENTOS7 7]#yum repolist all 显示所有仓库
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id repo name status
base cdrom enabled: 9,591
epel epel disabled 被禁用
repolist: 9,591
[root@CENTOS7 7]#yum repolist disabled 查看被禁用的仓库
Loaded plugins: fastestmirror, langpacks
repo id repo name
epel epel
repolist: 0
[root@CENTOS7 7]#ll /var/log/yum.log 用yum安装后log中已经有内容了
-rw——-. 1 root root 725 Apr 20 15:59 /var/log/yum.log
[root@CENTOS7 7]#yum remove sl 卸载sl
[root@CENTOS7 7]#cat /var/log/yum.log
Apr 20 15:02:00 Installed: apr-1.4.8-3.el7.x86_64
Apr 20 15:02:00 Installed: apr-util-1.5.2-6.el7.x86_64
Apr 20 15:02:00 Installed: httpd-tools-2.4.6-67.el7.centos.x86_64
Apr 20 15:02:00 Installed: mailcap-2.1.41-2.el7.noarch
Apr 20 15:02:08 Installed: httpd-2.4.6-67.el7.centos.x86_64
Apr 20 15:44:57 Installed: libmpc-1.0.1-3.el7.x86_64
Apr 20 15:45:01 Installed: cpp-4.8.5-16.el7.x86_64
Apr 20 15:45:03 Installed: kernel-headers-3.10.0-693.el7.x86_64
Apr 20 15:45:04 Installed: glibc-headers-2.17-196.el7.x86_64
Apr 20 15:45:04 Installed: glibc-devel-2.17-196.el7.x86_64
Apr 20 15:45:10 Installed: gcc-4.8.5-16.el7.x86_64
Apr 20 15:50:29 Installed: sl-5.02-1.el7.x86_64
Apr 20 15:59:34 Installed: tree-1.6.0-10.el7.x86_64
Apr 20 16:07:19 Erased: sl-5.02-1.el7.x86_64
yum客户端配置文件:
/etc/yum.conf:为所有仓库提供公共配置
/etc/yum.repos.d/*.repo:为仓库的指向提供配置
仓库指向的定义:
[repositoryID]
name=Some name for this repository
baseurl=url://path/to/repository/
enabled={1|0}
gpgcheck={1|0}
gpgkey=URL
enablegroups={1|0}
failovermethod={roundrobin|priority} 路径优先级。可以将baseurl=file:///mnt/cdrom
https://mirrors.aliyun.com/epel/7/x86_64/ 这两个路径写入/root/file1中。配置文件中写成mirrorlist=file:///root/file1
roundrobin:意为随机挑选,默认值
priority:按顺序访问
cost= 默认为1000 值越小越优先
yum的repo配置文件中可用的变量:
$releasever: 当前OS的发行版的主版本号
$arch: 平台,i386,i486,i586,x86_64等
$basearch:基础平台;i386, x86_64
$YUM0-$YUM9:自定义变量
http://server/centos/$releasever/$basearch/
http://server/centos/7/x86_64
http://server/centos/6/i384
[root@CENTOS7 7]#yum install autofs centos7的神奇目录misc
[root@CENTOS7 7]#rpm -ql autofs
/usr/lib/systemd/system/autofs.service 这是一个service文件需要启动服务
[root@CENTOS7 7]#systemctl start autofs 启动服务
[root@CENTOS7 7]#systemctl enable autofs 开机时自动启动此服务
Created symlink from /etc/systemd/system/multi-user.target.wants/autofs.service to /usr/lib/systemd/system/autofs.service.
[root@CENTOS7 7]#ls /misc
[root@CENTOS7 7]#ls /misc/cd 已经可用
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
修改配置文件vim /etc/yum.repos.d/cdrom.repo 让baseurl=file:///misc/cd
yum clean all 清除缓存 。 yum repolist 后可以正常使用yum
阿里云repo文件:
http://mirrors.aliyun.com/repo/
CentOS系统的yum源
阿里云:https://mirrors.aliyun.com/centos/$releasever/os/x86_64/
EPEL的yum源:
阿里云: https://mirrors.aliyun.com/epel/$releasever/x86_64
如何直接使用阿里云的yum服务
[root@CENTOS7 7]#cd /etc/yum.repos.d/
[root@CENTOS7 yum.repos.d]#wget http://mirrors.aliyun.com/repo/Centos-7.repo 从网上复制的路径
[root@CENTOS7 yum.repos.d]#yum repolist
Loaded plugins: fastestmirror, langpacks
Repository base is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
repo id repo name status
base/7/x86_64 CentOS-7 – Base – mirrors.aliyun.com 9,591
!extras/7/x86_64 CentOS-7 – Extras – mirrors.aliyun.com 448
!updates/7/x86_64 CentOS-7 – Updates – mirrors.aliyun.com 2,416
repolist: 12,455
用命令直接生成配置文件
yum-config-manager –add-repo= http://172.16.0.1/cobbler/ks_mirror/7/
yum-config-manager –disable “仓库名” 禁用仓库
yum-config-manager –enable “仓库名” 启用仓库
yum命令
显示仓库列表:
yum repolist [all|enabled|disabled]
显示程序包:
yum list
yum list [all | glob_exp1] [glob_exp2] […]
yum list {available|installed|updates} [glob_exp1] […]
[root@CENTOS7 yum.repos.d]#yum list *ftp
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Available Packages
ftp.x86_64 0.17-67.el7 base
lftp.i686 4.4.8-8.el7_3.2 base
lftp.x86_64 4.4.8-8.el7_3.2 base
tftp.x86_64 5.2-13.el7 base
升级程序包:
yum update [package1] [package2] […] 一般不建议使用
yum downgrade package1 [package2] […] (降级)
检查可用升级:
yum check-update
卸载程序包:
yum remove | erase package1 [package2] […]
查看程序包information: 类似于 rpm -qi 但是没有rpm -qi详细
yum info […]
查看指定的特性(可以是某文件)是由哪个程序包所提供: 类似于rpm -qf
yum provides | whatprovides feature1 [feature2] […]
[root@CENTOS7 yum.repos.d]#yum provides tree
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
tree-1.6.0-10.el7.x86_64 : File system tree viewer
Repo : base
tree-1.6.0-10.el7.x86_64 : File system tree viewer
Repo : @base
[root@CENTOS7 yum]#yum install mariadb-server 安装时有依赖所以同时安装了下面两个包
mariadb x86_64 1:5.5.56-2.el7 base 8.7 M
perl-DBD-MySQL x86_64 4.023-5.el7 base 140 k
[root@CENTOS7 yum]#yum remove mariadb-server 卸载的时候不会卸载这两个包。
清理本地缓存:
清除/var/cache/yum/$basearch/$releasever缓存
yum clean [ packages | metadata | expire-cache | rpmdb | plugins |
all ]
构建缓存: 一帮情况下不需要因为安装的时候会自动缓存
yum makecache
搜索:yum search string1 [string2] […]
以指定的关键字搜索程序包名及summary信息
[root@CENTOS7 yum]#yum search “ftp” 搜索关键字忽略大小写
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
============================================== N/S matched: ftp ==============================================
ftp.x86_64 : The standard UNIX FTP (File Transfer Protocol) client
lftp-scripts.noarch : Scripts for lftp
syslinux-tftpboot.x86_64 : SYSLINUX modules in /var/lib/tftpboot, available for network booting
tftp.x86_64 : The client for the Trivial File Transfer Protocol (TFTP)
tftp-server.x86_64 : The server for the Trivial File Transfer Protocol (TFTP)
vsftpd.x86_64 : Very Secure Ftp Daemon
vsftpd-sysvinit.x86_64 : SysV initscript for vsftpd daemon
curl.x86_64 : A utility for getting files from remote servers (FTP, HTTP, and others)
lftp.i686 : A sophisticated file transfer program
lftp.x86_64 : A sophisticated file transfer program
wget.x86_64 : A utility for retrieving files using the HTTP or FTP protocols
Name and summary matches only, use “search all” for everything.
查看指定包所依赖的capabilities:
yum deplist package1 [package2] […]
[root@CENTOS7 yum]#yum deplist httpd.x86_64
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
package: httpd.x86_64 2.4.6-67.el7.centos
dependency: /bin/sh
查看yum事务历史:
yum history [info|list|packages-list|packages-info|
summary|addon-info|redo|undo|
rollback|new|sync|stats]
yum history
yum history info 6
yum history undo 6
[root@CENTOS7 yum]#yum history
Loaded plugins: fastestmirror, langpacks
ID | Login user | Date and time | Action(s) | Altered
——————————————————————————-
12 | wang <wang> | 2018-04-20 17:22 | Install | 1
11 | wang <wang> | 2018-04-20 17:15 | Erase | 1
10 | wang <wang> | 2018-04-20 17:13 | Install | 3
9 | wang <wang> | 2018-04-20 16:59 | Reinstall | 1
8 | wang <wang> | 2018-04-20 16:32 | Install | 1
7 | wang <wang> | 2018-04-20 16:25 | Install | 2
6 | wang <wang> | 2018-04-20 16:07 | Erase | 1
5 | wang <wang> | 2018-04-20 15:59 | Install | 1 <
4 | wang <wang> | 2018-04-20 15:50 | Install | 1 >
3 | wang <wang> | 2018-04-20 15:44 | Install | 6
2 | wang <wang> | 2018-04-20 15:01 | Install | 5 <
1 | System <unset> | 2018-03-27 17:54 | Install | 1255 >
history list
[root@CENTOS7 yum]#yum history list 12
Loaded plugins: fastestmirror, langpacks
ID | Command line | Date and time | Action(s) | Altered
——————————————————————————-
12 | install mariadb-server | 2018-04-20 17:22 | Install | 1
history list
[root@CENTOS7 yum]#yum history info 12
Loaded plugins: fastestmirror, langpacks
Transaction ID : 12
Begin time : Fri Apr 20 17:22:48 2018
Begin rpmdb : 1274:20aafd54d5e9eb69d75961878f85f43291214f03
End time : 17:22:51 2018 (3 seconds)
End rpmdb : 1275:3accf9c7969dd14e1a2dd5b33fed02a300d70ef2
User : wang <wang>
Return-Code : Success
Command Line : install mariadb-server
Transaction performed with:
Installed rpm-4.11.3-25.el7.x86_64 @anaconda
Installed yum-3.4.3-154.el7.centos.noarch @anaconda
Installed yum-plugin-fastestmirror-1.1.31-42.el7.noarch @anaconda
Packages Altered:
Install mariadb-server-1:5.5.56-2.el7.x86_64 @base
history info
[root@CENTOS7 yum]#yum history undo 10 解决卸载残留问题
Loaded plugins: fastestmirror, langpacks
Undoing transaction 10, from Fri Apr 20 17:13:27 2018
Dep-Install mariadb-1:5.5.56-2.el7.x86_64 @base
Install mariadb-server-1:5.5.56-2.el7.x86_64 @base
Dep-Install perl-DBD-MySQL-4.023-5.el7.x86_64 @base
Resolving Dependencies
–> Running transaction check
—> Package mariadb.x86_64 1:5.5.56-2.el7 will be erased
—> Package mariadb-server.x86_64 1:5.5.56-2.el7 will be erased
—> Package perl-DBD-MySQL.x86_64 0:4.023-5.el7 will be erased
–> Finished Dependency Resolution
[root@CENTOS7 yum]#yum history redo 10 从新安装
Loaded plugins: fastestmirror, langpacks
Repeating transaction 10, from Fri Apr 20 17:13:27 2018
Dep-Install mariadb-1:5.5.56-2.el7.x86_64 @base
Install mariadb-server-1:5.5.56-2.el7.x86_64 @base
Dep-Install perl-DBD-MySQL-4.023-5.el7.x86_64 @base
[root@CENTOS7 yum]#yum install /misc/cd/Packages/httpd-2.4.6-67.el7.centos.x86_64.rpm 也可以写路径安装同时可以解决依赖性问题
包组管理的相关命令:
yum groupinstall group1 [group2] […]
yum groupupdate group1 [group2] […]
yum grouplist [hidden] [groupwildcard] […]
yum groupremove group1 [group2] […]
yum groupinfo group1 […]
[root@centos yum.repos.d]#cat > base.repo
[base]
name=cdroom
baseurl=file:///misc/cd
gpgcheck=0
[root@centos yum.repos.d]#yum grouplist
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Group Process
Loading mirror speeds from cached hostfile
base | 4.0 kB 00:00 …
base/primary_db | 4.7 MB 00:00 …
Installed Groups:
Additional Development
[root@CENTOS7 yum]#yum groupinfo “Development Tools” 查看包组信息
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Group: Development Tools
Group-Id: development
Description: A basic development environment.
Mandatory Packages:
=autoconf
=automake
binutils
[root@CENTOS7 yum]#yum grouplist 查看能够安装的包组
[root@CENTOS7 yum]#yum groupinstall “Development Tools” 安装包组
Group: Development Tools
Group-Id: development
Description: A basic development environment.
Mandatory Packages:
=autoconf
=automake
binutils
=bison
=flex
gcc
=gcc-c++
gettext
=libtool
前面什么符号都不带的表示包已经装上,而且不是随着包组装好的可能是以前装的或者装系统的时候装的
=表示包时随着包组装上的
+表示随着包组升级的时候会安装
-表示不会随着包组升级而安装
[root@CENTOS7 yum]#yum groupremove “Development Tools” 卸载包组但是没有卸载干净只卸载了26个还有19个没有卸载
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
No environment named Development Tools exists
Resolving Dependencies
[root@CENTOS7 yum]#yum history undo 15 卸载剩下的19个包
Loaded plugins: fastestmirror, langpacks
Undoing transaction 15, from Fri Apr 20 17:53:17 2018
Install autoconf-2.69-11.el7.noarch
yum的命令行选项:
–nogpgcheck:禁止进行gpg check
-y: 自动回答为“yes”
-q:静默模式
–disablerepo=repoidglob:临时禁用此处指定的repo
–enablerepo=repoidglob:临时启用此处指定的repo
–noplugins:禁用所有插件
[root@CENTOS7 yum]#yum -y -q install httpd 自动回答yes并且不显示安装过程,-y 与-q 不能写成-yq
[root@CENTOS7 yum]#rpm -q httpd
httpd-2.4.6-67.el7.centos.x86_64
创建yum仓库:
createrepo [options] <directory>
如果手动编译了一个rpm包创建这个rpm包的repodata
creatrepo后面跟上这个rpm包所在的文件夹即可
搭建yum服务器
[root@CENTOS7 ~]#systemctl start httpd 启动
echo welcome to magedu > index.html 页面显示magedu
添加一个光盘,光盘是6.9everthing
[root@CENTOS7 html]#echo ‘- – -‘ > /sys/class/scsi_host/host2/scan 在不重启的情况下启动添加的硬件设备
mount /dev/sr1 centos/6/os/x86_64
在centos6上修改配置文件vim /etc/yum.repos.d/base.repo
修改baseurl=http://172.18.116.150/centos/6/os/x86_64/
保存退出
yum clean all
即可使用这个server了
程序包编译
程序包编译安装:
Application-VERSION-release.src.rpm –> 安装后,使用rpmbuild命令制作
成二进制格式的rpm包,而后再安装
源代码–>预处理–>编译–>汇编–>链接–>执行
源代码组织格式:
多文件:文件中的代码之间,很可能存在跨文件依赖关系
C、C++:make 项目管理器
configure脚本 –> Makefile.in –> Makefile
java: maven
configure 后面加路径和启用禁用的功能
C语言源代码编译安装三步骤:
1、./configure
(1) 通过选项传递参数,指定启用特性、安装路径等;执行时会参考用户的
指定以及Makefile.in文件生成Makefile
(2) 检查依赖到的外部环境,如依赖的软件包
2、make 根据Makefile文件,构建应用程序
3、make install 复制文件到相应路径
开发工具:
autoconf: 生成configure脚本
automake:生成Makefile.in
注意:安装前查看INSTALL,README
开源程序源代码的获取:
官方自建站点:
apache.org (ASF:Apache Software Foundation)
mariadb.org
…
代码托管:
SourceForge.net
Github.com
code.google.com
c/c++编译器: gcc (GNU C Complier)
准备工作:
1 关闭firwalld
centos6: service iptables stop; chkconfig iptables off
centos7: systemctl stop firewalld; systemctl disable firewalld
2 关闭SElinux
setenforce 0
vim /etc/selinux/config
[root@centos man]#cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing – SELinux security policy is enforced.
# permissive – SELinux prints warnings instead of enforcing.
# disabled – No SELinux policy is loaded.
SELINUX=enforcing 永久关闭将enforcing 换成disabled
# SELINUXTYPE= can take one of these two values:
# targeted – Targeted processes are protected,
# mls – Multi Level Security protection.
SELINUXTYPE=targeted
SELINUX=disabled
先配置好安装需要的工具yum grouplist “development tool”
然后导入需要安装的软件源码,解压缩。在进行./configure之前需要进入解压后的文件夹
cat README 和INSTALL.
[root@centos httpd-2.2.34]#./configure -h
–prefix=PREFIX 指定总文件夹
–sysconfdir=DIR read-only single-machine data [PREFIX/etc] 分离出的文件此条是etc
最好写在文档里不容易出错
./configure \
–prefix=/app \
–sysconfdir=/etc/httpd22 \
–disable-env \
–enable-file-cache
运行./configure 脚本时,有可能缺少相关的包需要安装
no OpenSSL headers found
[root@centos httpd-2.2.34]#yum list openssl* 查询一下
openssl-devel.x86_64 一般都是devel的包
安装完openssl-devel.x86_64
再次执行
[root@centos httpd-2.2.34]#./configure –prefix=/app –sysconfdir=/etc/httpd22 –enable-ssl
如果没有问题echo $? = 0
第一步完成
make 需要时间可能很长所以添加cpu个数
[root@centos httpd-2.2.34]#make -j 4 && echo -e “\a” && sleep 1 && echo -e “\a” && sleep 1 && echo -e “\a” && sleep 1
[root@centos httpd-2.2.34]#ll Makefile 这个文件是运行 ./configure 生成的
-rw-r–r–. 1 root root 8929 Apr 21 20:02 Makefile
第二步完成
[root@centos httpd-2.2.34]#make install
运行程序,直接路径或者添加PATH变量里的路径
[root@centos httpd-2.2.34]#^C
[root@centos httpd-2.2.34]#vim /etc/profile.d/env.sh
[root@centos httpd-2.2.34]#. /etc/profile.d/env.sh
[root@centos httpd-2.2.34]#echo $PATH
/app/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@centos ~]#apachectl start
httpd: apr_sockaddr_info_get() failed for centos.localdomain
httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName
虽然报错了但是服务已经启动。80 服务就是APACHE
[root@centos ~]#ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:53548 *:*
LISTEN 0 128 :::42029 :::*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 *:111 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 100 127.0.0.1:25 *:*
[root@centos ~]#cd /app
[root@centos app]#ls
bin build cgi-bin error htdocs icons include lib logs man manual modules
[root@centos app]#cd htdocs/ 显示页面内容在这里
[root@centos htdocs]#ls
index.html
[root@centos httpd22]#ls 配置文件所在地
extra httpd.conf magic mime.types origina
[root@centos app]#ls man帮助的地方
bin build cgi-bin error htdocs icons include lib logs man manual modules
[root@centos app]#cd man
[root@centos man]#ls
man1 man8
远程使用写好的脚本
yum install httpd
/var/www/html/install.sh
systemctl start httpd
curl http://testsrv/install.sh |bash
系统默认的man帮助都在 /usr/share/man
centos7 添加man帮助文件编辑/etc/man_db.conf文件
centos6 添加man帮助文件编辑/etc/man.config
磁盘存储和文件系统
LVM 逻辑卷
设备类型的文件都在/dev 下放着
设备类型:
块设备:block,存取单位“块”,磁盘
字符设备:char,存取单位“字符”,键盘
典型的字符文件 /dev/zero 和/dev/null 存取单位是一个字符
设备文件:关联至一个设备驱动程序,进而能够跟与之对应硬件设备进行通信
设备号码:
主设备号:major number, 标识设备类型
次设备号:minor number, 标识同一类型下的不同设备
[root@CENTOS7 ~]#ll /dev/zero
crw-rw-rw-. 1 root root 1主设备号, 5次设备号 Apr 22 08:47 /dev/zero
主号就是这个文件属于的类别编号,次号这个类别里面有几个不同的设备
复制设备文件时不可以 cp /dev/sda 而是 cp -a /dev/sda
创建设备文件 mknod /data/zerofile c 1 5,这个文件和/dev/zero一样
硬盘接口类型
并行:
IDE:133MB/s
SCSI:640MB/s
串口:
SATA:6Gbps B是字节的意思b是位,一个B=8b
SAS:6Gbps
USB:480MB/s
rpm: rotations
per minute
在centos5版本中将IDE接口的硬盘叫做hd
在centos6以上的版本中所有接口的硬盘都叫sd
在centos6中添加一块IDE接口的硬盘后会变成sda而原来的硬盘会变成sdb,会导致以前写的配置文件中的sda失效,严重的后果可能导致启动失败。在配置文件中不要写设备名
机械硬盘和固态硬盘
机械硬盘(HDD):Hard Disk Drive,即是传统普通硬盘,主要由:盘片,磁头,盘片转轴及
控制电机,磁头控制器,数据转换器,接口,缓存等几个部分组成。机械硬盘中所有的盘片都
装在一个旋转轴上,每张盘片之间是平行的,在每个盘片的存储面上有一个磁头,磁头与盘片
之间的距离比头发丝的直径还小,所有的磁头联在一个磁头控制器上,由磁头控制器负责各个
磁头的运动。磁头可沿盘片的半径方向运动,加上盘片每分钟几千转的高速旋转,磁头就可以
定位在盘片的指定位置上进行数据的读写操作。数据通过磁头由电磁流来改变极性方式被电磁
流写到磁盘上,也可以通过相反方式读取。硬盘为精密设备,进入硬盘的空气必须过滤
固态硬盘(SSD):Solid State Drive,用固态电子存储芯片阵列而制成的硬盘,由控制单元和
存储单元(FLASH芯片、DRAM芯片)组成。固态硬盘在接口的规范和定义、功能及使用方法
上与普通硬盘的完全相同,在产品外形和尺寸上也与普通硬盘一致
相较于HDD,SSD在防震抗摔、传输速率、功耗、重量、噪音上有明显优势,SSD传输速率性
能是HDD的2倍
相较于SSD,HDD在价格、容量、使用寿命上占有绝对优势
硬盘有价,数据无价,目前SSD不能完全取代HHD 机械硬盘损坏数据可能恢复,固态硬盘一但损坏数据恢复的可能性不大。
设备文件
磁盘设备的设备文件命名:/dev/DEV_FILE
SCSI, SATA, SAS, IDE,USB: /dev/sd
虚拟磁盘:/dev/vd
不同磁盘标识:a-z,aa,ab…
/dev/sda, /dev/sdb, …
同一设备上的不同分区:1,2, …
/dev/sda1, /dev/sda5
硬盘存储术语
head:磁头 有几个磁头就有几个盘面
track:磁道 最外圈的磁道是0向内圈依次增大
cylinder: 柱面 所有的0磁道综合在一起叫做0柱面
sector: 扇区,512bytes
chs 磁盘的三维
区位记录磁盘扇区结构
ZBR(Zoned Bit Recording) 外圈扇区多内圈扇区少
[root@centos ~]#fdisk -l
255 heads, 63 sectors/track, 26108 cylinders
这些数据都是理论上的
真正的硬盘已将不这么使用
没个磁道有多少个扇区,占用6bit 来存放扇区的个数 最多可以存放64个扇区
有多少个磁头占用8bit 2的8次方 256个
10bit 来存放磁道数 1024
这个存放数据的大小:512*63*1024*255/1024/1024/1024=8G
CHS和LBA
采用24bit位寻址
其中前10位表示cylinder,中间8位表示head,后面6位表示sector
最大寻址空间8GB
LBA(logical block addressing
LBA是一个整数,通过转换成CHS格式完成磁盘具体寻址
LBA采用48个bit位寻址
最大寻址空间128PB
由于CHS寻址方式的寻址空间在大概8GB以内,所以在磁盘容量小于大概8GB
时,可以使用CHS寻址方式或是LBA寻址方式;在磁盘容量大于大概8GB时,则
只能使用LBA寻址方式
硬盘的使用
1.分区
2.创建文件系统(格式化)
3.挂载:分配目录名
可以直接往硬盘上存数据,但是存放的是2进制
磁盘分区
为什么分区
优化I/O性能
实现磁盘空间配额限制
提高修复速度
隔离系统和程序
安装多个OS
采用不同文件系统
分区 分区必须是连续的空间
两种分区方式:MBR,GPT
MBR: Master Boot Record,1982年,使用32位表示扇区数,分区不超过2T
如何分区:按柱面 一个柱面8M,整柱面分区,每个分区都是8M的整数倍
0磁道0扇区:512bytes
446bytes: boot loader
64bytes:分区表
16bytes: 标识一个分区
2bytes: 55AA
4个主分区;3主分区+1扩展(N个逻辑分区)
MBR分区结构
[root@centos ~]#hexdump -C /dev/sda -n 512
00000000 eb 48 90 10 8e d0 bc 00 b0 b8 00 00 8e d8 8e c0 |.H…………..|
00000010 fb be 00 7c bf 00 06 b9 00 02 f3 a4 ea 21 06 00 |…|………!..|
00000020 00 be be 07 38 04 75 0b 83 c6 10 81 fe fe 07 75 |….8.u……..u|
00000030 f3 eb 16 b4 02 b0 01 bb 00 7c b2 80 8a 74 03 02 |………|…t..|
00000040 80 00 00 80 80 13 05 00 00 08 fa 90 90 f6 c2 80 |…………….|
00000050 75 02 b2 80 ea 59 7c 00 00 31 c0 8e d8 8e d0 bc |u….Y|..1……|
00000060 00 20 fb a0 40 7c 3c ff 74 02 88 c2 52 f6 c2 80 |. ..@|<.t…R…|
00000070 74 54 b4 41 bb aa 55 cd 13 5a 52 72 49 81 fb 55 |tT.A..U..ZRrI..U|
00000080 aa 75 43 a0 41 7c 84 c0 75 05 83 e1 01 74 37 66 |.uC.A|..u….t7f|
00000090 8b 4c 10 be 05 7c c6 44 ff 01 66 8b 1e 44 7c c7 |.L…|.D..f..D|.|
000000a0 04 10 00 c7 44 02 01 00 66 89 5c 08 c7 44 06 00 |….D…f.\..D..|
000000b0 70 66 31 c0 89 44 04 66 89 44 0c b4 42 cd 13 72 |pf1..D.f.D..B..r|
000000c0 05 bb 00 70 eb 7d b4 08 cd 13 73 0a f6 c2 80 0f |…p.}….s…..|
000000d0 84 f0 00 e9 8d 00 be 05 7c c6 44 ff 00 66 31 c0 |……..|.D..f1.|
000000e0 88 f0 40 66 89 44 04 31 d2 88 ca c1 e2 02 88 e8 |..@f.D.1……..|
000000f0 88 f4 40 89 44 08 31 c0 88 d0 c0 e8 02 66 89 04 |..@.D.1……f..|
00000100 66 a1 44 7c 66 31 d2 66 f7 34 88 54 0a 66 31 d2 |f.D|f1.f.4.T.f1.|
00000110 66 f7 74 04 88 54 0b 89 44 0c 3b 44 08 7d 3c 8a |f.t..T..D.;D.}<.|
00000120 54 0d c0 e2 06 8a 4c 0a fe c1 08 d1 8a 6c 0c 5a |T…..L……l.Z|
00000130 8a 74 0b bb 00 70 8e c3 31 db b8 01 02 cd 13 72 |.t…p..1……r|
00000140 2a 8c c3 8e 06 48 7c 60 1e b9 00 01 8e db 31 f6 |*….H|`……1.|
00000150 31 ff fc f3 a5 1f 61 ff 26 42 7c be 7f 7d e8 40 |1…..a.&B|..}.@|
00000160 00 eb 0e be 84 7d e8 38 00 eb 06 be 8e 7d e8 30 |…..}.8…..}.0|
00000170 00 be 93 7d e8 2a 00 eb fe 47 52 55 42 20 00 47 |…}.*…GRUB .G|
00000180 65 6f 6d 00 48 61 72 64 20 44 69 73 6b 00 52 65 |eom.Hard Disk.Re|
00000190 61 64 00 20 45 72 72 6f 72 00 bb 01 00 b4 0e cd |ad. Error…….|
000001a0 10 ac 3c 00 75 f4 c3 00 00 00 00 00 00 00 00 00 |..<.u………..|
000001b0 00 00 00 00 00 00 00 00 6c e7 04 00 00 00 80 20 |……..l…… |
000001c0 21 00 83 aa 28 82 00 08 00 00 00 00 20 00 00 aa |!…(……. …|
000001d0 29 82 83 fe ff ff 00 08 20 00 00 80 1a 06 00 fe |)……. …….|
000001e0 ff ff 83 fe ff ff 00 88 3a 06 00 80 a9 03 00 fe |……..:…….|
000001f0 ff ff 05 fe ff ff 00 08 e4 09 00 f8 1b 0f 55 aa |…………..U.|
00000200
一个16进制数占4位,两个16进制数就是一个字节
这些就是分区表 80 20 |……..l…… |
000001c0 21 00 83 aa 28 82 00 08 00 00 00 00 20 00 00 aa |!…(……. …|
000001d0 29 82 83 fe ff ff 00 08 20 00 00 80 1a 06 00 fe |)……. …….|
000001e0 ff ff 83 fe ff ff 00 88 3a 06 00 80 a9 03 00 fe |……..:…….|
000001f0 ff ff 05 fe ff ff 00 08 e4 09 00 f8 1b 0f
如果删除这64个字节这导致系统无法识别分区,分区上的数据也无法访问 最好做备份
如果破坏前面的446个字节导致系统无法启动
[root@centos data]#dd if=/dev/sda of=/data/mbr_backup bs=1 count=521 备份
521+0 records in
521+0 records out
521 bytes (521 B) copied, 0.00136284 s, 382 kB/s
备份到别的硬盘上
[root@centos ~]#scp /data/mbr_backup 172.18.116.150:/data
[root@centos ~]#scp /data/mbr_backup 172.18.116.150:/data
The authenticity of host ‘172.18.116.150 (172.18.116.150)’ can’t be established.
RSA key fingerprint is b0:69:a3:d1:6f:85:a0:48:64:69:6f:36:02:73:51:2c.
Are you sure you want to continue connecting (yes/no)? y
Please type ‘yes’ or ‘no’: yes
Warning: Permanently added ‘172.18.116.150’ (RSA) to the list of known hosts.
root@172.18.116.150’s password:
mbr_backup 100% 521 0.5KB/s 00:00
[root@centos ~]#dd if=/dev/zero of=/dev/sda bs=1 count=512 破坏硬盘分区数据
512+0 records in
512+0 records out
512 bytes (512 B) copied, 0.000873945 s, 586 kB/s
[root@centos ~]#fdisk -l
fdisk -l 查看的是磁盘的分区情况
Disk /dev/sda: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
lsblk查看的是内存的中存放的分区情况
[root@centos ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 3.7G 0 rom /media/CentOS_6.9_Final
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 48.8G 0 part /
├─sda3 8:3 0 29.3G 0 part /data
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 2G 0 part [SWAP]
在没有关机的情况下恢复
dd if=/data/mbr_backup of=/dev/sda
如果关机了
机器无法启动
进入救援模式
进入救援模式后没有ip地址,需要手动配置
ifconfig ens33 192.168.30.101 centos7
ping 192.168.30.103 centos6
scp 192.168.30.103:/data/mbr_backup . 将centos6中备份的文件拷贝到centos7中, .代表当前文件夹
只要硬盘大小一样,分区策略一样。如果没有备份,也可以拷贝硬盘大小一样,分区策略一样的别的机器上的硬盘
可以用下面的命令复制sda的主分区到sdb上,前提sdb要不小于sda,而且只能复制主分区和扩展分区,逻辑分区存放的分区情况不在sda里,所以无法复制逻辑分区
dd if=/dev/sda of=/dev/sdb bs=1 count=512
只想删除512个字节的最后2个字节,无法使用vim
删除的方法是 dd if=/dev/zero of=/dev/sda bs=1 count=2 skip=510 seek=510 skip 跳过的意思 seek寻找的意思
将最后两个字节删除后 linux就认为这款硬盘是没有分区的硬盘
GPT分区
EFI部分又可以分为4个区域:EFI信息区(GPT头)、分区表、GPT分区、备份区域
GPT:GUID(Globals Unique Identifiers) partition table 支持128个分区,
使用64位,支持8Z( 512Byte/block )64Z ( 4096Byte/block)
使用128位UUID(Universally Unique Identifier) 表示磁盘和分区 GPT分区表
自动备份在头和尾两份,并有CRC校验位
UEFI (统一扩展固件接口)硬件支持GPT,使操作系统启动
[root@CENTOS7 ~]#cat /etc/fstab UUID=是16进制数一共128位
#
# /etc/fstab
# Created by anaconda on Tue Mar 27 17:53:47 2018
#
# 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=0a1bc23e-06e5-4210-9b32-0edbff09ca1a / xfs defaults 0 0
UUID=4d8d9214-eeed-4758-8c34-f05492b9ea73 /boot xfs defaults 0 0
UUID=fb669d84-551f-4a70-a11e-f61deec0fd86 /data xfs defaults 0 0
UUID=906330a5-2af1-4bf4-8b2d-9337eaf92250 swap swap defaults 0 0
列出可用的磁盘设备
图形化磁盘管理功能工具:点击“应用程序”->“系统工
具”->“磁盘”或执行命令gnome-disks
BIOS+MBR与UEFI+GPT 机器启动搭配
开机 →bios初始化→bios自检→引导操作系统→进入系统
开机 →UEFI初始化→引导操作系统→进入系统
管理分区
列出块设备
lsblk
创建分区使用:
fdisk 创建MBR分区
gdisk 创建GPT分区
parted 高级分区操作
partprobe-重新设置内存中的内核分区表版本
parted命令
parted的操作都是实时生效的,小心使用
用法:parted [选项]… [设备 [命令 [参数]…]…]
parted /dev/sdb mklabel gpt|msdos
parted /dev/sdb print
parted /dev/sdb mkpart primary 1 200 (默认M)
parted /dev/sdb rm 1
parted –l 列出分区信息
root@CENTOS7 ~]#parted /dev/sdb mklabel msdos 创建什么形式的分区
Information: You may need to update /etc/fstab.
[root@CENTOS7 ~]#parted /dev/sdb mklabel gpt 可以直接修改但是会格式化硬盘
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do
you want to continue?
Yes/No? yes
Information: You may need to update /etc/fstab.
[root@CENTOS7 ~]#parted /dev/sdb mkpart primary 1 1000 创建一个主分区
Information: You may need to update /etc/fstab.
[root@CENTOS7 ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 50G 0 part /
├─sda3 8:3 0 30G 0 part /data
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 2G 0 part [SWAP]
sdb 8:16 0 100G 0 disk
└─sdb1 8:17 0 953M 0 part
sdc 8:32 0 80G 0 disk
sdd 8:48 0 60G 0 disk
sr0 11:0 1 8.1G 0 rom /run/media/root/CentOS 7 x86_64
[root@CENTOS7 ~]#parted /dev/sdb print 查看当前分区情况
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 1000MB 999MB primary
[root@CENTOS7 ~]#parted /dev/sdb mkpart primary 1001 1500
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I
Information: You may need to update /etc/fstab.
[root@CENTOS7 ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 50G 0 part /
├─sda3 8:3 0 30G 0 part /data
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 2G 0 part [SWAP]
sdb 8:16 0 100G 0 disk
├─sdb1 8:17 0 953M 0 part
└─sdb2 8:18 0 475.9M 0 part
sdc 8:32 0 80G 0 disk
sdd 8:48 0 60G 0 disk
sr0 11:0 1 8.1G 0 rom /run/media/root/CentOS 7 x86_64
root@CENTOS7 ~]#parted /dev/sdb rm 1
Information: You may need to update /etc/fstab.
[root@CENTOS7 ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 50G 0 part /
├─sda3 8:3 0 30G 0 part /data
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 2G 0 part [SWAP]
sdb 8:16 0 100G 0 disk
└─sdb2 8:18 0 475.9M 0 part
sdc 8:32 0 80G 0 disk
sdd 8:48 0 60G 0 disk
sr0 11:0 1 8.1G 0 rom /run/media/root/CentOS 7 x86_64
parted 命令是直接生效的,一但执行立即生效,没有后悔的机会
分区工具fdisk和gdisk
gdisk /dev/sdb 类fdisk 的GPT分区工具
fdisk -l [-u] [device…] 查看分区
fdisk /dev/sdb 管理分区
子命令:
p 分区列表
t 更改分区类型
n 创建新分区
d 删除分区
v 校验分区
u 转换单位
w 保存并退出
q 不保存并退出
[root@CENTOS7 ~]#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.
Command (m for help): m
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 给分区加一个标签,告诉自己这个分区是干什么用的。有8300,8e00等
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): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-209715199, default 2048):
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199):
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): +1G
Partition 1 of type Linux and of size 1 GiB is set
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x0003d393
Device Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): e
Partition number (2-4, default 2):
First sector (2099200-209715199, default 2099200): 2099999
Last sector, +sectors or +size{K,M,G} (2099999-209715199, default 209715199): +2G
Partition 2 of type Extended and of size 2 GiB is set
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x0003d393
Device Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
/dev/sdb2 2099999 6293503 2096752+ 5 Extended
Command (m for help): n
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (2099200-209715199, default 2099200):
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-2099998, default 2099998):
Using default value 2099998
Partition 3 of type Linux and of size 399.5 KiB is set
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x0003d393
Device Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
/dev/sdb2 2099999 6293503 2096752+ 5 Extended
/dev/sdb3 2099200 2099998 399+ 83 Linux
Partition table entries are not in disk order
Command (m for help): d
Partition number (1-3, default 3): 3
Partition 3 is deleted
Command (m for help): n
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (2099200-209715199, default 2099200): 6293504
Last sector, +sectors or +size{K,M,G} (6293504-209715199, default 209715199): +2G
Partition 3 of type Linux and of size 2 GiB is set
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x0003d393
Device Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
/dev/sdb2 2099999 6293503 2096752+ 5 Extended
/dev/sdb3 6293504 10487807 2097152 83 Linux
Command (m for help): n
Partition type:
p primary (2 primary, 1 extended, 1 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (2102047-6293503, default 2103296):
Using default value 2103296
Last sector, +sectors or +size{K,M,G} (2103296-6293503, default 6293503): 500M
Value out of range.
Last sector, +sectors or +size{K,M,G} (2103296-6293503, default 6293503): +500M
Partition 5 of type Linux and of size 500 MiB is set
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x0003d393
Device Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
/dev/sdb2 2099999 6293503 2096752+ 5 Extended
/dev/sdb3 6293504 10487807 2097152 83 Linux
/dev/sdb5 2103296 3127295 512000 83 Linux
Device Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
/dev/sdb2 2099200 6293503 2097152 5 Extended
/dev/sdb3 6293504 10487807 2097152 83 Linux
/dev/sdb5 2101248 3125247 512000 83 Linux
/dev/sdb6 3127296 3536895 204800 83 Linux
Command (m for help): d
Partition number (1-3,5,6, default 6): 5
Partition 5 is deleted
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x0003d393
Device Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
/dev/sdb2 2099200 6293503 2097152 5 Extended
/dev/sdb3 6293504 10487807 2097152 83 Linux
/dev/sdb5 3127296 3536895 204800 83 Linux
Command (m for help): w 保存退出 , re-read重新读part表写入内存
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
在使用了一段时间的硬盘上添加或者删除分区很可能导致磁盘和内存不同步
查看lsblk 和fdisk -l 的结果是否一样,如果不一样则需要
在centos7上输入命令 partprobe
在centos6上添加分区同步命令是partx -a /dev/sda
删除分区同步命令式 partx -d –nr 6-8 /dev/sda
如果又增加又删除了分区最好在增加完时同步一次后再删除分区后再同步
从新启动也可以解决不同步问题
[root@CENTOS7 ~]#fdisk /dev/sda
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.
Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (174069760-419430399, default 174069760):
Using default value 174069760
Last sector, +sectors or +size{K,M,G} (174069760-419430399, default 419430399): +1G
Partition 6 of type Linux and of size 1 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@CENTOS7 ~]#fdisk -l /dev/sda
Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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: 0x000b3918
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 106956799 52428800 83 Linux
/dev/sda3 106956800 169871359 31457280 83 Linux
/dev/sda4 169871360 419430399 124779520 5 Extended
/dev/sda5 169873408 174067711 2097152 82 Linux swap / Solaris
/dev/sda6 174069760 176166911 1048576 83 Linux
[root@CENTOS7 ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 50G 0 part /
├─sda3 8:3 0 30G 0 part /data
├─sda4 8:4 0 512B 0 part
└─sda5 8:5 0 2G 0 part [SWAP]
sdb 8:16 0 100G 0 disk
├─sdb1 8:17 0 1G 0 part
├─sdb2 8:18 0 1K 0 part
├─sdb3 8:19 0 2G 0 part
└─sdb5 8:21 0 200M 0 part
sdc 8:32 0 80G 0 disk
sdd 8:48 0 60G 0 disk
sr0 11:0 1 8.1G 0 rom /run/media/root/CentOS 7 x86_64
[root@CENTOS7 ~]#cat /proc/partitions
major minor #blocks name
11 0 8491008 sr0
8 0 209715200 sda
8 1 1048576 sda1
8 2 52428800 sda2
8 3 31457280 sda3
8 4 0 sda4
8 5 2097152 sda5
8 32 83886080 sdc
8 16 104857600 sdb
8 17 1048576 sdb1
8 18 1 sdb2
8 19 2097152 sdb3
8 21 204800 sdb5
8 48 62914560 sdd
[root@CENTOS7 ~]#ls /dev/sda*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4 /dev/sda5
[root@CENTOS7 ~]#partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
[root@CENTOS7 ~]#ls /dev/sda*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4 /dev/sda5 /dev/sda6
文件系统
文件系统是操作系统用于明确存储设备或分区上的文件的方法和数据结构;即
在存储设备上组织文件的方法。操作系统中负责管理和存储文件信息的软件结
构称为文件管理系统,简称文件系统
从系统角度来看,文件系统是对文件存储设备的空间进行组织和分配,负责文
件存储并对存入的文件进行保护和检索的系统。具体地说,它负责为用户建立
文件,存入、读出、修改、转储文件,控制文件的存取,安全控制,日志,压
缩,加密等
支持的文件系统:/lib/modules/`uname –r`/kernel/fs
[root@centos ~]#ls /lib/modules/2.6.32-696.el6.x86_64/kernel/fs 系统支持的文件类型
autofs4 cifs dlm ext2 fat gfs2 jffs2 nfs nls udf
btrfs configfs ecryptfs ext3 fscache jbd lockd nfs_common squashfs xfs
cachefiles cramfs exportfs ext4 fuse jbd2 mbcache.ko nfsd ubifs
[root@centos ~]#df -T centos6
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda2 ext4 50264772 5514216 42190556 12% /
tmpfs tmpfs 502056 8 502048 1% /dev/shm
/dev/sda1 ext4 999320 34944 911948 4% /boot
/dev/sda3 ext4 30106576 44988 28525588 1% /data
/dev/sr0 iso9660 3878870 3878870 0 100% /media/CentOS_6.9_Final
[root@CENTOS7 ~]#df -T centos7
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda2 xfs 52403200 3636732 48766468 7% /
devtmpfs devtmpfs 535296 0 535296 0% /dev
tmpfs tmpfs 550036 0 550036 0% /dev/shm
tmpfs tmpfs 550036 7948 542088 2% /run
tmpfs tmpfs 550036 0 550036 0% /sys/fs/cgroup
/dev/sda3 xfs 31441920 33084 31408836 1% /data
/dev/sda1 xfs 1038336 161620 876716 16% /boot
tmpfs tmpfs 110008 24 109984 1% /run/user/0
/dev/sr0 iso9660 8490330 8490330 0 100% /run/media/root/CentOS 7 x86_64
tmpfs tmpfs 110008 0 110008 0% /run/user/1000
文件系统类型
Linux文件系统:ext2(Extended file system), ext3, ext4, xfs(SGI), btrfs
(Oracle), reiserfs, jfs(AIX), swap
光盘:iso9660
Windows:FAT32不支持4G以上的文件, exFAT,NTFS
Unix: FFS(fast), UFS(unix), JFS2
网络文件系统:NFS, CIFS
集群文件系统:GFS2, OCFS2(oracle)
分布式文件系统: fastdfs,ceph, moosefs, mogilefs, glusterfs, Lustre
RAW:未经处理或者未经格式化产生的文件系统
文件系统分类
根据其是否支持”journal”功能: 日志的作用,修改一个文件的时候,先读到内存中在内存中修改,修改完成后再传到磁盘中,在这个过程中可能断电导致文件损坏.有日志就是在内存中修改完后先传给日志,之后在传给内存
日志型文件系统: ext3, ext4, xfs, …
非日志型文件系统: ext2, vfat
文件系统的组成部分:
内核中的模块:ext4, xfs, vfat
用户空间的管理工具:mkfs.ext4, mkfs.xfs,mkfs.vfat
Linux的虚拟文件系统:VFS 平时使用命令时是命令与VFS打交道然后再由VFS和真正的文件系统打交道
查前支持的文件系统:cat /proc/filesystems
root@CENTOS7 ~]#ls /lib/modules/3.10.0-693.el7.x86_64/kernel/fs
binfmt_misc.ko.xz ceph dlm fat gfs2 lockd nfs_common overlayfs udf
btrfs cifs exofs fscache isofs mbcache.ko.xz nfsd pstore xfs
cachefiles cramfs ext4 fuse jbd2 nfs nls squashfs
[root@CENTOS7 ~]#cd /lib/modules/3.10.0-693.el7.x86_64/kernel/fs
[root@CENTOS7 fs]#cd ext4
[root@CENTOS7 ext4]#ls
ext4.ko.xz 这个文件就是ext4的驱动
[root@centos ~]#free
total used free shared buffers cached
Mem: 1004112 517428 486684 1856 51480 168932
-/+ buffers/cache: 297016 707096
Swap: 2097148 0 2097148
buffers 写修改文件的时候先放到buffers中缓冲,等修改完成后再写入到硬盘中
cached 读文件到内存中的时候是先将文件放在硬盘cache中缓存在读取到内存中
如果一个文件系统时ext4当有多个服务器(节点)同时访问时会导致文件损坏,这时候需要集群文件系统GFS2
创建文件系统
mkfs命令:
(1) mkfs.FS_TYPE /dev/DEVICE
ext4
xfs
btrfs
vfat
(2) mkfs -t FS_TYPE /dev/DEVICE
-L ‘LABEL’: 设定卷标
分文件系统前要先查询次分区是否已经有文件系统
[root@CENTOS7 ~]#blkid /dev/sdb1 没有
[root@CENTOS7 ~]#blkid /dev/sda1 有文件系统时xfs
/dev/sda1: UUID=”4d8d9214-eeed-4758-8c34-f05492b9ea73″ TYPE=”xfs”
UUID:当你创建一个文件系统之后,操作系统自动分配一个UUID
也可以手动生成 命令是 uuidgen 128位重复的概率太小,所以可以用UUID代替设备名
[root@CENTOS7 ~]#mkfs -t ext4 /dev/sdb1 将/dev/sdb1创建成ext4的文件系统
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
[root@CENTOS7 ~]#blkid /dev/sdb1 查看是否创建ext4成功
/dev/sdb1: UUID=”c837ab44-edcb-43af-b4fa-c26832a7af7e” TYPE=”ext4″
[root@CENTOS7 ~]#df -T 目前无法查看的原因是还没有挂载,df -T 只能查看挂载的文件系统
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda2 xfs 52403200 3636716 48766484 7% /
devtmpfs devtmpfs 535296 0 535296 0% /dev
tmpfs tmpfs 550036 0 550036 0% /dev/shm
tmpfs tmpfs 550036 7956 542080 2% /run
tmpfs tmpfs 550036 0 550036 0% /sys/fs/cgroup
/dev/sda3 xfs 31441920 33084 31408836 1% /data
/dev/sda1 xfs 1038336 161620 876716 16% /boot
tmpfs tmpfs 110008 24 109984 1% /run/user/0
/dev/sr0 iso9660 8490330 8490330 0 100% /run/media/root/CentOS 7 x86_64
tmpfs tmpfs 110008 0 110008 0% /run/user/1000
[root@CENTOS7 ~]#blkid 查看所有的文件系统 centos7上的会显示光盘
/dev/sda1: UUID=”4d8d9214-eeed-4758-8c34-f05492b9ea73″ TYPE=”xfs”
/dev/sdb1: UUID=”c837ab44-edcb-43af-b4fa-c26832a7af7e” TYPE=”ext4″
/dev/sr0: UUID=”2017-09-06-10-53-42-00″ LABEL=”CentOS 7 x86_64″ TYPE=”iso9660″ PTTYPE=”dos”
/dev/sda2: UUID=”0a1bc23e-06e5-4210-9b32-0edbff09ca1a” TYPE=”xfs”
/dev/sda3: UUID=”fb669d84-551f-4a70-a11e-f61deec0fd86″ TYPE=”xfs”
/dev/sda5: UUID=”906330a5-2af1-4bf4-8b2d-9337eaf92250″ TYPE=”swap”
在centos6上如果用 blkid 是不显示光盘的,想要查看命令是blkid /dev/sr0
[root@CENTOS7 ~]#mkfs.vfat /dev/sdb3 用mkfs.按两次Tab键可以显示系统支持的所有文件系统
mkfs.fat 3.0.20 (12 Jun 2013)
[root@CENTOS7 ~]#blkid
/dev/sda1: UUID=”4d8d9214-eeed-4758-8c34-f05492b9ea73″ TYPE=”xfs”
/dev/sdb1: UUID=”c837ab44-edcb-43af-b4fa-c26832a7af7e” TYPE=”ext4″
/dev/sr0: UUID=”2017-09-06-10-53-42-00″ LABEL=”CentOS 7 x86_64″ TYPE=”iso9660″ PTTYPE=”dos”
/dev/sda2: UUID=”0a1bc23e-06e5-4210-9b32-0edbff09ca1a” TYPE=”xfs”
/dev/sda3: UUID=”fb669d84-551f-4a70-a11e-f61deec0fd86″ TYPE=”xfs”
/dev/sda5: UUID=”906330a5-2af1-4bf4-8b2d-9337eaf92250″ TYPE=”swap”
/dev/sdb3: UUID=”79AD-713B” TYPE=”vfat” 老旧 的文件系统所以uuid很短
[root@CENTOS7 ~]#mkfs.ext2 /dev/sdb3 换成ext2的
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
[root@CENTOS7 ~]#blkid
/dev/sda1: UUID=”4d8d9214-eeed-4758-8c34-f05492b9ea73″ TYPE=”xfs”
/dev/sdb1: UUID=”c837ab44-edcb-43af-b4fa-c26832a7af7e” TYPE=”ext4″
/dev/sr0: UUID=”2017-09-06-10-53-42-00″ LABEL=”CentOS 7 x86_64″ TYPE=”iso9660″ PTTYPE=”dos”
/dev/sda2: UUID=”0a1bc23e-06e5-4210-9b32-0edbff09ca1a” TYPE=”xfs”
/dev/sda3: UUID=”fb669d84-551f-4a70-a11e-f61deec0fd86″ TYPE=”xfs”
/dev/sda5: UUID=”906330a5-2af1-4bf4-8b2d-9337eaf92250″ TYPE=”swap”
/dev/sdb3: UUID=”8eeacb99-2062-4604-89c5-6518d832bec8″ TYPE=”ext2″
tune2fs -l 只能查看ext系列的文件系统
这是ext2的文件系统
[root@CENTOS7 ~]#tune2fs -l /dev/sdb3 查看文件系统
tune2fs 1.42.9 (28-Dec-2013)
Filesystem volume name: <none>
Last mounted on: <not available>
Filesystem UUID: 8eeacb99-2062-4604-89c5-6518d832bec8
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: ext_attr resize_inode dir_index filetype sparse_super large_file 不支持日志
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 131072
Block count: 524288
Reserved block count: 26214
Free blocks: 515284
Free inodes: 131061
First block: 0
Block size: 4096
Fragment size: 4096
Reserved GDT blocks: 127
Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 8192
Inode blocks per group: 512
Filesystem created: Sun Apr 22 17:38:34 2018
Last mount time: n/a
Last write time: Sun Apr 22 17:38:34 2018
Mount count: 0
Maximum mount count: -1
Last checked: Sun Apr 22 17:38:34 2018
Check interval: 0 (<none>)
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 28
Desired extra isize: 28
Default directory hash: half_md4
Directory Hash Seed: b917dba2-cf04-412e-8c76-02bf6c2d27cd
这是ext4的文件系统
[root@CENTOS7 ~]#tune2fs -l /dev/sdb1
tune2fs 1.42.9 (28-Dec-2013)
Filesystem volume name: <none>
Last mounted on: <not available>
Filesystem UUID: c837ab44-edcb-43af-b4fa-c26832a7af7e
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 65536
Block count: 262144
Reserved block count: 13107
Free blocks: 249189
Free inodes: 65525
First block: 0
Block size: 4096
Fragment size: 4096
Group descriptor size: 64
Reserved GDT blocks: 127
Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 8192
Inode blocks per group: 512
Flex block group size: 16
Filesystem created: Sun Apr 22 17:29:14 2018
Last mount time: n/a
Last write time: Sun Apr 22 17:29:14 2018
Mount count: 0
Maximum mount count: -1
Last checked: Sun Apr 22 17:29:14 2018
Check interval: 0 (<none>)
Lifetime writes: 33 MB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 28
Desired extra isize: 28
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: 34c92d7d-7e86-42af-90d4-9664aa2daec9
Journal backup: inode blocks
在centos7上创建文件系统时默认是有acl权限的
Default mount options: user_xattr acl 在centos6上手动创建的文件系统是Default mount options:<none>这时你对文件加acl权限会报错
添加acl命令 tune2fs -o acl /dev/sdb1
Filesystem state: clean 说明文件系统没有问题,如果有问题回显是NO clean这时需要修复命令是fsck
[root@CENTOS7 ~]#fsck /dev/sdb1
fsck from util-linux 2.23.2
e2fsck 1.42.9 (28-Dec-2013)
/dev/sdb1: clean, 11/65536 files, 12955/262144 blocks
本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/96854