• Linux入门操作总结


    一、配置虚拟机NAT网络连接

    查看vmware的NAT网络默认配置

    vmwarestation软件点击 上方“编辑”,选择“虚拟网络编辑器”
    找到vmnet10,是NAT模式,子网地址是172.25.2.0,子网掩码是:255.255.255.0.
    再点击“NAT设置”,可看到它的网关:172.25.2.2

    配置当前虚拟机的网络配置

    vmwarestation软件点击 上方“虚拟机”,选择“设置”;
    首先没有NAT网卡的,点击“添加”,添加一个新的网络适配器。
    已经创建号NAT网卡的,进行如下配置:
    网络连接模式改为:"自定义(U):特定虚拟网络"
    在下拉选项中,选中“VMnet10(NAT模式)”

    配置linux网络

    # 进入网络配置目录
    cd /etc/sysconfig/network-scripts
    # 编辑nat网卡的配置
    vi ifcfg-ens33
    # 修改或添加如下信息:
    BOOTPROTO=static
    ONBOOT=yes
    IPADDR=172.25.2.101
    NETMASK=255.255.255.0
    GATEWAY=172.25.2.2
    DNS=8.8.8.8
    
    # 在vi编辑器中,输入:wq进行保存退出
    vi /etc/resolv.conf
    加入:
    nameserver 8.8.8.8
    输入:wq进行保存退出
    
    # 关闭防火墙
    systemctl stop firewalld.service
    systemctl disable firewalld.service
    
    # 重启网络
    systemctl restart network
    
    # 测试
    ping www.baidu.com
    

    二、yum源配置

    1、关闭网络管理、selinux、防火墙

    # 关闭网络管理
    systemctl disable NetworkManager
    # 关闭selinux,修改文件为disabled
    sed  -i 's/SELINUX=enforcing/SELINUX=disabled/g'  /etc/selinux/config
    # selinux修改生效
    setenforce 0
    

    2、更新yum源

    # 将官方的yum源备份到一个新目录:
    mkdir /etc/yum.repos.d/repo.bak/
    mv /etc/yum.repos.d/*.repo repo.bak/
    
    # 更新下载阿里源
    curl -o /etc/yum.repos.d/CentOS-Base.repo  http://mirrors.aliyun.com/repo/Centos-7.repo
    
    # 清理yum
    yum clean all
    yum makecache
    
    # 更新yum信息
    yum update -y
    

    3、安装lrzsz上传下载

    # 安装lrzsz
     yum install -y lrzsz
    # 上传
     rz
    # 安装vim
     yum install -y vim
    yum install -y vsftpd
    

    三、FTP配置和管理

    1、安装vsftpd

    (1)查询vsftpd是否安装

    # 查询vsftpd是否安装
    rpm -q vsftpd
    rpm -q openssh
    # 如果提示:package vsftpd is not installed,说明没有安装。
    
    #  查询 Linux 系统中所有已安装软件包的命令
    rpm -qa
    
    # 管道符查找出需要的内容
    rpm -qa| grep httpd
    rpm -qa | grep openssh
    
    # 查询软件包的详细信息
    rpm -qi httpd
    rpm -qi openssh
    

    (2)安装vsftpd

    yum install -y vsftpd
    yum install -y ftp
    rpm -qa| grep vsftpd
    

    (3)关闭防火墙

    setenforce 0;
    iptables -F;
    iptables -X;
    iptables -Z;
    systemctl stop firewalld;
    systemctl disable firewalld;
    

    2、vsftpd服务控制

    (1)控制服务

    # 重启服务
    systemctl restart vsftpd
    # 关闭服务
    systemctl stop vsftpd
    # 开启服务
    systemctl start vsftpd
    # 查看服务
    systemctl status vsftpd
    

    (2)服务开机设置

    # 开机启动vsftpd
    systemctl enable vsftpd
    # 开机不启动vsftpd
    systemctl disable vsftpd 
    

    四、vim和命令行快捷键

    1、命令行快捷键

    ctrl+左右键:在单词之间跳转
    ctrl+a:跳到本行的行首
    ctrl+e:跳到页尾
    Ctrl+u:删除当前光标前面的文字 (还有剪切功能)
    ctrl+k:删除当前光标后面的文字(还有剪切功能)
    Ctrl+L:进行清屏操作
    Ctrl+y:粘贴Ctrl+u或ctrl+k剪切的内容
    Ctrl+w:删除光标前面的单词的字符
    Alt – d :由光标位置开始,往右删除单词。往行尾删
    
    说明
    Ctrl – k: 先按住 Ctrl 键,然后再按 k 键;
    Alt – k: 先按住 Alt 键,然后再按 k 键;
    M – k:先单击 Esc 键,然后再按 k 键。
    
    移动光标
    Ctrl – a :移到行首
    Ctrl – e :移到行尾
    Ctrl – b :往回(左)移动一个字符
    Ctrl – f :往后(右)移动一个字符
    Alt – b :往回(左)移动一个单词
    Alt – f :往后(右)移动一个单词
    Ctrl – xx :在命令行尾和光标之间移动
    M-b :往回(左)移动一个单词
    M-f :往后(右)移动一个单词
    
    编辑命令
    Ctrl – h :删除光标左方位置的字符
    Ctrl – d :删除光标右方位置的字符(注意:当前命令行没有任何字符时,会注销系统或结束终端)
    Ctrl – w :由光标位置开始,往左删除单词。往行首删
    Alt – d :由光标位置开始,往右删除单词。往行尾删
    M – d :由光标位置开始,删除单词,直到该单词结束。
    Ctrl – k :由光标所在位置开始,删除右方所有的字符,直到该行结束。
    Ctrl – u :由光标所在位置开始,删除左方所有的字符,直到该行开始。
    Ctrl – y :粘贴之前删除的内容到光标后。
    ctrl – t :交换光标处和之前两个字符的位置。
    Alt + . :使用上一条命令的最后一个参数。
    Ctrl – _ :回复之前的状态。撤销操作。
    Ctrl -a + Ctrl -k 或 Ctrl -e + Ctrl -u 或 Ctrl -k + Ctrl -u 组合可删除整行。
    
    Bang(!)命令
    !! :执行上一条命令。
    ^foo^bar :把上一条命令里的foo替换为bar,并执行。
    !wget :执行最近的以wget开头的命令。
    !wget:p :仅打印最近的以wget开头的命令,不执行。
    !$ :上一条命令的最后一个参数, 与 Alt - . 和 $_ 相同。
    !* :上一条命令的所有参数
    !*:p :打印上一条命令是所有参数,也即 !*的内容。
    ^abc :删除上一条命令中的abc。
    ^foo^bar :将上一条命令中的 foo 替换为 bar
    ^foo^bar^ :将上一条命令中的 foo 替换为 bar
    !-n :执行前n条命令,执行上一条命令: !-1, 执行前5条命令的格式是: !-5
    
    查找历史命令
    Ctrl – p :显示当前命令的上一条历史命令
    Ctrl – n :显示当前命令的下一条历史命令
    Ctrl – r :搜索历史命令,随着输入会显示历史命令中的一条匹配命令,Enter键执行匹配命令;ESC键在命令行显示而不执行匹配命令。
    Ctrl – g :从历史搜索模式(Ctrl – r)退出。
    
    控制命令
    Ctrl – l :清除屏幕,然后,在最上面重新显示目前光标所在的这一行的内容。
    Ctrl – o :执行当前命令,并选择上一条命令。
    Ctrl – s :阻止屏幕输出
    Ctrl – q :允许屏幕输出
    Ctrl – c :终止命令
    Ctrl – z :挂起命令
    
    重复执行操作动作
    M – 操作次数 操作动作 : 指定操作次数,重复执行指定的操作。
    

    五、配置与管理磁盘

    1、fdisk:磁盘分区工具

    fdisk   /dev/sdb
    # 执行如上命令后进入fdisk磁盘分区操作
    # a:调整磁盘启动分区
    # d:删除分区
       Command (m for help): d
       Partition number (1-4, default 4): 4
       Partition 4 is deleted
    # l:列出所有支持的分区类型
       Command (m for help): l
       0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
       1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
       2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-  .....
    
    # m:列出所有命令和介绍
       Command (m for help): m
       Command action
          a   toggle a bootable flag
          b   edit bsd disklabel
          c   toggle the dos compatibility flag
          d   delete a partition
          g   create a new empty GPT partition table
          G   create an IRIX (SGI) partition table
          l   list known partition types
          m   print this menu
          n   add a new partition
          o   create a new empty DOS partition table
          p   print the partition table
          q   quit without saving changes
          s   create a new empty Sun disklabel
          t   change a partition system id
          u   change display/entry units
          v   verify the partition table
          w   write table to disk and exit
          x   extra functionality (experts only)
    
    # n:创建分区
       Command (m for help): n
       Partition type:
          p   primary (2 primary, 0 extended, 2 free)
          e   extended
       Select (default p): p
       Partition number (3,4, default 3): 3
       First sector (20973568-41943039, default 20973568): 
       Using default value 20973568
       Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +5G
       Partition 3 of type Linux and of size 5 GiB is set
    
    # p:列出硬盘分区表
       Command (m for help): p
    
       Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
       Units = sectors of 1 * 512 = 512 bytes
       Sector size (logical/physical): 512 bytes / 512 bytes
       I/O size (minimum/optimal): 512 bytes / 512 bytes
       Disk label type: dos
       Disk identifier: 0x7bded33b
    
          Device Boot      Start         End      Blocks   Id  System
       /dev/sdb1            2048    10487807     5242880   83  Linux
       /dev/sdb2        10487808    20973567     5242880   83  Linux
    # q:不保存更改,退出fdisk命令
       Command (m for help): q
       [root@localhost ~]# 
    
    # t:更改分区类型
       Command (m for help): t
       Partition number (1-3, default 3): 3
       Hex code (type L to list all codes): 82
       Changed type of partition 'Linux' to 'Linux swap / Solaris'
    
       Command (m for help): p
    
       Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
       Units = sectors of 1 * 512 = 512 bytes
       Sector size (logical/physical): 512 bytes / 512 bytes
       I/O size (minimum/optimal): 512 bytes / 512 bytes
       Disk label type: dos
       Disk identifier: 0x7bded33b
    
          Device Boot      Start         End      Blocks   Id  System
       /dev/sdb1            2048    10487807     5242880   83  Linux
       /dev/sdb2        10487808    20973567     5242880   83  Linux
    
    # u:切换所显示的分区大小的单位
       Command (m for help): u
       Changing display/entry units to cylinders (DEPRECATED!).
    
       Command (m for help): p
    
       Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
       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 label type: dos
       Disk identifier: 0x7bded33b
    
          Device Boot      Start         End      Blocks   Id  System
       /dev/sdb1               1         653     5242880   83  Linux
       /dev/sdb2             653        1306     5242880   83  Linux
    
       Command (m for help): u
       Changing display/entry units to sectors.
    
       Command (m for help): p       
    
       Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
       Units = sectors of 1 * 512 = 512 bytes
       Sector size (logical/physical): 512 bytes / 512 bytes
       I/O size (minimum/optimal): 512 bytes / 512 bytes
       Disk label type: dos
       Disk identifier: 0x7bded33b
    
          Device Boot      Start         End      Blocks   Id  System
       /dev/sdb1            2048    10487807     5242880   83  Linux
       /dev/sdb2        10487808    20973567     5242880   83  Linux
    
    # w:把修改写入硬盘分区表,再退出
       Command (m for help): w
       The partition table has been altered!
    
       Calling ioctl() to re-read partition table.
       Syncing disks.
    
    # x:列出高级选项
       Command (m for help): x
       Expert command (m for help): m
       Command action
          b   move beginning of data in a partition
          c   change number of cylinders
          d   print the raw data in the partition table
          e   list extended partitions
          f   fix partition order
          g   create an IRIX (SGI) partition table
          h   change number of heads
          i   change the disk identifier
          m   print this menu
          p   print the partition table
          q   quit without saving changes
          r   return to main menu
          s   change number of sectors/track
          v   verify the partition table
          w   write table to disk and exit
    

    2、mkfs:建立文件系统

    硬盘分区后,下一步的工作就是建立文件系统。建立文件系统的命令是
    mkfs [参数] 文件系统

    命令常用的参数选项如下:

    -t:指定要创建的文件系统类型。比如 ext3(centos5) ;ext4(centos6);xfs(centos7) 。如不指定默认施ext2。
    -c:建立文件系统前首先检查坏块。
    -l file:从文件file中读磁盘坏块列表,file文件一般是由磁盘坏块检查程序产生的。
    -V:输出建立文件系统详细信息。

    注意:直接格式化扩展分区是不允许的,只能格式化主分区和逻辑分区。如果要格式化一个扩展分区,要在扩展分区上创建逻辑分区.

    # 查看分区情况
    [root@localhost ~]# lsblk
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda               8:0    0   20G  0 disk 
    ├─sda1            8:1    0  500M  0 part /boot
    └─sda2            8:2    0 19.5G  0 part 
      ├─centos-root 253:0    0 17.5G  0 lvm  /
      └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
    sdb               8:16   0   20G  0 disk 
    ├─sdb1            8:17   0    5G  0 part 
    └─sdb2            8:18   0    5G  0 part 
    sr0              11:0    1 1024M  0 rom  
    # 建立ext4文件系统,建立时检查磁盘坏块并显示详细信息
    [root@localhost ~]# mkfs -t ext4 -V -c /dev/sdb1
    mkfs from util-linux 2.23.2
    mkfs.ext4 -c /dev/sdb1 
    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
    327680 inodes, 1310720 blocks
    65536 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=1342177280
    40 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks: 
            32768, 98304, 163840, 229376, 294912, 819200, 884736
    
    Checking for bad blocks (read-only test): done                                                 
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done 
    
    # 格式化为xfs格式
    # 需要加-f原因:提示这个分区已有ext4文件系统;需要使用-f选项强制覆盖。
    [root@localhost ~]# mkfs -t xfs -V -f /dev/sdb1
    mkfs from util-linux 2.23.2
    mkfs.xfs -f /dev/sdb1 
    meta-data=/dev/sdb1              isize=256    agcount=4, agsize=327680 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=0        finobt=0
    data     =                       bsize=4096   blocks=1310720, 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
    
    # 挂载操作
    mkdir /newFS
    mount /dev/sdb1 /mnt
    mount /dev/sdb2 /newFS
    df -H
    
    # 卸载挂载
    umount /mnt
    umount /newFS
    df -H
    

    3、fsck:检查文件系统的正确性,并对磁盘进行修复

    fsck(英文全拼:file system check)命令用于检查与修复 Linux 档案系统,可以同时检查一个或多个 Linux 档案系统。

    # 语法:fsck  [参数选项]  文件系统
    -t : 给定档案系统的型式,若在 /etc/fstab 中已有定义或 kernel 本身已支援的则不需加上此参数
    -s : 依序一个一个地执行 fsck 的指令来检查
    -A : 对/etc/fstab 中所有列出来的 partition 做检查
    -C : 显示完整的检查进度
    -d : 列印 e2fsck 的 debug 结果
    -p : 同时有 -A 条件时,同时有多个 fsck 的检查一起执行
    -R : 同时有 -A 条件时,省略 / 不检查
    -V : 详细显示模式
    -a : 如果检查有错则自动修复
    -r : 如果检查有错则由使用者回答是否修复
    
    # 必须先把磁盘卸载才能检查分区
    [root@localhost /]# fsck -a /dev/sdb1
    fsck from util-linux 2.23.2
    /sbin/fsck.xfs: XFS file system.
    [root@localhost /]# fsck -a /dev/sdb2
    fsck from util-linux 2.23.2
    /dev/sdb2: clean, 11/327680 files, 58462/1310720 blocks
    

    4、dd:建立和使用交换文件。

    dd:用指定大小的块拷贝一个文件,并在拷贝的同时进行指定的转换
    使用dd命令建立和使用交换文件。当系统的交换分区不能满足系统的要求而磁盘上又没有可用空间时,可以使用交换文件提供虚拟内存。

    # 查看交换空间方法
    # 查看swap交换空间方式一:free -m
    [root@localhost dev]# free -m
                  total        used        free      shared  buff/cache   available
    Mem:           1985         101        1455           8         428        1729
    Swap:          2303           0        2303
    # 查看swap交换空间方式二:grep SwapTotal /proc/meminfo
    [root@localhost dev]# grep SwapTotal /proc/meminfo 
    SwapTotal:       2359288 kB
    # 查看swap交换空间方式三:cat /proc/swaps
    [root@localhost dev]# cat /proc/swaps              
    Filename                                Type            Size    Used    Priority
    /dev/dm-1                               partition       2097148 0       -1
    /swapfile                               file            262140  0       -2
    
    # dd命令创建交换文件
    # 在硬盘的根目录下建立了一个块大小为1 024字节、块数为262144的名为swapfile的交换文件。该文件的大小为256MB
    [root@localhost dev]# dd  if=/dev/zero  of=/swapfile  bs=1024  count=262144
    10240+0 records in
    10240+0 records out
    10485760 bytes (10 MB) copied, 0.0824385 s, 127 MB/s
    
    # mkswap命令说明文件用于交换空间
    [root@localhost dev]# mkswap /swapfile
    Setting up swapspace version 1, size = 10236 KiB
    no label, UUID=1c15b10a-a536-40f0-9d5e-4ea88cfddc65
    
    # swapon激活交换空间
    [root@localhost dev]# swapon /swapfile
    swapon: /swap: insecure permissions 0644, 0600 suggested.
    
    # swapoff卸载被激活的交换空间
    [root@localhost dev]# swapoff /swapfile
    

    目前红帽官方推荐交换分区的大小应当与系统物理内存的大小保持线性比例关系,不过在小于2GB物理内存的系统中,交换分区大小应该设置为内存大小的两倍,如果内存大小多于2GB,交换分区大小应该是物理内存大小加上2GB。其原因在于,系统中的物理内存越大, 对于内存的负荷可能也越大。但是,如果物理内存大小扩展到数百GB,这样做就没什么意义了,大家说对吧!

    实际上,系统中交换分区的大小并不取决于物理内存的量,而是取决于系统中内存的负荷。Red Hat Enterprise Linux 可以在这样的情况下工作:完全没有交换分区,而且系统中匿名内存页和共享内存页小于3/4的物理内存量。在这种情况下,系统会将匿名内存页和共享内存页锁定在物理内存中,而使用剩余的物理内存来缓冲文件系统数据(pagecache),当内存耗尽时,系统内核只会回收利用这些pagecache内存。

    物理内存 交换分区(SWAP)
    <2G 至少2G
    2~4G 至少4G
    4~16G 至少8G
    16G~64G 至少16G
    64G~256G 至少32G

    5、df:查看文件系统的磁盘空间占用情况。

    df命令用来查看文件系统的磁盘空间占用情况。

    • 可以利用该命令来获取硬盘被占用了多少空间,以及目前还有多少空间等信息。
    • 还可以利用该命令获得文件系统的挂载位。
    # df命令的常见参数选项如下。
    -a:显示所有文件系统磁盘使用情况,包括0块的文件系统,如/proc文件系统。
    -k:以k字节为单位显示。
    -i:显示i节点信息。
    -t:显示各指定类型的文件系统的磁盘空间使用情况。
    -x:列出不是某一指定类型文件系统的磁盘空间使用情况(与t选项相反)。
    -T:显示文件系统类型
    
    [root@localhost ~]# df -i
    Filesystem               Inodes IUsed   IFree IUse% Mounted on
    /dev/mapper/centos-root 8910848 26331 8884517    1% /
    devtmpfs                 121677   384  121293    1% /dev
    tmpfs                    124744     1  124743    1% /dev/shm
    tmpfs                    124744   720  124024    1% /run
    tmpfs                    124744    16  124728    1% /sys/fs/cgroup
    /dev/sda1                524288   326  523962    1% /boot
    tmpfs                    124744     1  124743    1% /run/user/0
    [root@localhost ~]# df -k
    Filesystem              1K-blocks    Used Available Use% Mounted on
    /dev/mapper/centos-root  17811456 1032708  16778748   6% /
    devtmpfs                   486708       0    486708   0% /dev
    tmpfs                      498976       0    498976   0% /dev/shm
    tmpfs                      498976    7792    491184   2% /run
    tmpfs                      498976       0    498976   0% /sys/fs/cgroup
    /dev/sda1                 1038336  132472    905864  13% /boot
    tmpfs                       99796       0     99796   0% /run/user/0
    [root@localhost ~]# df -h
    Filesystem               Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root   17G 1009M   17G   6% /
    devtmpfs                 476M     0  476M   0% /dev
    tmpfs                    488M     0  488M   0% /dev/shm
    tmpfs                    488M  7.7M  480M   2% /run
    tmpfs                    488M     0  488M   0% /sys/fs/cgroup
    /dev/sda1               1014M  130M  885M  13% /boot
    tmpfs                     98M     0   98M   0% /run/user/0
    [root@localhost ~]# df -t xfs
    Filesystem              1K-blocks    Used Available Use% Mounted on
    /dev/mapper/centos-root  17811456 1032708  16778748   6% /
    /dev/sda1                 1038336  132472    905864  13% /boot
    [root@localhost ~]# df -t tmpfs
    Filesystem     1K-blocks  Used Available Use% Mounted on
    tmpfs             498976     0    498976   0% /dev/shm
    tmpfs             498976  7792    491184   2% /run
    tmpfs             498976     0    498976   0% /sys/fs/cgroup
    tmpfs              99796     0     99796   0% /run/user/0
    
    [root@localhost ~]# df -T -h
    Filesystem              Type      Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root xfs        17G 1009M   17G   6% /
    devtmpfs                devtmpfs  476M     0  476M   0% /dev
    tmpfs                   tmpfs     488M     0  488M   0% /dev/shm
    tmpfs                   tmpfs     488M  7.7M  480M   2% /run
    tmpfs                   tmpfs     488M     0  488M   0% /sys/fs/cgroup
    /dev/sda1               xfs      1014M  130M  885M  13% /boot
    tmpfs                   tmpfs      98M     0   98M   0% /run/user/0
    

    6、du:查看磁盘空间的使用情况。

    du命令用于显示磁盘空间的使用情况。该命令逐级显示指定目录的每一级子目录占用文件系统数据块的情况。 du命令的语法如下:
    du [参数选项] [文件或目录名称]

    du命令的参数选项:
    -s:对每个name 参数只给出占用的数据块总数。
    -a:递归显示指定目录中各文件及子目录中各文件占用的数据块数。
    -b:以字节为单位列出磁盘空间使用情况(AS 4.0中默认以KB为单位)。
    -k:以1024字节为单位列出磁盘空间使用情况。-h:按照KMG展示
    -c:在统计后加上一个总计(系统默认设置total)。
    -l:计算所有文件大小,对硬链接文件重复计算。
    -x:跳过在不同文件系统上的目录,不予统计。
    
    [root@localhost sysconfig]# du -b
    133	./cbq
    6	./console
    6	./modules
    158923	./network-scripts
    177031	.
    [root@localhost sysconfig]# du -k
    8	./cbq
    0	./console
    0	./modules
    232	./network-scripts
    324	.
    [root@localhost sysconfig]# du -h
    8.0K	./cbq
    0	./console
    0	./modules
    232K	./network-scripts
    324K	.
    [root@localhost sysconfig]# du -c
    8	./cbq
    0	./console
    0	./modules
    232	./network-scripts
    324	.
    324	total
    
    [root@localhost /]# du -xsh
    964M	.
    [root@localhost /]# du -sh
    du: cannot access ‘./proc/1941/task/1941/fd/4’: No such file or directory
    du: cannot access ‘./proc/1941/task/1941/fdinfo/4’: No such file or directory
    du: cannot access ‘./proc/1941/fd/3’: No such file or directory
    du: cannot access ‘./proc/1941/fdinfo/3’: No such file or directory
    1.1G	.
    

    7、mount/umount

    1. 在磁盘上建立好文件系统之后,还需要把新建立的文件系统挂载到系统上才能使用,这个过程称为挂载。
    • 文件系统所挂载到的目录被称为挂载点(mount point)。
    • Linux系统中提供了/mnt和/media两个专门的挂载点。
    • 挂载点应该是一个空目录,否则目录中原来的文件将被系统隐藏。
    1. 卸载文件系统的命令是umount。umount 命令的格式为

    umount 设备 挂载点

    # 挂载磁盘
    mount /dev/sdb2 /swift/node
    
    # 挂载本地iso文件到空目录
    mount -o loop CentOS-7-x86_64-DVD-1511.iso /mnt/
    umount /mnt
    mount -o loop /root/XianDian-IaaS-v2.2.iso /mnt
    # 解除挂载
    umount /mnt
    
    # 挂载光盘
    [root@localhost media]# mount -t iso9660 /dev/cdrom /media/cdrom
    mount: /dev/sr0 is write-protected, mounting read-only
    [root@localhost media]# du -sh *
    4.2G	cdrom
    # 解除挂载
    [root@localhost media]# umount /media/cdrom
    
    1. /etc/fstab文件系统的自动挂载
      如果要实现每次开机自动挂载文件系统,可以通过编辑/etc/fstab文件来实现。
      /etc/fstab文件的每一行代表一个文件系统,每一行又包含6列,这6列的内容如下所示。

    fs_spec:将要挂载的设备文件。
    fs_file:文件系统的挂载点。
    fs_vfstype:文件系统类型。
    fs_mntops:挂载选项,决定传递给mount命令时如何挂载,各选项之间用逗号隔开。
    fs_freq:由dump程序决定文件系统是否需要备份,0表示不备份,1表示备份。
    fs_passno:由fsck程序决定引导时是否检查磁盘以及检查次序,取值可以为0、1、2。

    [root@compute bin]# cat /etc/fstab 
    # /etc/fstab
    # Created by anaconda on Mon Sep 13 16:48:20 2021
    #
    # 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
    #
    /dev/mapper/centos-root /                       xfs     defaults        0 0
    UUID=f3d08635-77c9-4e68-9fac-a3e23df311c8 /boot                   xfs     defaults        0 0
    /dev/mapper/centos-swap swap                    swap    defaults        0 0
    /dev/sdb2 /swift/node xfs loop,noatime,nodiratime,nobarrier,logbufs=8 0 0
    

    六、LVM逻辑卷管理器

    LVM(Logical Volume Manager,逻辑卷管理器)可以允许用户对硬盘资源进行动态调整。

    1、部署逻辑卷

    # 让新添加的两块硬盘设备支持LVM
    [root@localhost ~]# pvcreate /dev/sdb /dev/sdc
      Physical volume "/dev/sdb" successfully created.
      Physical volume "/dev/sdc" successfully created.
    
    # 两块硬盘设备加入到storage卷组
    [root@localhost ~]# vgcreate storage-hqs /dev/sdb /dev/sdc 
      Volume group "storage-hqs" successfully created
    
    # 查看卷组的状态
    [root@localhost ~]# vgdisplay
      --- Volume group ---
      VG Name               storage-hqs
      System ID             
      Format                lvm2
      Metadata Areas        2
      Metadata Sequence No  1
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                0
      Open LV               0
      Max PV                0
      Cur PV                2
      Act PV                2
      VG Size               19.99 GiB
      PE Size               4.00 MiB
      Total PE              5118
      Alloc PE / Size       0 / 0   
      Free  PE / Size       5118 / 19.99 GiB
      VG UUID               qVIk5C-AbPD-NH0i-OMHJ-MRMQ-yAmu-QRwYq1
       
      --- Volume group ---
      VG Name               centos
      System ID             
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  3
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                2
      Open LV               2
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               <9.00 GiB
      PE Size               4.00 MiB
      Total PE              2303
      Alloc PE / Size       2303 / <9.00 GiB
      Free  PE / Size       0 / 0   
      VG UUID               JqLsRj-HHfi-0n1y-QBua-gIA5-WVo6-l8ayBT
    
    # 创建一个大小为2GB的逻辑卷hqs_test_lvm
    [root@localhost ~]# lvcreate -L 2G -n hqs_test_lvm storage-hqs
      Logical volume "hqs_test_lvm" created.
    
    # 查看逻辑卷状态
    [root@localhost ~]# lvdisplay        #  系统会有两个默认的LV:root、swap
      --- Logical volume ---
      LV Path                /dev/storage-hqs/hqs_test_lvm
      LV Name                hqs_test_lvm
      VG Name                storage-hqs
      LV UUID                npsiLb-bdXO-m0kz-pfLX-UTsf-A9Om-TcnyfT
      LV Write Access        read/write
      LV Creation host, time localhost.localdomain, 2021-11-12 02:27:46 -0500
      LV Status              available
      # open                 0
      LV Size                2.00 GiB
      Current LE             512
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:2
    
    # 查看lv和pv的简略信息
    [root@localhost ~]# pvs
      PV         VG          Fmt  Attr PSize   PFree  
      /dev/sda2  centos      lvm2 a--   <9.00g      0 
      /dev/sdb   storage-hqs lvm2 a--  <10.00g  <8.00g
      /dev/sdc   storage-hqs lvm2 a--  <10.00g <10.00g
    [root@localhost ~]# lvs
      LV           VG          Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      root         centos      -wi-ao---- <8.00g                                                    
      swap         centos      -wi-ao----  1.00g                                                    
      hqs_test_lvm storage-hqs -wi-a-----  2.00g 
    
    # 把生成好的逻辑卷进行格式化,然后挂载使用
    [root@localhost ~]# mkfs.xfs /dev/storage-hqs/hqs_test_lvm 
    meta-data=/dev/storage-hqs/hqs_test_lvm isize=512    agcount=4, agsize=131072 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0, sparse=0
    data     =                       bsize=4096   blocks=524288, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal log           bsize=4096   blocks=2560, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    [root@localhost ~]# mount /dev/storage-hqs/hqs_test_lvm /mnt/
    
    # 查看挂载状态
    [root@localhost ~]# lsblk
    NAME                        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda                           8:0    0   10G  0 disk 
    ├─sda1                        8:1    0    1G  0 part /boot
    └─sda2                        8:2    0    9G  0 part 
      ├─centos-root             253:0    0    8G  0 lvm  /
      └─centos-swap             253:1    0    1G  0 lvm  [SWAP]
    sdb                           8:16   0   10G  0 disk 
    └─storage--hqs-hqs_test_lvm 253:2    0    2G  0 lvm  /mnt
    sdc                           8:32   0   10G  0 disk 
    sr0                          11:0    1 1024M  0 rom  
    [root@localhost ~]# df -H -T
    Filesystem                            Type      Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root               xfs       8.6G  1.1G  7.6G  13% /
    devtmpfs                              devtmpfs  499M     0  499M   0% /dev
    tmpfs                                 tmpfs     511M     0  511M   0% /dev/shm
    tmpfs                                 tmpfs     511M  8.0M  503M   2% /run
    tmpfs                                 tmpfs     511M     0  511M   0% /sys/fs/cgroup
    /dev/sda1                             xfs       1.1G  136M  928M  13% /boot
    tmpfs                                 tmpfs     103M     0  103M   0% /run/user/0
    /dev/mapper/storage--hqs-hqs_test_lvm xfs       2.2G   34M  2.2G   2% /mnt
    

    2、扩容逻辑卷

    
    

    七、配置和管理apache服务

    HTTP(Hypertext Transfer Protocol,超文本传输协议)可以算得上是目前国际互联网基础上的一个重要组成部分。而Apache、IIS服务器是HTTP协议的服务器软件,微软的Internet Explorer和Mozilla的Firefox则是HTTP协议的客户端实现。

    1、安装和启动

    # 安装
    yum install -y httpd
    
    # 启动
    systemctl start httpd     # 访问当前虚拟机地址加端口 : 192.168.37.101:80
    # 关闭   
    systemctl stop httpd      # 访问当前虚拟机地址加端口 : 192.168.37.101:80
    # 查看
    systemctl status httpd
    # 重启
    systemctl restart httpd   # 访问当前虚拟机地址加端口 : 192.168.37.101:80
    
    # 关闭selinux,修改文件为disabled
    sed  -i 's/SELINUX=enforcing/SELINUX=disabled/g'  /etc/selinux/config
    # selinux修改生效
    setenforce 0
    # 查看是否生效
    getenforce   # 输出permissive
    
    # 关闭防火墙
    systemctl stop firewalld
    # 开机不启动防火墙
    systemctl disable  firewalld
    

    2、apache配置文件

    Linux系统中的配置文件及存放位置如下表:

    配置文件名 存放位置
    服务目录 /etc/httpd
    主配置文件 /etc/httpd/conf/httpd.conf
    网站数据目录 /var/www/html
    访问日志 /var/log/httpd/access_log
    错误日志 /var/log/httpd/error_log

    (1)主配置文件httpd.conf

    httpd.conf文件不区分大小写,在该文件中以“#”开始的行为注释行。除了注释和空行外,服务器把其他的行认为是完整的或部分的指令。指令又分为类似于shell的命令和伪HTML标记。
    指令的语法为“配置参数名称 参数值”。伪HTML标记的语法格式如下:

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    

    在httpd服务程序主配置文件中,存在三种:注释行信息、全局配置、区域配置。

    (2)常用参数及用途

    ServerRoot "/etc/httpd"    # 服务目录
    
    #Listen 12.34.56.78:80
    Listen 80       # 监听的IP地址和端口
    
    User apache     # 运行服务的用户
    Group apache    # 运行服务的用户组
    
    ServerAdmin root@localhost    # 管理员邮箱
    
    ServerName www.example.com:80 # 网站服务器域名
    
    DocumentRoot "/var/www/html"   # 文档根目录(网站)
    
    ErrorLog "logs/error_log"    # 错误日志文件
    LogLevel warn                # 日志等级
    
    CustomLog "logs/access_log" combined   # 访问日志文件
    
    AddDefaultCharset UTF-8    # 默认字符集
    
  • 相关阅读:
    将深度学习低延迟推理性能提高一倍
    常量特征
    数据库链接笔记
    html5页面调用手机打电话功能
    插件使用一表单验证一validation
    插件使用一树形插件---zTree一zTree异步加载
    插件使用一树形插件---zTree
    插件使用一进度条---nprogress
    插件使用一颜色选择器---cxColor
    插件使用一顶部消息提示---overhang
  • 原文地址:https://www.cnblogs.com/xiugeng/p/15470630.html
Copyright © 2020-2023  润新知