基于CentOS7系統(tǒng)部署cobbler批量安裝系統(tǒng)

圖為開源自動化運維體系鏈

1、cobbler實現(xiàn)自動裝機
2夺艰、saltstack實現(xiàn)工程自動化配置
3黄痪、kubernetes實現(xiàn)容器自動化編排
4、zabbix實現(xiàn)自動化監(jiān)控
5见秽、elastic實現(xiàn)應(yīng)用日志自動化收集
6愉烙、jenkins實現(xiàn)開發(fā)持續(xù)化交付

原理分析

cobbler簡介

Cobbler通過將設(shè)置和管理一個安裝服務(wù)器所涉及的任務(wù)集中在一起,從而簡化了系統(tǒng)配置解取。相當(dāng)于Cobbler封裝了DHCP步责、TFTP、XINTED等服務(wù)肮蛹,結(jié)合了PXE勺择、kickstart等安裝方法,可以實現(xiàn)自動化安裝操作系統(tǒng)伦忠,并且可以同時提供多種版本省核,以實現(xiàn)在線安裝不同版本的系統(tǒng)。

cobbler相關(guān)服務(wù)

DHCP:DHCP(Dynamic Host Configuration Protocol昆码,動態(tài)主機配置協(xié)議)是一個局域網(wǎng)的網(wǎng)絡(luò)協(xié)議气忠,使用UDP協(xié)議工作邻储, 主要有兩個用途:給內(nèi)部網(wǎng)絡(luò)或網(wǎng)絡(luò)服務(wù)供應(yīng)商自動分配IP地址,給用戶或者內(nèi)部網(wǎng)絡(luò)管理員作為對所有計算機作中央管理的手段旧噪。DHCP有3個端口吨娜,其中UDP67和UDP68為正常的DHCP服務(wù)端口,分別作為DHCP Server和DHCP Client的服務(wù)端口淘钟;546號端口用于DHCPv6 Client宦赠,而不用于DHCPv4,是為DHCP failover服務(wù)米母,這是需要特別開啟的服務(wù)勾扭,DHCP failover是用來做“雙機熱備”的。
TFTP:TFTP是一種比較特殊的文件傳輸協(xié)議铁瞒。相對于FTP和目前經(jīng)常使用的SFTP妙色,TFTP是基于TCP/IP協(xié)議簇,用于進行簡單文件傳輸慧耍,提供簡單身辨、低開銷的傳輸服務(wù)。TFTP的端口設(shè)置為69芍碧。
相對于常見的FTP煌珊,TFTP有兩個比較好的優(yōu)勢:

  1. TFTP基于UDP協(xié)議,如果環(huán)境中沒有TCP協(xié)議师枣,是比較合適的怪瓶;
  2. TFTP執(zhí)行和代碼占用內(nèi)存量比較小践美;
    默認(rèn)情況下洗贰,Linux內(nèi)部是安裝了tftp服務(wù)器包的。但是默認(rèn)是不啟動的陨倡。
    PXE:預(yù)啟動執(zhí)行環(huán)境(Preboot eXecution Environment敛滋,PXE,也被稱為預(yù)執(zhí)行環(huán)境)提供了一種使用網(wǎng)絡(luò)接口(Network Interface)啟動計算機的機制兴革。這種機制讓計算機的啟動可以不依賴本地數(shù)據(jù)存儲設(shè)備(如硬盤)或本地已安裝的操作系統(tǒng)绎晃。
    PXE當(dāng)初是作為Intel的有線管理體系的一部分,Intel 和 Systemsoft于1999年9月20日公布其規(guī)格(版本2.1)[1]杂曲。通過使用像網(wǎng)際協(xié)議(IP)庶艾、用戶數(shù)據(jù)報協(xié)議(UDP)、動態(tài)主機設(shè)定協(xié)定(DHCP)擎勘、小型文件傳輸協(xié)議(TFTP)等幾種網(wǎng)絡(luò)協(xié)議和全局唯一標(biāo)識符(GUID)咱揍、通用網(wǎng)絡(luò)驅(qū)動接口(UNDI)、通用唯一識別碼(UUID)的概念并通過對客戶機(通過PXE自檢的電腦)固件擴展預(yù)設(shè)的API來實現(xiàn)目的棚饵。

交互過程

  1. 裸機配置了從網(wǎng)絡(luò)啟動后煤裙,開機后會廣播包請求DHCP服務(wù)器(cobbler server)發(fā)送其分配好的一個IP
  2. DHCP服務(wù)器(cobbler server)收到請求后發(fā)送responese掩完,包括其ip地址
  3. 裸機拿到ip后再向cobbler server發(fā)送請求OS引導(dǎo)文件的請求
  4. cobbler server告訴裸機OS引導(dǎo)文件的名字和TFTP server的ip和port
  5. 裸機通過上面告知的TFTP server地址和port通信,下載引導(dǎo)文件
  6. 裸機執(zhí)行執(zhí)行該引導(dǎo)文件硼砰,確定加載信息且蓬,選擇要安裝的os,期間會再向cobbler server請求kickstart文件和os image
  7. cobbler server發(fā)送請求的kickstart和os iamge
  8. 裸機加載kickstart文件
  9. 裸機接收os image题翰,安裝該os image

注釋:

系統(tǒng)環(huán)境準(zhǔn)備及其下載cobbler

一.系統(tǒng)環(huán)境

開啟兩個網(wǎng)卡恶阴。一個僅主機模式,一個橋接模式遍愿,主機模式對內(nèi)提供cobbler服務(wù)存淫。

image

[root@ken ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:13:a1:49 brd ff:ff:ff:ff:ff:ff
inet 192.168.4.190/24 brd 192.168.4.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe13:a149/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:13:a1:53 brd ff:ff:ff:ff:ff:ff
inet 192.168.182.128/24 brd 192.168.182.255 scope global noprefixroute dynamic eth1
valid_lft 1786sec preferred_lft 1786sec
inet6 fe80::7073:2021:e866:204f/64 scope link noprefixroute
valid_lft forever preferred_lft forever

系統(tǒng)版本:CentOS Linux release 7.5.1804 (Core)
內(nèi)網(wǎng)IP:192.168.182.128/24 #用來對內(nèi)通信,提供cobbler服務(wù)
外網(wǎng)IP:192.168.4.190/24 #連接外網(wǎng)

二. 關(guān)閉安全服務(wù)

[root@ken ~]# systemctl stop firewalld #關(guān)閉防火墻
[root@ken ~]# setenforce 0 #關(guān)閉selinux</pre>

三. 下載cobbler及其所需服務(wù)程序

2.沼填,配置yum源
[epel]
name=epel
enabled=1
gpgcheck=0
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
[centos]
name=centos base
enabled=1
gpgcheck=0
baseurl=http://mirrors.163.com/centos/7/os/x86_64/

3,下載相關(guān)的軟件
[root@ken ~]# yum install httpd cobbler tftp-server xinetd syslinux dhcp pykickstart -y

4.啟動tftp服務(wù)
[root@ken ~]# vim /etc/xinetd.d/tftp
disable = no
[root@ken ~]# systemctl restart xinetd

  1. 配置dhcp服務(wù)
    subnet 192.168.182.0 netmask 255.255.255.0 {
    range 192.168.182.10 192.168.182.20;
    default-lease-time 600;
    max-lease-time 7200;
    filename “pxelinux.0”;
    }
    [root@ken ~]# systemctl restart dhcpd

  2. 啟動httpd
    [root@ken ~]# systemctl restart httpd

  3. 啟動cobbler
    [root@ken ~]# systemctl restart cobblerd

8.cobbler檢測
[root@ken ~]# cobbler check

  1. 修改提示信息

1 : The ‘server’ field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work. This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
把server指定的本地IP改為提供cobbler服務(wù)的IP地址

2 : For PXE to be functional, the ‘next_server’ field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
把next_server指定的本地IP改為提供cobbler服務(wù)的IP地址

4 : enable and start rsyncd.service with systemctl
[root@ken ~]# systemctl restart rsyncd
[root@ken ~]# systemctl enable rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.

6 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to ‘cobbler’ and should be changed, try: “openssl passwd -1 -salt ‘random-phrase-here’ ‘your-password-here'” to generate new one
[root@ken ~]# openssl passwd -1 -salt ‘123’ ‘123’
1123$nE5gIYTYiF1PIXVOFjQaW/

  1. 重啟cobbler并在此檢測
    [root@ken ~]# systemctl restart cobblerd
    [root@ken ~]# cobbler check
    The following are potential configuration items that you may want to fix:
    1 : Some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run ‘cobbler get-loaders’ to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a recent version of the syslinux package installed and can ignore this message entirely. Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The ‘cobbler get-loaders’ command is the easiest way to resolve these requirements.
    2 : debmirror package is not installed, it will be required to manage debian deployments and repositories
    3 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
    Restart cobblerd and then run ‘cobbler sync’ to apply changes.

11.同步
[root@ken ~]# cobbler sync
task started: 2019-05-24_104642_sync
task started (id=Sync, time=Fri May 24 10:46:42 2019)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /usr/share/syslinux/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /usr/share/syslinux/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering TFTPD files
generating /etc/xinetd.d/tftp
cleaning link caches
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.manage_genders
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***

  1. 導(dǎo)入鏡
    [root@ken ~]# cobbler import –path=/mnt –name=”centos7″
    task started: 2019-05-24_104753_import
    task started (id=Media import, time=Fri May 24 10:47:53 2019)
    Found a candidate signature: breed=redhat, version=rhel6
    Found a candidate signature: breed=redhat, version=rhel7
    Found a matching signature: breed=redhat, version=rhel7
    Adding distros from path /var/www/cobbler/ks_mirror/centos7:
    creating new distro: centos7-x86_64
    trying symlink: /var/www/cobbler/ks_mirror/centos7 -> /var/www/cobbler/links/centos7-x86_64
    creating new profile: centos7-x86_64
    associating repos
    checking for rsync repo(s)
    checking for rhn repo(s)
    checking for yum repo(s)
    starting descent into /var/www/cobbler/ks_mirror/centos7 for centos7-x86_64
    processing repo at : /var/www/cobbler/ks_mirror/centos7
    need to process repo/comps: /var/www/cobbler/ks_mirror/centos7
    looking for /var/www/cobbler/ks_mirror/centos7/repodata/comps.xml
    Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos7/repodata
    *** TASK COMPLETE ***

13.查看生成的distro
[root@ken ~]# cobbler distro list
centos7-x86_64

14.查看生成的profile
[root@ken ~]# cobbler profile list
centos7-x86_64

15.準(zhǔn)備kickstart文件
[root@ken ~]# cp anaconda-ks.cfg /var/lib/cobbler/kickstarts/ks.cfg

16.編輯kickstart文件
url –url=http://192.168.182.128/cobbler/ks_mirror/centos7/

17.制作自己的profile
[root@ken ~]# cobbler profile add –distro=centos7-x86_64 –kickstart= /var/lib/cobbler/kickstarts/ks.cfg –name=”cent7_ken”

  1. 刪除默認(rèn)的profile
    [root@ken ~]# cobbler profile remove –name=centos7-x86_64
    [root@ken ~]# cobbler profile list
    cent7_ken

19.開啟客戶端進行驗證

注意:
1.客戶端模式需要與服務(wù)器模式一致

  1. 內(nèi)存最少3個G
    cobbler實現(xiàn)單臺服務(wù)器提供安裝不同操作系統(tǒng)

第一步:關(guān)機重新掛載新的光盤(vmeare)

第二步:開啟所有相關(guān)的服務(wù)
[root@ken ~]# systemctl restart httpd cobblerd xinetd dhcpd

第三步:在linux系統(tǒng)中掛載光盤
[root@ken ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only

第四步:導(dǎo)入一個新的鏡像
[root@ken ~]# cobbler import –path=/mnt –name=”centos7.3″
task started: 2019-05-24_192206_import
task started (id=Media import, time=Fri May 24 19:22:06 2019)
Found a candidate signature: breed=redhat, version=rhel6
Found a candidate signature: breed=redhat, version=rhel7
Found a matching signature: breed=redhat, version=rhel7
Adding distros from path /var/www/cobbler/ks_mirror/centos7.3:
creating new distro: centos7.3-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos7.3 -> /var/www/cobbler/links/centos7.3-x86_64
creating new profile: centos7.3-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/ks_mirror/centos7.3 for centos7.3-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos7.3
need to process repo/comps: /var/www/cobbler/ks_mirror/centos7.3
looking for /var/www/cobbler/ks_mirror/centos7.3/repodata/comps.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos7.3/repodata
*** TASK COMPLETE ***

第四步:查看生成的distro
[root@ken ~]# cobbler distro list
centos7-x86_64
centos7.3-x86_64

第五步:制作profile
[root@ken ~]# cobbler profile add –distro=centos7.3-x86_64 –kickstart=/var/lib/cobbler/kickstarts/ks.cfg –name=”centos7.3_ken”

第六步: 刪除默認(rèn)的profile
[root@ken ~]# cobbler profile list
cent7_ken
centos7.3-x86_64
centos7.3_ken
[root@ken ~]# cobbler profile remove –name=centos7.3-x86_64
[root@ken ~]# cobbler profile list
cent7_ken
centos7.3_ken

第七步:開啟客戶端進行驗證

find詳解

1.name: 指定文件名

例子1. 找到以ken結(jié)尾的文件
[root@ken ~]# find / -name “*ken”
/sys/firmware/dmi/entries/15-0/sys tem_event_log/change_token
/etc/yum.repos.d/ken
/var/spool/mail/ken
/home/ken

例子2:找到包含ken的文件
[root@ken ~]# find / -name “ken” | head -3
/sys/bus/hid/drivers/kensington
/sys/devices/pci0000:00/0000:00:00.0/broken_parity_status
/sys/devices/pci0000:00/0000:00:01.0/broken_parity_status

  1. perm:指定文件權(quán)限

例子1:找到所有644權(quán)限的文件
[root@ken ~]# find / -perm 644 | head -3
/boot/grub2/device.map
/boot/grub2/i386-pc/gcry_rmd160.mod
/boot/grub2/i386-pc/acpi.mod
[root@ken ~]# ls -l /boot/grub2/device.map
-rw-r–r–. 1 root root 64 Feb 26 22:25 /boot/grub2/device.map

例子2:模糊匹配644權(quán)限
[root@ken ~]# find / -perm -644 | head -3
/boot/efi
/boot/efi/EFI
/boot/efi/EFI/centos
[root@ken ~]# ls -l /boot/efi
total 0
drwxr-xr-x. 3 root root 20 Feb 26 22:21 EFI

  1. user:指定屬主

例子1:找到屬主是ken的文件
[root@ken ~]# find /etc -user ken
[root@ken ~]# find / -user ken
find: ‘/proc/1672/task/1672/fd/6’: No such file or directory
find: ‘/proc/1672/task/1672/fdinfo/6’: No such file or directory
find: ‘/proc/1672/fd/5’: No such file or directory
find: ‘/proc/1672/fdinfo/5’: No such file or directory
/var/spool/mail/ken
[root@ken ~]# ls -l /var/spool/mail/ken
-rw-rw—- 1 ken mail 0 Mar 11 18:16 /var/spool/mail/ken

4.group:指定屬組

例子1:
[root@ken ~]# ls -l /var/spool/mail/ken
-rw-rw—- 1 ken mail 0 Mar 11 18:16 /var/spool/mail/ken
[root@ken ~]# find / -group ken
find: ‘/proc/1709/task/1709/fd/6’: No such file or directory
find: ‘/proc/1709/task/1709/fdinfo/6’: No such file or directory
find: ‘/proc/1709/fd/5’: No such file or directory
find: ‘/proc/1709/fdinfo/5’: No such file or directory
/home/ken
/home/ken/.bash_logout
/home/ken/.bash_profile
/home/ken/.bashrc
/home/ken/.bash_history
[root@ken ~]# ls -l /home/ken -d
drwx—— 2 ken ken 83 Mar 11 18:16 /home/ken

  1. nouser:指定無屬主

例子1:
[root@ken ~]# useradd kenken
[root@ken ~]# touch test
[root@ken ~]# chown kenken: test
[root@ken ~]# userdel kenken
[root@ken ~]# find / -nouser
find: ‘/proc/1811/task/1811/fd/6’: No such file or directory
find: ‘/proc/1811/task/1811/fdinfo/6’: No such file or directory
find: ‘/proc/1811/fd/5’: No such file or directory
find: ‘/proc/1811/fdinfo/5’: No such file or directory
/root/test
/var/spool/mail/kenken
/home/kenken
/home/kenken/.bash_logout
/home/kenken/.bash_profile

  1. nogroup:指定無屬主
    [root@ken ~]# find / -nogroup
    find: ‘/proc/1848/task/1848/fd/6’: No such file or directory
    find: ‘/proc/1848/task/1848/fdinfo/6’: No such file or directory
    find: ‘/proc/1848/fd/5’: No such file or directory
    find: ‘/proc/1848/fdinfo/5’: No such file or directory
    /root/test
    /home/kenken
    /home/kenken/.bash_logout
    /home/kenken/.bash_profile
    /home/kenken/.bashrc

7.type:指定文件類型

例子1:找到所有的鏈接文件
[root@ken ~]# find / -type l | head -3
/dev/cdrom
/dev/snd/by-path/pci-0000:02:02.0
/dev/initctl
[root@ken ~]# ls -l /dev/cdrom
lrwxrwxrwx 1 root root 3 May 24 19:19 /dev/cdrom -> sr0
[root@ken ~]#

例子2: 找到所有普通文件
[root@ken ~]# find / -type f | head -3
/boot/grub2/device.map
/boot/grub2/i386-pc/gcry_rmd160.mod
/boot/grub2/i386-pc/acpi.mod
[root@ken ~]# ls -l /boot/grub2/device.map
-rw-r–r–. 1 root root 64 Feb 26 22:25 /boot/grub2/device.map
[root@ken ~]#

  1. size:指定文件大小

例子1:找到大于100M的文件
[root@ken ~]# find / -size +100M
/proc/kcore
find: ‘/proc/2018/task/2018/fd/6’: No such file or directory
find: ‘/proc/2018/task/2018/fdinfo/6’: No such file or directory
find: ‘/proc/2018/fd/5’: No such file or directory
find: ‘/proc/2018/fdinfo/5’: No such file or directory
/sys/devices/pci0000:00/0000:00:0f.0/resource1_wc
/sys/devices/pci0000:00/0000:00:0f.0/resource1
/root/gitlab-ce-8.9.5-ce.0.el7.x86_64.rpm
^C
[root@ken ~]# ls -lh /root/gitlab-ce-8.9.5-ce.0.el7.x86_64.rpm
-rw-r–r– 1 root root 265M Nov 13 2018 /root/gitlab-ce-8.9.5-ce.0.el7.x86_64.rpm

  1. mtime: 指文件修改時間括授,權(quán)限坞笙,屬主,屬組

例子1:找到文件修改時間一天以上的
[root@ken ~]# find / -mtime +1 | head -3
/boot
/boot/efi
/boot/efi/EFI
[root@ken ~]# stat /boot
File: ‘/boot’
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 801h/2049d Inode: 64 Links: 5
Access: (0555/dr-xr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-05-24 19:31:37.453000000 +0800
Modify: 2019-02-26 22:25:57.574000000 +0800
Change: 2019-03-14 18:49:48.066000000 +0800
Birth: –

  1. atime:指定文件訪問時間

[root@ken ~]# find / -atime +1 | head -3
/boot/grub2/device.map
/boot/grub2/i386-pc/gcry_rmd160.mod
/boot/grub2/i386-pc/acpi.mod
^C
[root@ken ~]# stat /boot/grub2/device.map
File: ‘/boot/grub2/device.map’
Size: 64 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 1572929 Links: 1
Access: (0644/-rw-r–r–) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-02-26 22:25:05.730000000 +0800
Modify: 2019-02-26 22:25:05.582000000 +0800
Change: 2019-02-26 22:25:05.582000000 +0800
Birth: –

11.ctime:指定文件內(nèi)容

例子1:指定文件內(nèi)容修改一天以上
[root@ken ~]# find / -ctime +1 | head -3
/boot
/boot/efi
/boot/efi/EFI
C
[root@ken ~]# stat /boot
File: ‘/boot’
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 801h/2049d Inode: 64 Links: 5
Access: (0555/dr-xr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-05-24 19:31:37.453000000 +0800
Modify: 2019-02-26 22:25:57.574000000 +0800
Change: 2019-03-14 18:49:48.066000000 +0800
Birth: –

  1. exec: 執(zhí)行命令

例子1:刪除無屬主的文件
[root@ken ~]# find / -nouser
find: ‘/proc/2395/task/2395/fd/6’: No such file or directory
find: ‘/proc/2395/task/2395/fdinfo/6’: No such file or directory
find: ‘/proc/2395/fd/5’: No such file or directory
find: ‘/proc/2395/fdinfo/5’: No such file or directory
/root/test
/var/spool/mail/kenken
/home/kenken
/home/kenken/.bash_logout
/home/kenken/.bash_profile
/home/kenken/.bashrc
[root@ken ~]# find / -nouser -exec rm -rf {} ;
find: missing argument to `-exec’
[root@ken ~]# find / -nouser -exec rm -rf {} ;
find: ‘/proc/2451/task/2451/fd/6’: No such file or directory
find: ‘/proc/2451/task/2451/fdinfo/6’: No such file or directory
find: ‘/proc/2451/fd/5’: No such file or directory
find: ‘/proc/2451/fdinfo/5’: No such file or directory
find: ‘/home/kenken’: No such file or directory
[root@ken ~]# find / -nouser
find: ‘/proc/2463/task/2463/fd/6’: No such file or directory
find: ‘/proc/2463/task/2463/fdinfo/6’: No such file or directory
find: ‘/proc/2463/fd/5’: No such file or directory
find: ‘/proc/2463/fdinfo/5’: No such file or directory

例子2:xargs
[root@ken ~]# touch {1..100}.txt
[root@ken ~]# powd
-bash: powd: command not found
[root@ken ~]# pwd
/root
[root@ken ~]# ls
100.txt 19.txt 28.txt 37.txt 46.txt 55.txt 64.txt 73.txt 82.txt 91.txt anaconda-ks.cfg
10.txt 1.txt 29.txt 38.txt 47.txt 56.txt 65.txt 74.txt 83.txt 92.txt a.out
11.txt 20.txt 2.txt 39.txt 48.txt 57.txt 66.txt 75.txt 84.txt 93.txt gitlab-ce-8.9.5-ce.0.el7.x86_64.rpm
12.txt 21.txt 30.txt 3.txt 49.txt 58.txt 67.txt 76.txt 85.txt 94.txt ken1
13.txt 22.txt 31.txt 40.txt 4.txt 59.txt 68.txt 77.txt 86.txt 95.txt
14.txt 23.txt 32.txt 41.txt 50.txt 5.txt 69.txt 78.txt 87.txt 96.txt
15.txt 24.txt 33.txt 42.txt 51.txt 60.txt 6.txt 79.txt 88.txt 97.txt
16.txt 25.txt 34.txt 43.txt 52.txt 61.txt 70.txt 7.txt 89.txt 98.txt
17.txt 26.txt 35.txt 44.txt 53.txt 62.txt 71.txt 80.txt 8.txt 99.txt
18.txt 27.txt 36.txt 45.txt 54.txt 63.txt 72.txt 81.txt 90.txt 9.txt
[root@ken ~]# find /root -name “*txt” | xargs rm -rf
[root@ken ~]# ls
anaconda-ks.cfg a.out gitlab-ce-8.9.5-ce.0.el7.x86_64.rpm ken1

13.find可以使用-a和-o或荚虚!

例子1:找到所有事普通文件并且權(quán)限是777
[root@ken ~]# find / -type f -a -perm 644 | head -3
/boot/grub2/device.map
/boot/grub2/i386-pc/gcry_rmd160.mod
/boot/grub2/i386-pc/acpi.mod
[root@ken ~]# ls -l /boot/grub2/device.map
-rw-r–r–. 1 root root 64 Feb 26 22:25 /boot/grub2/device.map

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末薛夜,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子版述,更是在濱河造成了極大的恐慌梯澜,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,509評論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件渴析,死亡現(xiàn)場離奇詭異晚伙,居然都是意外死亡,警方通過查閱死者的電腦和手機俭茧,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,806評論 3 394
  • 文/潘曉璐 我一進店門咆疗,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人母债,你說我怎么就攤上這事午磁。” “怎么了毡们?”我有些...
    開封第一講書人閱讀 163,875評論 0 354
  • 文/不壞的土叔 我叫張陵迅皇,是天一觀的道長。 經(jīng)常有香客問我衙熔,道長登颓,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,441評論 1 293
  • 正文 為了忘掉前任青责,我火速辦了婚禮挺据,結(jié)果婚禮上取具,老公的妹妹穿的比我還像新娘。我一直安慰自己扁耐,他們只是感情好暇检,可當(dāng)我...
    茶點故事閱讀 67,488評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著婉称,像睡著了一般块仆。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上王暗,一...
    開封第一講書人閱讀 51,365評論 1 302
  • 那天悔据,我揣著相機與錄音,去河邊找鬼俗壹。 笑死科汗,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的绷雏。 我是一名探鬼主播头滔,決...
    沈念sama閱讀 40,190評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼涎显!你這毒婦竟也來了坤检?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,062評論 0 276
  • 序言:老撾萬榮一對情侶失蹤期吓,失蹤者是張志新(化名)和其女友劉穎早歇,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體讨勤,經(jīng)...
    沈念sama閱讀 45,500評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡箭跳,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,706評論 3 335
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了悬襟。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片衅码。...
    茶點故事閱讀 39,834評論 1 347
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖脊岳,靈堂內(nèi)的尸體忽然破棺而出逝段,到底是詐尸還是另有隱情,我是刑警寧澤割捅,帶...
    沈念sama閱讀 35,559評論 5 345
  • 正文 年R本政府宣布奶躯,位于F島的核電站,受9級特大地震影響亿驾,放射性物質(zhì)發(fā)生泄漏嘹黔。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,167評論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望儡蔓。 院中可真熱鬧郭蕉,春花似錦、人聲如沸喂江。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,779評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽获询。三九已至涨岁,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間吉嚣,已是汗流浹背梢薪。 一陣腳步聲響...
    開封第一講書人閱讀 32,912評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留尝哆,地道東北人秉撇。 一個月前我還...
    沈念sama閱讀 47,958評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像较解,于是被迫代替她去往敵國和親畜疾。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,779評論 2 354