• 红帽学习笔记[RHCSA] 第八课[Nice值、时间同步、RPM与Yum软件安装]


    第八课

    nice值

    • 什么是nice值

    给进程设置的优先级就是nice。nice的范围是-20~20。nice值越小占用的系统资源就越多,就是这个进程不nice。

    • 如何查看nice值
    # 使用top命令查看时 会有一列时NI 就是nice值
    top - 14:01:36 up 9 min,  2 users,  load average: 0.08, 0.23, 0.18
    Tasks: 494 total,   2 running, 492 sleeping,   0 stopped,   0 zombie
    %Cpu(s): 16.7 us, 16.7 sy,  0.0 ni, 66.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
    
       PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                              
      3742 root      20   0  619884  18616  12072 R  60.4  1.0   0:00.85 gnome-terminal-                      
      3778 root      20   0  123924   1940   1152 R  60.4  0.1   0:00.43 top                                  
         1 root      20   0   53692   7660   2524 S   0.0  0.4   0:03.93 systemd                              
         2 root      20   0       0      0      0 S   0.0  0.0   0:00.07 kthreadd                             
         3 root      20   0       0      0      0 S   0.0  0.0   0:00.34 ksoftirqd/0                          
         5 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/0:0H                         
         7 root      rt   0       0      0      0 S   0.0  0.0   0:00.66 migration/0     
    
    • 设置nice值
    # 执行4个 dd命令 一致在吃资源
    PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                              
      3985 root      20   0  107920    624    532 R  95.6  0.0   0:14.21 dd if=/dev/zero of=/dev/null         
      3977 root      20   0  107920    624    532 R  93.7  0.0   0:15.64 dd if=/dev/zero of=/dev/null         
      3981 root      20   0  107920    620    532 R  86.4  0.0   0:14.18 dd if=/dev/zero of=/dev/null         
      3973 root      20   0  107920    624    532 R  84.4  0.0   0:16.26 dd if=/dev/zero of=/dev/null 
    # renice 其那两个nice值为-20
    renice -19 3977
    renice -20 3985
    renice +19 3981
    renice +19 3973
    #再次查看top
       PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                              
      3977 root       1 -19  107920    624    532 R 100.0  0.0  10:14.42 dd if=/dev/zero of=/dev/null         
      3985 root       0 -20  107920    624    532 R 100.0  0.0  10:38.96 dd if=/dev/zero of=/dev/null         
      3981 root      39  19  107920    620    532 R  96.5  0.0  10:01.17 dd if=/dev/zero of=/dev/null         
      3973 root      39  19  107920    624    532 R  88.6  0.0   9:55.61 dd if=/dev/zero of=/dev/null   
    # 修改后-20的进程一直比19nice值得占用的多,此时如果再开一个进程会更明显,但是虚拟机卡住了,做不了任何操作
    

    调整时间

    • timedatectl
    # 查看
    [root@master /]# timedatectl
          Local time: Fri 2019-08-30 14:21:58 CST
      Universal time: Fri 2019-08-30 06:21:58 UTC
            RTC time: Fri 2019-08-30 14:21:58
            Timezone: Asia/Shanghai (CST, +0800)
         NTP enabled: yes
    NTP synchronized: no
     RTC in local TZ: no
          DST active: n/a
    # 设置时间
    [root@master /]# timedatectl set-time "2019-08-30 14:24:20"
    [root@master /]# date
    Fri Aug 30 14:24:23 CST 2019
    # 查看所有时区
    [root@master /]# timedatectl list-timezones 
    # 设置时区
    [root@master /]# timedatectl set-timezone Asia/Hong_Kong
    # 设置ntp同步为yes
    timedatectl set-ntp 1
    
    • 自动对时

    使用的时服务 chronyd。redhat7自带的。

    # 编辑配置文件,注释掉默认的4行,增加阿里云的同步时间配置
    [root@master ~]# vi /etc/chrony.conf 
    #server 0.rhel.pool.ntp.org iburst
    #server 1.rhel.pool.ntp.org iburst
    #server 2.rhel.pool.ntp.org iburst
    #server 3.rhel.pool.ntp.org iburst
    server ntp6.aliyun.com iburst
    [root@localhost ~]# vi /etc/chrony.conf 
    [root@localhost ~]# vi /etc/chrony.conf 
    [root@localhost ~]# systemctl restart chronyd
    [root@localhost ~]# systemctl enable chronyd
    
    
    

    安装软件包

    • 什么时RPM:RPM package manager 包管理

    • 包的全名:

    httpd-tools-2.4.6-17.el7.x86_64.rpm
    # httpd-tools是名字
    # 2.4.6是版本
    # 17是发行班号(发行的次数)
    # .el7是radhat7平台
    # .x86_64处理器cpu的架构
    # .noarch是32位64位都可以
    
    • 考试提供的iso镜像中有rpm的包。挂载后直接使用
    [root@localhost /]# mount /dev/sr0 /mnt
    mount: /dev/sr0 is write-protected, mounting read-only
    [root@localhost /]# cd /mnt/Packages/
    # packages下面全都是rpm包 
    	# -i 安装 -v详细信息 -h 显示进度条
    [root@localhost Packages]#  rpm -ivh tree-1.6.0-10.el7.x86_64.rpm 
    warning: tree-1.6.0-10.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:tree-1.6.0-10.el7                ################################# [100%]
    # 卸载
    [root@localhost Packages]# rpm -evh tree
    Preparing...                          ################################# [100%]
    Cleaning up / removing...
       1:tree-1.6.0-10.el7                ################################# [100%]
    # 查看包
    [root@localhost Packages]# rpm -q tree
    tree-1.6.0-10.el7.x86_64
    #查看所有包,太多了不直接显示
    [root@localhost Packages]# rpm -qa|grep "tree"
    tree-1.6.0-10.el7.x86_64
    # 查看包的详细
    [root@localhost Packages]# rpm -qi tree
    Name        : tree
    Version     : 1.6.0
    Release     : 10.el7
    Architecture: x86_64
    Install Date: Fri 30 Aug 2019 04:16:26 PM CST
    Group       : Applications/File
    Size        : 89505
    License     : GPLv2+
    Signature   : RSA/SHA256, Thu 03 Apr 2014 05:33:48 AM CST, Key ID 199e2f91fd431d51
    Source RPM  : tree-1.6.0-10.el7.src.rpm
    Build Date  : Tue 28 Jan 2014 01:29:58 AM CST
    Build Host  : x86-020.build.eng.bos.redhat.com
    Relocations : (not relocatable)
    Packager    : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
    Vendor      : Red Hat, Inc.
    URL         : http://mama.indstate.edu/users/ice/tree/
    Summary     : File system tree viewer
    Description :
    The tree utility recursively displays the contents of directories in a
    tree-like format.  Tree is basically a UNIX port of the DOS tree
    utility.
    # 查看包装在哪里
    [root@localhost Packages]# rpm -ql tree
    /usr/bin/tree
    /usr/share/doc/tree-1.6.0
    /usr/share/doc/tree-1.6.0/LICENSE
    /usr/share/doc/tree-1.6.0/README
    /usr/share/man/man1/tree.1.gz
    # 查看文件从哪个包来的
    [root@localhost Packages]# rpm -qf /usr/share/doc/tree-1.6.0
    tree-1.6.0-10.el7.x86_64
    
    • 关于rpm 包的依赖问题

      • 树形依赖: a->b->c直接按照提示从下层一个个装就可以,按照c>b>a的顺序

      • 环形依赖:a->b->c->a将三个包名写在一起,直接一次装

      • 模块依赖:用httpd举例

    # 需要一些模块
    [root@localhost Packages]# rpm -ivh httpd-2.4.6-17.el7.x86_64.rpm 
    warning: httpd-2.4.6-17.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
    error: Failed dependencies:
    	/etc/mime.types is needed by httpd-2.4.6-17.el7.x86_64
    	httpd-tools = 2.4.6-17.el7 is needed by httpd-2.4.6-17.el7.x86_64
    	libapr-1.so.0()(64bit) is needed by httpd-2.4.6-17.el7.x86_64
    	libaprutil-1.so.0()(64bit) is needed by httpd-2.4.6-17.el7.x86_64
    # 访问 http://www.rpmfind.net/ 去查找这个模块在哪个包中,安装那个包
    

    使用yum 安装软件包

    • 什么是yum : yellow dog update manage黄狗更新管理器

    • 使用rpm安装yum

    [root@master Packages]# rpm -ivh yum-3.4.3-118.el7.noarch.rpm 
    warning: yum-3.4.3-118.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
    Preparing...                          ################################# [100%]
    	package yum-3.4.3-118.el7.noarch is already installed
    
    • 配置yum源
    ###注:考试给一个http的连接给啥写啥###
    # 将iso光盘挂在到/mnt目录上
    sudo mount -o /dev/sr0 /mnt
    # 查看目录挂载
    [kane@master mnt]$ df -H
    Filesystem             Size  Used Avail Use% Mounted on
    /dev/mapper/rhel-root   19G  3.3G   16G  18% /
    devtmpfs               949M     0  949M   0% /dev
    tmpfs                  958M  152k  958M   1% /dev/shm
    tmpfs                  958M  9.4M  949M   1% /run
    tmpfs                  958M     0  958M   0% /sys/fs/cgroup
    /dev/sda1              521M  125M  397M  24% /boot
    /dev/sr0               3.8G  3.8G     0 100% /mnt
    # 我们将iso中的package配置成yum源
    sudo yum-config-manager --add-repo=file:///mnt
    # 到 yum源目录下
    [root@master request-key.d]# cd /etc/yum.repos.d/
    # 追加内容gpgcheck=0。让其不检查
    [root@master yum.repos.d]# echo "gpgcheck=0" >> ./mnt.repo
    # 刷新缓存
    [root@master yum.repos.d]# yum makechahe
    
    
    • 安装与安装回滚
    # 安装httpd
    [root@master yum.repos.d]# yum install httpd
    # 查看安装历史
    [root@master yum.repos.d]# yum history
    Loaded plugins: langpacks, product-id, subscription-manager
    This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
    ID     | Login user               | Date and time    | Action(s)      | Altered
    -------------------------------------------------------------------------------
         5 | kane <kane>              | 2019-10-22 13:45 | Install        |    5      
    history list
    # 回滚某次安装 使用ID
    [root@master yum.repos.d]# yum history undo 5
    # 再次查看,会多一个抹去的操作
    [root@master yum.repos.d]# yum history
    Loaded plugins: langpacks, product-id, subscription-manager
    This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
    ID     | Login user               | Date and time    | Action(s)      | Altered
    -------------------------------------------------------------------------------
         6 | kane <kane>              | 2019-10-22 13:47 | Erase          |    5   
         5 | kane <kane>              | 2019-10-22 13:45 | Install        |    5    
    history list
    # 此处看不到每个Id都是做什么的,我们可以查看yum安装log
    [root@master yum.repos.d]# cat /var/log/yum.log
    Oct 22 13:45:09 Installed: apr-1.4.8-3.el7.x86_64
    Oct 22 13:45:09 Installed: apr-util-1.5.2-6.el7.x86_64
    Oct 22 13:45:09 Installed: httpd-tools-2.4.6-17.el7.x86_64
    Oct 22 13:45:09 Installed: mailcap-2.1.41-2.el7.noarch
    Oct 22 13:45:11 Installed: httpd-2.4.6-17.el7.x86_64
    Oct 22 13:47:04 Erased: httpd-2.4.6-17.el7.x86_64
    Oct 22 13:47:04 Erased: httpd-tools-2.4.6-17.el7.x86_64
    Oct 22 13:47:04 Erased: mailcap-2.1.41-2.el7.noarch
    Oct 22 13:47:04 Erased: apr-util-1.5.2-6.el7.x86_64
    Oct 22 13:47:05 Erased: apr-1.4.8-3.el7.x86_64
    
    • 软件包组
    [root@master yum.repos.d]# yum groups list
    Loaded plugins: langpacks, product-id, subscription-manager
    This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
    There is no installed groups file.
    Maybe run: yum groups mark convert (see man yum)
    Available environment groups:
       Minimal Install
       Infrastructure Server
       File and Print Server
       Basic Web Server
       Virtualization Host
       Server with GUI
    Available Groups:
       Compatibility Libraries
       Console Internet Tools
       Development Tools
       Graphical Administration Tools
       Legacy UNIX Compatibility
       Scientific Support
       Security Tools
       Smart Card Support
       System Administration Tools
       System Management
    Done
    
  • 相关阅读:
    Linux下sed,awk,grep,cut,find学习笔记
    Python文件处理(1)
    KMP详解
    Java引用详解
    解决安卓中页脚被输入法顶起的问题
    解决swfupload上传控件文件名中文乱码问题 三种方法 flash及最新版本11.8.800.168
    null id in entry (don't flush the Session after an exception occurs)
    HQL中的Like查询需要注意的地方
    spring mvc controller间跳转 重定向 传参
    node to traverse cannot be null!
  • 原文地址:https://www.cnblogs.com/primadonna/p/11719413.html
Copyright © 2020-2023  润新知