网络地址获取方式:
1)DHCP自动获取
2)手动配置
1.网卡配置文件: /etc/sysconfig/network-scripts/
[root@server0 Desktop]# ifconfig
eth0: flags=4163 mtu 1500 # eth0 系统分配, 无法修改
inet 172.25.0.11 netmask 255.255.255.0 broadcast 172.25.0.255
inet6 fe80::5054:ff:fe00:b prefixlen 64 scopeid 0x20
ether 52:54:00:00:00:0b txqueuelen 1000 (Ethernet)
RX packets 208 bytes 35256 (34.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 65 bytes 7468 (7.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 0 (Local Loopback)
RX packets 12 bytes 976 (976.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 12 bytes 976 (976.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@server0 Desktop]# cd /etc/sysconfig/network-scripts/
[root@server0 network-scripts]# ls
ifcfg-eth0 ifdown-ppp ifup-eth ifup-sit
ifcfg-lo ifdown-routes ifup-ippp ifup-Team
ifdown ifdown-sit ifup-ipv6 ifup-TeamPort
ifdown-bnep ifdown-Team ifup-isdn ifup-tunnel
ifdown-eth ifdown-TeamPort ifup-plip ifup-wireless
ifdown-ippp ifdown-tunnel ifup-plusb init.ipv6-global
ifdown-ipv6 ifup ifup-post network-functions
ifdown-isdn ifup-aliases ifup-ppp network-functions-ipv6
ifdown-post ifup-bnep ifup-routes
[root@server0 network-scripts]#
网卡配置文件:ifcfg-eth0 ifcfg-开头,
[root@server0 network-scripts]# cat ifcfg-eth0
DEVICE=eth0 #此配置文件应用给哪个网卡设备
BOOTPROTO=dhcp # 地址获取方式 dhcp:自动获取 static:手动配置, none:手动配置
ONBOOT=yes #开机启用此网络 管理性关闭
TYPE=Ethernet #网卡类型
USERCTL=yes
PEERDNS=yes
IPV6INIT=no
PERSISTENT_DHCLIENT=1
HWADDR=52:54:00:00:00:0b
NAME=eth0
[root@server0 network-scripts]#
生产环境:
rhel7中网卡命名变化: 网卡设备类型命名 en :ethernet network
rhel6中网卡命名与设备类型无关:eth0 eth1 eth2 一定要关闭 NetworkManager 服务 图形化工具
rhel7配置网络 工具:nmcli :network manager command line interface
1 ) 使用工具配置:
[root@server0 Desktop]# nmcli connection show
NAME UUID TYPE DEVICE
eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0
配置文件名 配置文件的ID 网卡类型 设备名
[root@server0 Desktop]#
删除现有的网卡配置文件:
[root@server0 network-scripts]# ls
ifcfg-eth0 ifdown-ppp ifup-eth ifup-sit
ifcfg-lo ifdown-routes ifup-ippp ifup-Team
ifdown ifdown-sit ifup-ipv6 ifup-TeamPort
ifdown-bnep ifdown-Team ifup-isdn ifup-tunnel
ifdown-eth ifdown-TeamPort ifup-plip ifup-wireless
ifdown-ippp ifdown-tunnel ifup-plusb init.ipv6-global
ifdown-ipv6 ifup ifup-post network-functions
ifdown-isdn ifup-aliases ifup-ppp network-functions-ipv6
ifdown-post ifup-bnep ifup-routes
[root@server0 network-scripts]# nmcli connection delete eth0 #删除网卡配置文件
[root@server0 network-scripts]# ls
ifcfg-lo ifdown-routes ifup-ippp ifup-Team
ifdown ifdown-sit ifup-ipv6 ifup-TeamPort
ifdown-bnep ifdown-Team ifup-isdn ifup-tunnel
ifdown-eth ifdown-TeamPort ifup-plip ifup-wireless
ifdown-ippp ifdown-tunnel ifup-plusb init.ipv6-global
ifdown-ipv6 ifup ifup-post network-functions
ifdown-isdn ifup-aliases ifup-ppp network-functions-ipv6
ifdown-post ifup-bnep ifup-routes
ifdown-ppp ifup-eth ifup-sit
[root@server0 network-scripts]#
[root@server0 network-scripts]# nmcli connection show
NAME UUID TYPE DEVICE
[root@server0 network-scripts]#
[root@server0 network-scripts]# ifconfig
eth0: flags=4163 mtu 1500
ether 52:54:00:00:00:0b txqueuelen 1000 (Ethernet)
RX packets 338 bytes 59290 (57.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 75 bytes 8196 (8.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 0 (Local Loopback)
RX packets 12 bytes 976 (976.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 12 bytes 976 (976.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@server0 network-scripts]#
使用nmcli 工具的前提: NetworkManager 一定要运行
[root@server0 network-scripts]# systemctl status NetworkManager
NetworkManager.service - Network Manager
Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled)
Active: active (running) since Sun 2019-06-23 08:57:20 CST; 45min ago
Main PID: 1104 (NetworkManager)
CGroup: /system.slice/NetworkManager.service
└─1104 /usr/sbin/NetworkManager --no-daemon
Jun 23 08:57:26 server0.example.com NetworkManager[1104]: startup c...
Jun 23 09:00:00 server0.example.com NetworkManager[1104]: use BlueZ...
如果将NetworkManager停掉,会产生什么结果:
[root@server0 network-scripts]# systemctl stop NetworkManager
[root@server0 network-scripts]#
[root@server0 network-scripts]#
[root@server0 network-scripts]# nmcli connection show # 无服务,工具无法使用
Error: nmcli (0.9.9.1) and NetworkManager (unknown) versions don't match. Force execution using --nocheck, but the results are unpredictable.
[root@server0 network-scripts]#
联系:
为server0配置如下的网络信息:
IP地址: 172.25.0.11
子网掩码: 255.255.255.0
网关: 172.25.0.254
DNS服务器地址: 172.25.254.254
为网卡eth0新建新的配置文件 ifcfg-mynetwork,默认配置为 DHCP ,指定此网卡开机启用。指定类型为 ethernet
[root@server0 network-scripts]# nmcli connection add con-name mynetwork ifname eth0 type ethernet autoconnect yes
Connection 'mynetwork' (22ce1b09-f64a-40ce-84d8-d9d848191e7f) successfully added.
[root@server0 network-scripts]# ls
ifcfg-lo ifdown-ppp ifup-eth ifup-sit
ifcfg-mynetwork ifdown-routes ifup-ippp ifup-Team
ifdown ifdown-sit ifup-ipv6 ifup-TeamPort
ifdown-bnep ifdown-Team ifup-isdn ifup-tunnel
ifdown-eth ifdown-TeamPort ifup-plip ifup-wireless
ifdown-ippp ifdown-tunnel ifup-plusb init.ipv6-global
ifdown-ipv6 ifup ifup-post network-functions
ifdown-isdn ifup-aliases ifup-ppp network-functions-ipv6
ifdown-post ifup-bnep ifup-routes
[root@server0 network-scripts]#
修改网卡配置文件,使用静态配置:
[root@server0 network-scripts]# cat ifcfg-mynetwork
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=mynetwork
UUID=22ce1b09-f64a-40ce-84d8-d9d848191e7f
DEVICE=eth0
ONBOOT=yes
[root@server0 network-scripts]#
配置ip ,网关
[root@server0 network-scripts]# nmcli connection modify mynetwork ipv4.addresses "172.25.0.11/24 172.25.0.254"
配置dns:
[root@server0 network-scripts]# nmcli connection modify mynetwork ipv4.dns 172.25.254.254
[root@server0 network-scripts]#
修改 地址获取方式为 静态:
[root@server0 network-scripts]# nmcli connection modify mynetwork ipv4.method manual
[root@server0 network-scripts]#
以新的配置激活网卡:
[root@server0 network-scripts]# nmcli connection up mynetwork
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1)
[root@server0 network-scripts]#
查看配置结果:
[root@server0 network-scripts]# ifconfig
eth0: flags=4163 mtu 1500
inet 172.25.0.11 netmask 255.255.255.0 broadcast 172.25.0.255
inet6 fe80::5054:ff:fe00:b prefixlen 64 scopeid 0x20
ether 52:54:00:00:00:0b txqueuelen 1000 (Ethernet)
RX packets 431 bytes 80911 (79.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 145 bytes 19790 (19.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 0 (Local Loopback)
RX packets 24 bytes 2152 (2.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 24 bytes 2152 (2.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@server0 network-scripts]# ip address
1: lo: mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:00:00:0b brd ff:ff:ff:ff:ff:ff
inet 172.25.0.11/24 brd 172.25.0.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fe00:b/64 scope link
valid_lft forever preferred_lft forever
[root@server0 network-scripts]#
查看网关:
[root@server0 network-scripts]#
[root@server0 network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.25.0.254 0.0.0.0 UG 1024 0 0 eth0
172.25.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
[root@server0 network-scripts]#
查看DNS:
[root@server0 network-scripts]# cat /etc/resolv.conf
# Generated by NetworkManager
search example.com
nameserver 172.25.254.254
[root@server0 network-scripts]#
查看ARP表项:
[root@server0 network-scripts]#
[root@server0 network-scripts]# arp -a
? (172.25.0.254) at 52:54:00:00:00:fe [ether] on eth0
[root@server0 network-scripts]#
再添加一个IP地址:
[root@server0 network-scripts]# nmcli connection modify mynetwork +ipv4.addresses 172.26.0.11/24
[root@server0 network-scripts]# nmcli connection up mynetwork
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
[root@server0 network-scripts]#
[root@server0 network-scripts]# ip address
1: lo: mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:00:00:0b brd ff:ff:ff:ff:ff:ff
inet 172.25.0.11/24 brd 172.25.0.255 scope global eth0
valid_lft forever preferred_lft forever
inet 172.26.0.11/24 brd 172.26.0.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fe00:b/64 scope link
valid_lft forever preferred_lft forever
[root@server0 network-scripts]#
添加DNS:
[root@server0 network-scripts]# nmcli connection modify mynetwork +ipv4.dns 8.8.8.8
[root@server0 network-scripts]# nmcli connection up mynetwork
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)
[root@server0 network-scripts]# cat /etc/resolv.conf
# Generated by NetworkManager
search example.com
nameserver 172.25.254.254
nameserver 8.8.8.8
[root@server0 network-scripts]#
[root@server0 network-scripts]# nmcli connection modify mynetwork -ipv4.dns 8.8.8.8
[root@server0 network-scripts]# nmcli connection up mynetwork
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
[root@server0 network-scripts]# cat /etc/resolv.conf
# Generated by NetworkManager
search example.com
nameserver 172.25.254.254
[root@server0 network-scripts]#
[root@server0 Desktop]# nmcli connection show
NAME UUID TYPE DEVICE
mynetwork 22ce1b09-f64a-40ce-84d8-d9d848191e7f 802-3-ethernet --
[root@server0 Desktop]#
修改配置文件所应用的网卡设备名:
[root@server0 Desktop]# nmcli connection show
NAME UUID TYPE DEVICE
mynetwork 22ce1b09-f64a-40ce-84d8-d9d848191e7f 802-3-ethernet --
[root@server0 Desktop]# nmcli device
DEVICE TYPE STATE CONNECTION
eno16777736 ethernet disconnected --
lo loopback unmanaged --
[root@server0 Desktop]# nmcli connection modify mynetwork connection.interface-name eno16777736
[root@server0 Desktop]# nmcli connection show
NAME UUID TYPE DEVICE
mynetwork 22ce1b09-f64a-40ce-84d8-d9d848191e7f 802-3-ethernet eno16777736
[root@server0 Desktop]# nmcli connection up mynetwork
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1)
[root@server0 Desktop]#
[root@server0 Desktop]# nmcli connection show mynetwork
1.归档:tar 只归档,无压缩功能
需求:在client1上将本地的/etc目录,归档到/backup目录
[root@server0 /]# cd /backup/
[root@server0 backup]# ls
website
[root@server0 backup]# cd ..
[root@server0 /]# ls
backup boot etc lib media opt project run srv tmp var
bin dev home lib64 mnt proc root sbin sys usr website
[root@server0 /]# cd /
[root@server0 /]# ls
backup boot etc lib media opt project run srv tmp var
bin dev home lib64 mnt proc root sbin sys usr website
[root@server0 /]# du -sh /etc
34M /etc
[root@server0 /]#
[root@server0 /]# tar -cvf /backup/etc.tar etc
[root@server0 /]# cd /backup/
[root@server0 backup]# ls
etc.tar website
[root@server0 backup]# du -sh etc.tar
30M etc.tar
[root@server0 backup]#
将归档解开到指定 /tmp
[root@server0 etc]# cd /backup/
[root@server0 backup]# ls
etc.tar website
[root@server0 backup]# tar -xf etc.tar -C /tmp/
[root@server0 backup]# cd /tmp/
[root@server0 tmp]# ls
etc systemd-private-M60Ns1
http.err systemd-private-mQd918
root-dir systemd-private-NxUC65
root-dir2 systemd-private-ojlC6f
root-file systemd-private-P21HpA
root-file2 systemd-private-P4AAgY
ssh-4dJaoaWqAXm2 systemd-private-pswtKp
ssh-GerWpAsTt8ug systemd-private-tdSF1J
ssh-IruwrkpsovjC systemd-private-Vx4GJi
ssh-wUeTAwfmP1gN test.sh
student-dir VMwareDnD
student-file2 vmware-root
student-file3 wangwu-file
student-file4 wangwu-file2
systemd-private-5HOcJf yum_save_tx.2019-06-22.09-30.N9Pw18.yumtx
systemd-private-CibDHd yum_save_tx.2019-06-23.10-00.gr85GF.yumtx
systemd-private-CkW6Oj
[root@server0 tmp]#
2.调用第三方压缩软件: gzip ,bzip2, xz
1、 tar + gzip:
压缩:
[root@server0 tmp]# cd /
[root@server0 /]#
[root@server0 /]# ls
backup boot etc lib media opt project run srv tmp var
bin dev home lib64 mnt proc root sbin sys usr website
[root@server0 /]# tar -czf /backup/etc.tar.gz etc
[root@server0 /]# cd /backup/
[root@server0 backup]# ls
etc.tar etc.tar.gz website
[root@server0 backup]# du -sh etc.tar.gz
8.4M etc.tar.gz
[root@server0 backup]#
解压:
[root@server0 backup]# du -sh etc.tar.gz
8.4M etc.tar.gz
[root@server0 backup]# rm -rf /tmp/etc
[root@server0 backup]# tar -xzf etc.tar.gz -C /tmp/
[root@server0 backup]#
2)tar + bzip2:
[root@server0 /]#
[root@server0 /]# ls
backup boot etc lib media opt project run srv tmp var
bin dev home lib64 mnt proc root sbin sys usr website
[root@server0 /]# tar -cjf /backup/etc.tar.bz2 etc
[root@server0 /]# cd /backup/
[root@server0 backup]# ls
etc.tar etc.tar.bz2 etc.tar.gz website
[root@server0 backup]# du -sh etc.tar.bz2
7.0M etc.tar.bz2
[root@server0 backup]#
3 )tar + xz:
[root@server0 /]# ls
backup boot etc lib media opt project run srv tmp var
bin dev home lib64 mnt proc root sbin sys usr website
[root@server0 /]# tar -cJf /backup/etc.tar.xz etc
[root@server0 /]# cd /backup/
[root@server0 backup]# ls
etc.tar etc.tar.bz2 etc.tar.gz etc.tar.xz website
[root@server0 backup]# du -sh etc.tar.xz
5.7M etc.tar.xz
[root@server0 backup]#
[root@server0 backup]# file etc.tar.bz2
etc.tar.bz2: bzip2 compressed data, block size = 900k
[root@server0 backup]# file etc.tar.xz
etc.tar.xz: XZ compressed data
[root@server0 backup]# file etc.tar.gz
etc.tar.gz: gzip compressed data, from Unix, last modified: Sun Jun 23 11:18:16 2019
[root@server0 backup]#
2.远程复制工具: scp 基于ssh安全的远程文件复制
[root@client1 backup]# scp /backup/etc.tar.xz [email protected]:/root
etc.tar.xz 100% 7864KB 45.5MB/s 00:00
[root@client1 backup]#
3.远程文件同步:增量同步 rsync 基于ssh安全的远程文件复制
将client1 中的/etc/同步到server1的/root目录下
[root@client1 /]# rsync -av /etc [email protected]:/root/
etc/yum/pluginconf.d/langpacks.conf
etc/yum/protected.d/
etc/yum/protected.d/systemd.conf
etc/yum/vars/
etc/yum/vars/infra
sent 34526911 bytes received 50287 bytes 13830879.20 bytes/sec
total size is 34353962 speedup is 0.99
[root@client1 /]#
[root@client1 /]# rsync -av /etc [email protected]:/root/
sending incremental file list
sent 72644 bytes received 737 bytes 48920.67 bytes/sec
total size is 34353962 speedup is 468.16
[root@client1 /]# rsync -av /etc [email protected]:/root/
sending incremental file list
sent 72644 bytes received 737 bytes 146762.00 bytes/sec
total size is 34353962 speedup is 468.16
[root@client1 /]#
我可以发现rsync会先查看该目录下是否已经存在了文件,如果没有,就将缺少的文件传输过去
[root@client1 etc]#
[root@client1 etc]# rsync -av /etc [email protected]:/root/
sending incremental file list
etc/
etc/backup-test
sent 72719 bytes received 759 bytes 146956.00 bytes/sec
total size is 34353970 speedup is 467.54
[root@client1 etc]# rsync -av /etc [email protected]:/root/
sending incremental file list
sent 72665 bytes received 737 bytes 48934.67 bytes/sec
total size is 34353970 speedup is 468.02
[root@client1 etc]#
[root@client1 etc]# echo "heloooo3233233" >> /etc/backup-test
[root@client1 etc]# rsync -av /etc [email protected]:/root/
sending incremental file list
etc/backup-test
sent 72791 bytes received 762 bytes 49035.33 bytes/sec
total size is 34354045 speedup is 467.07
[root@client1 etc]#
1.管理软件的工具:yum yellow-dog update manager 安装,删除,升级 在线网络方式 软件仓库
配置仓库:源 本地,ftp, nfs,http
软件仓库条件:
1) Packages目录 : 保存rpm包
2) repodata目录: 保存软件依赖的数据库
3) rpm-gpg-key :公钥文件 ,验证软件包的合法性
配置文件的位置: /etc/yum.repos.d/*.repo #后缀名一定是.repo
[root@server0 backup]# cd /etc/yum.repos.d/
[root@server0 yum.repos.d]# ls
rhel_dvd.repo
[root@server0 yum.repos.d]# rm -rf rhel_dvd.repo
[root@server0 yum.repos.d]# ls
[root@server0 yum.repos.d]#
[root@server0 yum.repos.d]# ls
[root@server0 yum.repos.d]# touch http.repo
[root@server0 yum.repos.d]# vim http.repo
[root@server0 yum.repos.d]# cat http.repo
[http]
name=http repo
baseurl=http://classroom.example.com/content/rhel7.0/x86_64/dvd/
enabled=1
#未配置 gpgcheck的选项 ,默认开启状态
查看仓库:
[root@server0 yum.repos.d]# yum repolist
Loaded plugins: langpacks
http | 4.1 kB 00:00
(1/2): http/group_gz | 134 kB 00:00
(2/2): http/primary_db | 3.4 MB 00:00
repo id repo name status
http http repo 4,305
repolist: 4,305
[root@server0 yum.repos.d]#
无法安装:
[root@server0 yum.repos.d]# yum -y install mariadb-server
Loaded plugins: langpacks
You have enabled checking of packages via GPG keys. This is a good thing.
However, you do not have any GPG public keys installed. You need to download
the keys for packages you wish to install and install them.
You can do that by running the command:
rpm --import public.gpg.key
Alternatively you can specify the url to the key you would like to use
for a repository in the 'gpgkey' option in a repository section and yum
will install it for you.
For more information contact your distribution or package provider.
Problem repository: http
[root@server0 yum.repos.d]#
[root@server0 yum.repos.d]# cat http.repo
[http]
name=http repo
baseurl=http://classroom.example.com/content/rhel7.0/x86_64/dvd/
enabled=1
gpgcheck=0
启用gpgcheck=1
[root@server0 tmp]# cat /etc/yum.repos.d/http.repo
[http]
name=http repo
baseurl=http://classroom.example.com/content/rhel7.0/x86_64/dvd/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[root@server0 tmp]#
[root@server0 rpm-gpg]# yum -y install mariadb-server
检验本地的rpm:
[root@server0 ~]# ls
anaconda-ks.cfg Pictures
Desktop Public
Documents Templates
Downloads Videos
kernel-3.10.0-123.1.2.el7.x86_64.rpm zsh-5.0.2-7.el7.x86_64.rpm
Music
[root@server0 ~]# rpm -K zsh-5.0.2-7.el7.x86_64.rpm
zsh-5.0.2-7.el7.x86_64.rpm: rsa sha1 (md5) pgp md5 OK
[root@server0 ~]# rpm -qa |grep pub
gpg-pubkey-fd431d51-4ae0493b
gpg-pubkey-2fa658e0-45700c69
[root@server0 ~]#
升级:
[root@server0 ~]# yum list updates
Loaded plugins: langpacks
Updated Packages
yum.noarch 3.4.3-118.el7 http
[root@server0 ~]#
查看包信息:
[root@server0 ~]# yum info mod_ssl
Loaded plugins: langpacks
Available Packages
Name : mod_ssl
Arch : x86_64
Epoch : 1
Version : 2.4.6
Release : 17.el7
Size : 97 k
Repo : http
Summary : SSL/TLS module for the Apache HTTP Server
URL : http://httpd.apache.org/
License : ASL 2.0
Description : The mod_ssl module provides strong cryptography for the Apache
: Web server via the Secure Sockets Layer (SSL) and Transport
: Layer Security (TLS) protocols.
[root@server0 ~]#
搜索软件包:
[root@server0 ~]# yum list |grep httpd
httpd.x86_64 2.4.6-17.el7 @rhel_dvd
httpd-tools.x86_64 2.4.6-17.el7 @rhel_dvd
httpd-devel.x86_64 2.4.6-17.el7 http
httpd-manual.noarch 2.4.6-17.el7 http
libmicrohttpd.i686 0.9.33-2.el7 http
libmicrohttpd.x86_64 0.9.33-2.el7 http
[root@server0 ~]#
[root@server0 ~]# yum search all "database"
2 . rpm管理软件: 离线安装工具
[root@server0 ~]# ls
anaconda-ks.cfg Pictures
Desktop Public
Documents Templates
Downloads Videos
kernel-3.10.0-123.1.2.el7.x86_64.rpm zsh-5.0.2-7.el7.x86_64.rpm
Music
[root@server0 ~]#
[root@server0 ~]# rpm -ivh zsh-5.0.2-7.el7.x86_64.rpm
Preparing... (100%################################# [100%]
Updating / installing...
1:zsh-5.0.2-7.el7 ( 2%################################# [100%]
[root@server0 ~]#
[root@server0 ~]# rpm -ivh samba-4.1.1-31.el7.x86_64.rpm
error: Failed dependencies:
samba-common = 4.1.1-31.el7 is needed by samba-0:4.1.1-31.el7.x86_64
libpopt_samba3.so()(64bit) is needed by samba-0:4.1.1-31.el7.x86_64
libpopt_samba3.so(SAMBA_4.1.1)(64bit) is needed by samba-0:4.1.1-31.el7.x86_64
[root@server0 ~]#
yum安装离线的rpm包:
[root@server0 ~]# yum -y localinstall samba-4.1.1-31.el7.x86_64.rpm
查询所有已安装的软件包:
[root@server0 ~]# rpm -qa
[root@server0 ~]# yum list installed
yum查看所有未安装:
[root@server0 ~]# yum list available
查询软件包配置文件列表:
[root@server0 ~]# rpm -qc httpd
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf.modules.d/00-base.conf
/etc/httpd/conf.modules.d/00-dav.conf
/etc/httpd/conf.modules.d/00-lua.conf
/etc/httpd/conf.modules.d/00-mpm.conf
/etc/httpd/conf.modules.d/00-proxy.conf
/etc/httpd/conf.modules.d/00-systemd.conf
/etc/httpd/conf.modules.d/01-cgi.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/logrotate.d/httpd
/etc/sysconfig/htcacheclean
/etc/sysconfig/httpd
[root@server0 ~]#
查询帮助文档:
[root@server0 ~]# rpm -qd httpd
/usr/share/doc/httpd-2.4.6/ABOUT_APACHE
/usr/share/doc/httpd-2.4.6/CHANGES
/usr/share/doc/httpd-2.4.6/LICENSE
/usr/share/doc/httpd-2.4.6/NOTICE
/usr/share/doc/httpd-2.4.6/README
/usr/share/doc/httpd-2.4.6/VERSIONING
/usr/share/doc/httpd-2.4.6/httpd-dav.conf
/usr/share/doc/httpd-2.4.6/httpd-default.conf
/usr/share/doc/httpd-2.4.6/httpd-info.conf
/usr/share/doc/httpd-2.4.6/httpd-languages.conf
/usr/share/doc/httpd-2.4.6/httpd-manual.conf
列出软件包的文件列表:
[root@server0 ~]# rpm -ql httpd
通过文件反向查找 软件包:
[root@server0 ~]# which ifconfig
/usr/sbin/ifconfig
[root@server0 ~]# rpm -qf /usr/sbin/ifconfig
net-tools-2.0-0.17.20131004git.el7.x86_64
[root@server0 ~]#
未安装的:
[root@server0 ~]# rpm -qpc zsh-5.0.2-7.el7.x86_64.rpm
/etc/skel/.zshrc
/etc/zlogin
/etc/zlogout
/etc/zprofile
/etc/zshenv
/etc/zshrc
[root@server0 ~]#
rpm包的本质:
1) 一个归档文件,按照绝对路径 安装文件的,安装的用户root
2) rpm包中包含了大量shell脚本程序,在安装时,删除时等都会运行的。
[root@server0 ~]# wget http://classroom.example.com/content/rhel7.0/x86_64/dvd/Packages/httpd-2.4.6-17.el7.x86_64.rpm
--2019-06-23 14:43:36-- http://classroom.example.com/content/rhel7.0/x86_64/dvd/Packages/httpd-2.4.6-17.el7.x86_64.rpm
Resolving classroom.example.com (classroom.example.com)... 172.25.254.254
Connecting to classroom.example.com (classroom.example.com)|172.25.254.254|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1211944 (1.2M) [application/x-rpm]
Saving to: ‘httpd-2.4.6-17.el7.x86_64.rpm’
100%[===================================>] 1,211,944 --.-K/s in 0.04s
2019-06-23 14:43:36 (27.0 MB/s) - ‘httpd-2.4.6-17.el7.x86_64.rpm’ saved [1211944/1211944]
[root@server0 ~]#
[root@server0 ~]# rpm -qp --scripts httpd-2.4.6-17.el7.x86_64.rpm
preinstall scriptlet (using /bin/sh):
# Add the "apache" user
/usr/sbin/useradd -c "Apache" -u 48 \
-s /sbin/nologin -r -d /usr/share/httpd apache 2> /dev/null || :
postinstall scriptlet (using /bin/sh):
if [ $1 -eq 1 ] ; then
# Initial installation
/usr/bin/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
/usr/bin/systemctl --no-reload disable httpd.service htcacheclean.service > /dev/null 2>&1 || :
/usr/bin/systemctl stop httpd.service htcacheclean.service > /dev/null 2>&1 || :
fi
postuninstall scriptlet (using /bin/sh):
/usr/bin/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@server0 ~]#
yum缓存过期:
[root@server0 ~]# yum clean all
Loaded plugins: langpacks
Cleaning repos: http
Cleaning up everything
[root@server0 ~]#
创建离线仓库:
[root@server0 ~]# yum --downloadonly --downloaddir=/root/samba-package samba
Loaded plugins: langpacks
No such command: samba. Please use /usr/bin/yum --help
[root@server0 ~]# yum --downloadonly --downloaddir=/root/samba-package install samba
Loaded plugins: langpacks
Resolving Dependencies
--> Running transaction check
---> Package samba.x86_64 0:4.1.1-31.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================================
Package Arch Version Repository Size
=================================================================================================
Installing:
samba x86_64 4.1.1-31.el7 http 527 k
Transaction Summary
=================================================================================================
Install 1 Package
Total download size: 527 k
Installed size: 1.5 M
Background downloading packages, then exiting:
samba-4.1.1-31.el7.x86_64.rpm | 527 kB 00:00:00
exiting because "Download Only" specified
[root@server0 ~]# ls
anaconda-ks.cfg kernel-3.10.0-123.1.2.el7.x86_64.rpm samba-package
Desktop Music Templates
Documents Pictures Videos
Downloads Public zsh-5.0.2-7.el7.x86_64.rpm
httpd-2.4.6-17.el7.x86_64.rpm samba-4.1.1-31.el7.x86_64.rpm
[root@server0 ~]# cd samba-package/
[root@server0 samba-package]# ls
samba-4.1.1-31.el7.x86_64.rpm
[root@server0 samba-package]# cd ..
[root@server0 ~]# ls
anaconda-ks.cfg kernel-3.10.0-123.1.2.el7.x86_64.rpm samba-package
Desktop Music Templates
Documents Pictures Videos
Downloads Public zsh-5.0.2-7.el7.x86_64.rpm
httpd-2.4.6-17.el7.x86_64.rpm samba-4.1.1-31.el7.x86_64.rpm
[root@server0 ~]# createrepo /root/samba-package
Spawning worker 0 with 1 pkgs
Spawning worker 1 with 0 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@server0 ~]# cd samba-package/
[root@server0 samba-package]# ls
repodata samba-4.1.1-31.el7.x86_64.rpm
[root@server0 samba-package]# pwd
/root/samba-package
[root@server0 samba-package]#
通过程序文件名查找所在的软件包:
[root@server0 samba-package]# yum provides "*/tree"
1.文件系统:保存和组织管理文件方法和数据结构
1)Linux: 基于日志文件系统
EXT3: rhel5 扩展文件系统版本3 , 服务器意外断电, fsck :文件系统检查 非常慢 , 服务器长时间不开机 也会fsck
EXT4: rhel6 性能好,同时fsck检查时间是ext3的10倍。 兼容性好 存储 小文件,中型文件 性能好。
XFS: rhel7 超大文件的支持,性能优化 支持更大的文件系统 100TB服务 CPU资源占用高
LVM: 软件
zfs: unix 在文件系统层 在线扩展空间和快照 sun java solaris 10
文件系统 创建在 块设备上的。
LV:逻辑卷 *** 在线磁盘扩容
/dev/sdb1 : 普通 主分区(逻辑)分区 **
/dev/sdb: 磁盘
一个块文件:
[root@server0 ~]# dd if=/dev/zero of=/root/blockdev bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 13.1099 s, 81.9 MB/s
[root@server0 ~]#
当前系统支持哪些文件系统:
[root@server0 mnt]# mkfs.
mkfs.btrfs mkfs.ext2 mkfs.ext4 mkfs.minix mkfs.vfat
mkfs.cramfs mkfs.ext3 mkfs.fat mkfs.msdos mkfs.xfs
[root@server0 mnt]#
创建文件系统:准备磁盘
[root@server0 mnt]# fdisk -l
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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 /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 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 # MBR
Disk identifier: 0x00013f3e
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 20970332 10484142+ 83 Linux
[root@server0 mnt]#
磁盘分区表的格式:
1)MBR: 磁盘默认格式,兼容性好 分区在大小最大 2TB
分区类型:
主分区: 最多4个, /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb4
扩展分区: 占用一个主分区的编号
逻辑分区:从5开编号
创建MBR: fdisk工具,创建mbr分区
[root@server0 mnt]# fdisk -l
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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 /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00013f3e
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 20970332 10484142+ 83 Linux
[root@server0 mnt]#
[root@server0 mnt]#
[root@server0 mnt]# 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 0xd008724a.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +2G
Partition 1 of type Linux and of size 2 GiB is set
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (4196352-20971519, default 4196352):
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-20971519, default 20971519): +2G
Partition 2 of type Linux and of size 2 GiB is set
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): e
Partition number (3,4, default 3):
First sector (8390656-20971519, default 8390656):
Using default value 8390656
Last sector, +sectors or +size{K,M,G} (8390656-20971519, default 20971519):
Using default value 20971519
Partition 3 of type Extended and of size 6 GiB is set
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 (8392704-20971519, default 8392704):
Using default value 8392704
Last sector, +sectors or +size{K,M,G} (8392704-20971519, default 20971519): +2G
Partition 5 of type Linux and of size 2 GiB is set
Command (m for help): p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xd008724a
Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux
/dev/sdb2 4196352 8390655 2097152 83 Linux
/dev/sdb3 8390656 20971519 6290432 5 Extended
/dev/sdb5 8392704 12587007 2097152 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@server0 mnt]#
格式化:
[root@server0 mnt]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1 isize=256 agcount=4, agsize=131072 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=524288, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@server0 mnt]#
挂载使用:
手动临时:重启服务器无效
[root@server0 /]#
[root@server0 /]# mount /dev/sdb1 /mnt
[root@server0 /]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 xfs 10G 3.6G 6.5G 36% /
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 140K 1.9G 1% /dev/shm
tmpfs tmpfs 1.9G 864K 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/loop0 ext4 976M 2.6M 907M 1% /run/media/root/6aa99fad-c938-4e1e-8cec-87d5af97ad8f
/dev/sdb1 xfs 2.0G 33M 2.0G 2% /mnt
[root@server0 /]#
永久挂载:/etc/fstab
[root@server0 /]# umount /mnt
[root@server0 /]# mkdir /database #创 建挂载点
[root@server0 /]#
[root@server0 /]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed May 7 01:22:57 2014
#
# 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=9bf6b9f7-92ad-441b-848e-0257cbb883d1 / xfs defaults 1 1
设备名 挂载点 文件系统 选项 dump开关 fsck检测顺序
[root@server0 /]#
[root@server0 /]# vim /etc/fstab
[root@server0 /]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed May 7 01:22:57 2014
#
# 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=9bf6b9f7-92ad-441b-848e-0257cbb883d1 / xfs defaults 1 1
/dev/sdb1 /database xfs defaults 1 2
[root@server0 /]#
[root@server0 /]# mount -a #激活未挂载的挂载点
[root@server0 /]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 xfs 10G 3.6G 6.5G 36% /
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 140K 1.9G 1% /dev/shm
tmpfs tmpfs 1.9G 864K 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/loop0 ext4 976M 2.6M 907M 1% /run/media/root/6aa99fad-c938-4e1e-8cec-87d5af97ad8f
/dev/sdb1 xfs 2.0G 33M 2.0G 2% /database
[root@server0 /]#
2) GPT: 支持最多 128主分区 超大分区
[root@server0 /]#
[root@server0 /]# fdisk -l
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xd008724a
Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux
/dev/sdb2 4196352 8390655 2097152 83 Linux
/dev/sdb3 8390656 20971519 6290432 5 Extended
/dev/sdb5 8392704 12587007 2097152 83 Linux
Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00013f3e
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 20970332 10484142+ 83 Linux
Disk /dev/sdc: 4398.0 GB, 4398046511104 bytes, 8589934592 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
[root@server0 /]#
[root@server0 /]#
[root@server0 /]# gdisk /dev/sdc
GPT fdisk (gdisk) version 0.8.6
Partition table scan:
MBR: not present
BSD: not present
APM: not present
GPT: not present
Creating new GPT entries.
Command (? for help): n
Partition number (1-128, default 1):
First sector (34-8589934558, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-8589934558, default = 8589934558) or {+-}size{KMGTP}: +2048G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
Command (? for help): p
Disk /dev/sdc: 8589934592 sectors, 4.0 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): F5DD9A38-115F-4D91-B1AD-2653BB2F021A
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 8589934558
Partitions will be aligned on 2048-sector boundaries
Total free space is 4294967229 sectors (2.0 TiB)
Number Start (sector) End (sector) Size Code Name
1 2048 4294969343 2.0 TiB 8300 Linux filesystem
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdc.
The operation has completed successfully.
[root@server0 /]# gdisk /dev/sdc
GPT fdisk (gdisk) version 0.8.6
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): p
Disk /dev/sdc: 8589934592 sectors, 4.0 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): F5DD9A38-115F-4D91-B1AD-2653BB2F021A
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 8589934558
Partitions will be aligned on 2048-sector boundaries
Total free space is 4294967229 sectors (2.0 TiB)
Number Start (sector) End (sector) Size Code Name
1 2048 4294969343 2.0 TiB 8300 Linux filesystem
Command (? for help):
链接文件:
1) 软链接文件: 类拟windows快捷方式 ,文件指向源文件,可以给文件和目录创建软链接,也可以跨文件系统。删除原文件,软链接失效
[root@localhost ~]# hostnamectl set-hostname server0.example.com
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# exit
[root@server0 tmp]# rm -rf /tmp/*
[root@server0 tmp]# ls
[root@server0 tmp]#
[root@server0 tmp]# ls
[root@server0 tmp]# ln -s /etc /tmp/etc-soft-link
[root@server0 tmp]# ls
etc-soft-link
[root@server0 tmp]# ls -l
total 0
lrwxrwxrwx. 1 root root 4 Jul 13 09:53 etc-soft-link -> /etc
[root@server0 tmp]#
[root@server0 tmp]# touch root-file
[root@server0 tmp]# echo "hello" >> root-file
[root@server0 tmp]# ls
etc-soft-link root-file
[root@server0 tmp]# cat root-file
hello
[root@server0 tmp]# ln -s root-file root-file-soft
[root@server0 tmp]#
[root@server0 tmp]# ls -l
total 4
lrwxrwxrwx. 1 root root 4 Jul 13 09:53 etc-soft-link -> /etc
-rw-r--r--. 1 root root 6 Jul 13 09:54 root-file
lrwxrwxrwx. 1 root root 9 Jul 13 09:54 root-file-soft -> root-file
[root@server0 tmp]# cat root-file
hello
[root@server0 tmp]# cat root-file-soft
hello
[root@server0 tmp]#
[root@server0 tmp]# rm -rf /tmp/root-file
[root@server0 tmp]# ls -l
total 0
lrwxrwxrwx. 1 root root 4 Jul 13 09:53 etc-soft-link -> /etc
lrwxrwxrwx. 1 root root 9 Jul 13 09:54 root-file-soft -> root-file
[root@server0 tmp]# cat root-file-soft
cat: root-file-soft: No such file or directory
[root@server0 tmp]#
硬链接文件: 为文件创建不同的文件名, inode节点号一样。
[root@server0 tmp]# ls -i -l
total 8
33554505 -rw-r–r--. 2 root root 6 Jul 13 09:56 root-file
33554505 -rw-r–r--. 2 root root 6 Jul 13 09:56 root-file-hard
[root@server0 tmp]# cat root-file
hello
[root@server0 tmp]# cat root-file-hard
hello
[root@server0 tmp]# echo “helloooooo” >> root-file
[root@server0 tmp]# cat root-file-hard
hello
helloooooo
[root@server0 tmp]# cat root-file
hello
helloooooo
[root@server0 tmp]# rm -rf /tmp/root-file
[root@server0 tmp]# cat root-file-hard
hello
helloooooo
[root@server0 tmp]#
不能为目录创建硬链接:
[root@server0 tmp]# ln /etc /tmp/etc-hard
ln: ‘/etc’: hard link not allowed for directory
[root@server0 tmp]#
不能跨文件系统:
[root@server0 tmp]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 37G 3.3G 34G 9% /
devtmpfs devtmpfs 977M 0 977M 0% /dev
tmpfs tmpfs 993M 0 993M 0% /dev/shm
tmpfs tmpfs 993M 9.0M 984M 1% /run
tmpfs tmpfs 993M 0 993M 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 199M 816M 20% /boot
tmpfs tmpfs 199M 28K 199M 1% /run/user/0
[root@server0 tmp]# cd /
[root@server0 /]# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
[root@server0 /]# touch root-file
[root@server0 /]# pwd
/
[root@server0 /]# ls
bin dev home lib64 mnt proc root-file sbin sys usr
boot etc lib media opt root run srv tmp var
[root@server0 /]# ln /root-file /boot/root-file-hard
ln: failed to create hard link ‘/boot/root-file-hard’ => ‘/root-file’: Invalid cross-device link
[root@server0 /]#
查找文件:
查看命令文件:
[root@server0 /]# which ifconfig
/usr/sbin/ifconfig
[root@server0 /]# which at
/usr/bin/at
[root@server0 /]#
[root@server0 /]# whereis ifconfig
ifconfig: /usr/sbin/ifconfig /usr/share/man/man8/ifconfig.8.gz
[root@server0 /]#
locate:查看文件,在文件数据库中查找
[root@server0 /]# updatedb
[root@server0 /]# updatedb
[root@server0 /]# locate ifconfig
/usr/libexec/hypervkvpd/hv_set_ifconfig
/usr/sbin/ifconfig
/usr/sbin/pifconfig
/usr/share/man/de/man8/ifconfig.8.gz
/usr/share/man/fr/man8/ifconfig.8.gz
/usr/share/man/man8/ifconfig.8.gz
/usr/share/man/man8/pifconfig.8.gz
/usr/share/man/pt/man8/ifconfig.8.gz
[root@server0 /]# updatedb #更新文件数据库
[root@server0 /]# cd /tmp/
[root@server0 tmp]# ls
root-file-hard
[root@server0 tmp]# touch root-file
[root@server0 tmp]# echo "hello" >> root-file
[root@server0 tmp]# locate root-file
/root-file
[root@server0 tmp]# ls
root-file root-file-hard
[root@server0 tmp]#
find查找文件, 遍历操作系统查找文件:
[root@server0 tmp]# find / -name root-file
/tmp/root-file
/root-file
[root@server0 tmp]#
find查看条件:
-name:文件名
-user: 用户
-perm: 权限
-size: 大小
-type: 类型: -:普通文件,d :目录 ,l:链接文件
查看所有是链接文件的文件:
[root@server0 tmp]# find / -type l
[root@server0 tmp]# find / -type b
/dev/dm-1
/dev/dm-0
/dev/sr0
/dev/sda2
/dev/sda1
/dev/sda
[root@server0 tmp]#
多个条件同时成立:查看目录名为etc的目录
[root@server0 tmp]# find / -name etc -and -type d
/run/initramfs/state/etc
/etc
/etc/avahi/etc
/usr/lib64/festival/etc
/usr/share/doc/oddjob-0.31.5/sample/etc
/usr/share/festival/lib/etc
/usr/etc
/usr/local/etc
[root@server0 tmp]#
查看系统中文件大小大于10MB的文件:
[root@server0 tmp]# find / -size +10M
对于已查找到的文件进行进一步处理:
查看student用户的所有文件,并将文件复制到/tmp/student
root@server0 ~]# su - student
[student@server0 ~]$ ls
[student@server0 ~]$ touch student_file{1..50}
[student@server0 ~]$ ls
student_file1 student_file21 student_file33 student_file45
student_file10 student_file22 student_file34 student_file46
student_file11 student_file23 student_file35 student_file47
student_file12 student_file24 student_file36 student_file48
student_file13 student_file25 student_file37 student_file49
student_file14 student_file26 student_file38 student_file5
student_file15 student_file27 student_file39 student_file50
student_file16 student_file28 student_file4 student_file6
student_file17 student_file29 student_file40 student_file7
student_file18 student_file3 student_file41 student_file8
student_file19 student_file30 student_file42 student_file9
student_file2 student_file31 student_file43
student_file20 student_file32 student_file44
[student@server0 ~]$ cd ..
[student@server0 home]$
[root@server0 ~]# find / -user student -exec cp -r -a {} /tmp/student/ \; # \; \转义符 ; find -exec 结束参数
[root@server0 ~]# cd /tmp/student/
[root@server0 student]# ls
abrt student_file18 student_file30 student_file43
extensions student_file19 student_file31 student_file44
lastnotification student_file2 student_file32 student_file45
plugins student_file20 student_file33 student_file46
student student_file21 student_file34 student_file47
student_file1 student_file22 student_file35 student_file48
student_file10 student_file23 student_file36 student_file49
student_file11 student_file24 student_file37 student_file5
student_file12 student_file25 student_file38 student_file50
student_file13 student_file26 student_file39 student_file6
student_file14 student_file27 student_file4 student_file7
student_file15 student_file28 student_file40 student_file8
student_file16 student_file29 student_file41 student_file9
student_file17 student_file3 student_file42
[root@server0 student]#