• The Fourth Week Lucklyzpp


     The Fourth Week Lucklyzpp

     (我的博客:www.lucklyzheng.top)

    先安装epel源包,跑个小火车,成为老司机。

    [13:53:38 root@lucklyzpp8 ~]#yum -y install epel-release
    [16:52:37 root@lucklyzpp8 ~]#yum -y install sl
    [16:53:57 root@lucklyzpp8 ~]#rpm -ql sl
    /usr/bin/sl
    /usr/lib/.build-id
    /usr/lib/.build-id/cb
    /usr/lib/.build-id/cb/664a85114a0cb25cf0460ada9ed86a7b128658
    .....
    
    [16:54:28 root@lucklyzpp8 ~]#sl -a

    1、自建yum仓库,分别为网络源和本地源

    yum源配置文件主要有2个。
    /etc/yum.conf:为所有仓库提供公共配置
    /etc/yum.repos.d/*.repo  这里面的*.repo文件。为仓库的指向提供配置

    一 置本地yum源
    1、确保虚拟机的光盘已经挂在了相应版本的系统光盘

    [06:09:53 root@lucklyzpp7 ~]#df -Th /mnt/
    文件系统                类型  容量  已用  可用 已用% 挂载点
    /dev/mapper/centos-root xfs    16G  2.2G   14G   14% /
    [06:10:27 root@lucklyzpp7 ~]#mount /dev/sr0 /mnt/
    mount: /dev/sr0 写保护,将以只读方式挂载
    [06:10:55 root@lucklyzpp7 ~]#df -Th /mnt/
    文件系统       类型     容量  已用  可用 已用% 挂载点
    /dev/sr0       iso9660  4.2G  4.2G     0  100% /mnt
    [06:11:00 root@lucklyzpp7 ~]#mkdir /etc/yum.repos.d/Centos
    [06:11:33 root@lucklyzpp7 ~]#mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/Centos
    Centos/        Centos-7.repo  
    [06:11:33 root@lucklyzpp7 ~]#mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/Centos/
    [06:13:20 root@lucklyzpp7 ~]#cd /etc/yum.repos.d/
    [06:13:29 root@lucklyzpp7 yum.repos.d]#ls
    Centos  repo_bak
    [06:13:31 root@lucklyzpp7 yum.repos.d]#cat > local.repo << EOF
    > [base]
    > name=local repo
    > baseurl=file:///mnt
    > enabled=1
    > gpgcheck=0
    > EOF
    [06:15:13 root@lucklyzpp7 yum.repos.d]#ls
    Centos  local.repo  repo_bak
    [06:15:17 root@lucklyzpp7 yum.repos.d]#yum repolist
    已加载插件:fastestmirror
    Determining fastest mirrors
    源标识                                     源名称                                         状态
    !base                                      local repo                                     10,072

    二,配置网络源(EPEL源)

    EPEL的yum源
    #阿里云
    https://mirrors.aliyun.com/epel/$releasever/x86_64

    baseurl=http://mirrors.aliyun.com/epel/$releasever/$basearch/

    技巧:在配置阿里云的epel源的时候可以使用变量的方式不容易出错

    [06:15:52 root@lucklyzpp7 yum.repos.d]#cat > epel.repo << EOF
    > [epel]
    > name=aliyun epel
    > baseurl=http://mirrors.aliyun.com/epel/$releasever/$basearch/
    > enabled=1
    > gpgcheck=0
    > EOF
    [06:35:42 root@lucklyzpp7 yum.repos.d]#ls
    Centos  epel.repo  local.repo  repo_bak
    [06:40:26 root@lucklyzpp7 yum.repos.d]#yum repolist
    已加载插件:fastestmirror
    Determining fastest mirrors
    base                                                                     | 3.6 kB  00:00:00     
    epel                                                                     | 4.7 kB  00:00:00     
    (1/5): base/primary_db                                                   | 3.1 MB  00:00:00     
    (2/5): base/group_gz                                                     | 166 kB  00:00:00     
    (3/5): epel/7/x86_64/group_gz                                            |  96 kB  00:00:01     
    (4/5): epel/7/x86_64/updateinfo                                          | 1.0 MB  00:00:19     
    (5/5): epel/7/x86_64/primary_db                                          | 7.0 MB  00:00:55     
    源标识                                        源名称                                      状态
    base                                          local repo                                   3,971
    epel/7/x86_64                                 aliyun epel                                 13,665
    repolist: 17,636

    三 本地服务搭建网络源

       [07:03:01 root@lucklyzpp7 yum.repos.d]#yum -y install httpd

    [07:04:01 root@lucklyzpp7 yum.repos.d]#systemctl start httpd
    [07:04:28 root@lucklyzpp7 yum.repos.d]#systemctl enable httpd
    Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
    [07:04:36 root@lucklyzpp7 yum.repos.d]#mkdir -p /var/www/html/centos/7
    [07:05:10 root@lucklyzpp7 yum.repos.d]#mount /dev/sr0 /var/www/html/centos/7/
    mount: /dev/sr0 写保护,将以只读方式挂载
    [07:05:47 root@lucklyzpp7 yum.repos.d]#ls /var/www/html/centos/7/
    CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
    EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL

    [07:13:47 root@lucklyzpp7 yum.repos.d]#elinks http://192.168.33.128/centos/7 --dump

    Index of /centos/7

    [1][ICO] [2]Name [3]Last [4]Size [5]Description
    modified
    ----------------------------------------------------------------------------
    [6][PARENTDIR] [7]Parent Directory   -  
    [8][ ] [9]CentOS_BuildTag 2018-05-02 14  
    19:28
    [10][DIR] [11]EFI/ 2018-05-04 -  
    04:34
    [12][TXT] [13]EULA 2017-08-30 227  
    22:33
    [14][TXT] [15]GPL 2015-12-10 18K  
    06:35
    [16][DIR] [17]LiveOS/ 2018-05-04 -  
    04:34
    [18][DIR] [19]Packages/ 2018-05-04 -  
    04:52
    [20][ ] [21]RPM-GPG-KEY-CentOS-7 2015-12-10 1.7K  
    06:35
    [22][ ] [23]RPM-GPG-KEY-CentOS-T..> 2015-12-10 1.7K  
    06:35
    [24][ ] [25]TRANS.TBL 2018-05-04 2.8K  
    04:55
    [26][DIR] [27]images/ 2018-05-04 -  
    04:44
    [28][DIR] [29]isolinux/ 2018-05-04 -  
    04:34
    [30][DIR] [31]repodata/ 2018-05-04 -  
    04:54
    ----------------------------------------------------------------------------

    2、编译安装http2.4,实现可以正常访问,并将编译步骤和结果提交。

    [23:47:40 root@lucklyzpp8 ~]#wget 'https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.48.tar.bz2'
    [23:47:40 root@lucklyzpp8 ~]#tar -xvf httpd-2.4.48.tar.bz2 
    [23:47:40 root@lucklyzpp8 ~]#ls
    anaconda-ks.cfg  cmatrix  httpd-2.4.48  httpd-2.4.48.tar.bz2  webmin-1.981
    [23:48:28 root@lucklyzpp8 ~]#cd httpd-2.4.48/
    [23:48:32 root@lucklyzpp8 httpd-2.4.48]#ls
    ABOUT_APACHE     BuildAll.dsp     configure     httpd.spec      libhttpd.mak   os                srclib
    acinclude.m4     BuildBin.dsp     configure.in  include         LICENSE        README            support
    Apache-apr2.dsw  buildconf        docs          INSTALL         Makefile.in    README.CHANGES    test
    Apache.dsw       CHANGES          emacs-style   InstallBin.dsp  Makefile.win   README.cmake      VERSIONING
    apache_probes.d  changes-entries  httpd.dep     LAYOUT          modules        README.platforms
    ap.d             CMakeLists.txt   httpd.dsp     libhttpd.dep    NOTICE         ROADMAP
    build            config.layout    httpd.mak     libhttpd.dsp    NWGNUmakefile  server
    [23:48:32 root@lucklyzpp8 httpd-2.4.48]#./configure --prefix=/apps/httpd24 --sysconfdir=/etc/httpd24 --enable-ssl
    [23:56:54 root@lucklyzpp8 httpd-2.4.48]#make  && make install
    23:56:54 root@lucklyzpp8 httpd-2.4.48]#echo 'PATH=/apps/httpd24/bin:$PATH' > /etc/profile.d/httpd24.sh
    [23:59:59 root@lucklyzpp8 httpd-2.4.48]#. /etc/profile.d/httpd.sh 
    [00:02:03 root@lucklyzpp8 httpd-2.4.48]#useradd -r -s /sbin/nologin -d /var/www -c Apache -u 58 apache2
    [00:02:30 root@lucklyzpp8 httpd-2.4.48]#id apache2 
    uid=58(apache2) gid=58(apache2) 组=58(apache2)
    [00:02:39 root@lucklyzpp8 httpd-2.4.48]#vim /etc/httpd24/httpd.conf 
    [00:03:43 root@lucklyzpp8 httpd-2.4.48]#apachectl 
    AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::30e1:66e5:d982:6200. Set the 'ServerName' directive globally to suppress this message
    httpd (pid 1152) already running
    [00:04:51 root@lucklyzpp8 httpd-2.4.48]#ps aux | grep httpd
    root       30985  0.1  1.5 281472 11376 ?        Ss   9月13   0:02 /usr/sbin/httpd -DFOREGROUND
    apache     30986  0.0  1.1 294208  8440 ?        S    9月13   0:00 /usr/sbin/httpd -DFOREGROUND
    apache     30987  0.0  2.0 1483000 14352 ?       Sl   9月13   0:01 /usr/sbin/httpd -DFOREGROUND
    apache     31007  0.0  1.4 1352000 10380 ?       Sl   9月13   0:01 /usr/sbin/httpd -DFOREGROUND
    apache     31039  0.0  1.4 1352000 10376 ?       Sl   9月13   0:01 /usr/sbin/httpd -DFOREGROUND
    apache     31204  0.0  1.6 1352000 12104 ?       Sl   9月13   0:01 /usr/sbin/httpd -DFOREGROUND
    root       57781  0.0  0.1 221924  1136 pts/0    S+   00:05   0:00 grep --color=auto httpd

    3、利用sed 取出ifconfig命令中本机的IPv4地址

    [22:33:37 root@lucklyzpp8 ~]#ifconfig|sed -rn '2s/^[^0-9]+([0-9.]+) .*$/1/p'
    192.168.33.131


    4、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符

    [22:39:05 root@lucklyzpp8 ~]#sed -ri.bak '/^#s+/s/^#s+//' /data/fstab 
    [22:40:17 root@lucklyzpp8 ~]#cat /data/fstab
    
    #
    /etc/fstab
    Created by anaconda on Sat Aug 28 16:16:41 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.
    #
    After editing this file, run 'systemctl daemon-reload' to update systemd
    units generated from this file.
    #
    /dev/mapper/cl-root     /                       xfs     defaults        0 0
    UUID=33947e41-cdf9-43a5-958a-27ef955fe7f6 /boot                   ext4    defaults        1 2
    /dev/mapper/cl-home     /home                   xfs     defaults        0 0
    /dev/mapper/cl-swap     swap                    swap    defaults        0 0


    5、处理/etc/fstab路径,使用sed命令取出其目录名和基名

    [22:40:24 root@lucklyzpp8 ~]#echo /etc/fstab|sed -r 's@^(/.*/)(.*)@path:1 basename:2@'
    path:/etc/ basename:fstab


    6、列出ubuntu软件管理工具apt的一些用法(自由总结)

     dpkg 包管理器

    帮助参看:man dpkg
    dpkg 常见用法
    #安装包
    dpkg -i package.deb
    #删除包,不建议,不自动卸载依赖于它的包
    dpkg -r package
    #删除包(包括配置文件)
    dpkg -P package
    #列出当前已安装的包,类似rpm -qa
    dpkg -l
    #显示该包的简要说明
    dpkg -l package
    #列出该包的状态,包括详细信息,类似rpm –qi
    dpkg -s package
    #列出该包中所包含的文件,类似rpm –ql
    dpkg -L package
    #搜索包含pattern的包,类似rpm –qf
    dpkg -S <pattern>
    #配置包,-a 使用,配置所有没有配置的软件包
    dpkg --configure package
    #列出 deb 包的内容,类似rpm –qpl
    dpkg -c package.deb

    #解开 deb 包的内容
    dpkg --unpack package.deb

    [16:34:55 root@ubuntu1804 ~]#dpkg -l |head -n2
    Desired=Unknown/Install/Remove/Purge/Hold
    | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
    [16:35:03 root@ubuntu1804 ~]#dpkg -L bash|head -2
    /.
    /bin
    [16:35:36 root@ubuntu1804 ~]#dpkg -S /bin/bash 
    bash: /bin/bash

    2 apt
    apt 特有的命令
    apt list 列出包含条件的包(已安装,可升级等)
    apt edit-sources 编辑源列表
    APT包索引配置文件
    /etc/apt/sources.list
    /etc/apt/sources.list.d
    apt命令操作(如安装和删除软件包)日志文件
    /var/log/dpkg.log

    #安装包:
    apt install tree zip
    #安装图形桌面
    apt install ubuntu-desktop
    #删除包:
    apt remove tree zip
    #说明:apt remove中添加--purge选项会删除包配置文件,谨慎使用
    #更新包索引,相当于yum clean all;yum makecache
    apt update  
    #升级包:要升级系统,请首先更新软件包索引,再升级
    apt upgrade
    #apt列出仓库软件包,等于yum list
    apt list
    #搜索安装包
    apt search nginx
    #查看某个安装包的详细信息
    apt show apache2
    #在线安装软件包
    apt install apache2
    #卸载单个软件包但是保留配置⽂件
    apt remove apache2
    #删除安装包并解决依赖关系
    apt autoremove apache2
    #更新本地软件包列表索引,修改了apt仓库后必须执⾏
    apt update 
    #编辑source源⽂件
    apt edit-sources

    #查看仓库中软件包有哪些版本可以安装
    apt-cache madison nginx
    #安装软件包的时候指定安装具体的版本
    apt install nginx=1.14.0-0ubuntu1.6
    #查看文件来自于哪个包,类似redhat中的yum provides <filename>
    apt-file search 'string' #默认是包含此字符串的文件
    apt-file search -x '正则表达式'
    apt-file search -F /path/file

    ubuntu建议安装的常用包
    [root@ubuntu1804 ~]#apt purge ufw lxd lxd-client lxcfs liblxc-common
    [root@ubuntu1804 ~]#apt install iproute2 ntpdate tcpdump telnet traceroute nfskernel-server nfs-common lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev gcc openssh-server iotop unzip zip

  • 相关阅读:
    @bzoj
    @bzoj
    @codeforces
    @codeforces
    @bzoj
    @codeforces
    @codeforces
    @codeforces
    @NOIP2018
    反转字符串--C和Python
  • 原文地址:https://www.cnblogs.com/zpkf/p/15270088.html
Copyright © 2020-2023  润新知