美文网首页
编译安装http、sed的用法实例

编译安装http、sed的用法实例

作者: 沐熙一叶_Leaf | 来源:发表于2021-01-03 19:42 被阅读0次

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

    #CentOS8创建网络源
    [root@localhost ~]#vim ali_erpo.sh 
    #!/bin/bash
    mkdir /etc/yum.repos.d/backup
    mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
    cat > /etc/yum.repos.d/aliyun.repo <<EOF
    [AppStream]
    name=AppStream
    baseurl=https://mirrors.aliyun.com/centos/\$releasever/AppStream/\$basearch/os/
    gpgcheck=0
    
    [BaseOS]
    name=BaseOS
    baseurl=https://mirrors.aliyun.com/centos/\$releasever/BaseOS/\$basearch/os/
    gpgcheck=0
    
    [epel]
    name=EPEL
    baseurl=https://mirrors.aliyun.com/epel/\$releasever/Everything/\$basearch/
    gpgcheck=0
    
    EOF
    
    echo "创建成功!"
    
    #创建本地源
    [root@localhost ~]#Vim local_repo.sh 
    #!/bin/bash
    yum -y install autofs
    systemctl enable --now autofs
    lsblk |grep 'sr0'&& echo "光盘已插入"||( "光盘未插入请检查" && exit )
    mkdir -p  /mnt/cdroom
    mount -r /dev/cdrom /mnt/cdroom
    echo "/dev/cdrom /mnt/cdroom  挂载成功"
    cat > /etc/yum.repos.d/local.repo <<EOF
    [Appstream]
    name=AppStream
    baseurl=file:///mnt/cdroom/AppStream/
    gpgcheck=0
    
    [BaseOS]
    name=BaseOS
    baseurl=file:///mnt/cdroom/BaseOS/
    gpgcheck=0
    EOF
    
    echo "创建成功! "
    

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

    #1 关闭selinux 开启80端口
    [root@localhost ~]# setenforce = 0
    usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]
    #修改将“SELINUX=enforcing”更改为“SELINUX=disabled”,永久关闭SELINUX
    [root@localhost ~]# vim /etc/sysconfig/selinux   
    ...
    SELINUX=disabled
    ...
    #查看selinux状态
    [root@localhost ~]# getenforce
    Disabled
    [root@localhost ~]# firewall-cmd --add-port=80/tcp --permanent
    [root@localhost ~]# firewall-cmd --reload 
    #2 安装对应编译工具和依赖包
    [root@localhost ~]# yum -y install gcc make apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config
    #3 下载并解压压缩包
    [root@localhost ~]# tar xvf httpd-2.4.43.tar.gz -C /usr/local/src/
    #4 配置
    [root@localhost ~]# cd /usr/local/src/httpd-2.4.43/
    [root@localhost httpd-2.4.43]# ./configure --prefix=/apps/httpd24 --sysconfdir=/etc/httpd24 --enable-ssl 
    #5 编译安装
    [root@localhost httpd-2.4.43]# make && make install
    #6  配置环境
    [root@localhost httpd-2.4.43]# echo 'PATH=/apps/httpd24/bin:$PATH' > /etc/profile.d/httpd24.sh 
    [root@localhost httpd-2.4.43]# . /etc/profile.d/httpd24.sh 
    #7 指定用apache用户运行
    [root@localhost httpd-2.4.43]#useradd -r -s /sbin/nologin -d /var/www -c Apache -u 48 apache
    #8 修改配置文件
    [root@localhost httpd-2.4.43]#vim /etc/httpd24/httpd.conf
    ......
    167 User apache
    168 Group apache
    ......
    198 ServerName localhost:80
    ......
    #9  启动服务
    [root@localhost httpd-2.4.43]#apachectl restart
    #10 查看状态
    [root@localhost httpd-2.4.43]#ps aux
    apache    23551  0.0  0.4 392664  4404 ?        Sl   23:38   0:00 /apps/httpd24/bin/httpd
    apache    23552  0.0  0.4 392664  4404 ?        Sl   23:38   0:00 /apps/httpd24/bin/httpd
    apache    23553  0.0  0.4 392664  4404 ?        Sl   23:38   0:00 /apps/httpd24/bin/httpd
    #11 访问 10.0.0.202
    

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

    [root@localhost ~]#ifconfig ens160 |sed -nr "2s/[^0-9]+([0-9.]+).*/\1/p"
    10.0.0.201
    

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

    #查看文件源格式
    [root@localhost ~]#cat /etc/fstab 
    #
    # /etc/fstab
    # Created by anaconda on Wed Dec  9 04:33:52 2020
    #
    # 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=70489617-8843-487b-be19-4d0e4dbda82b /boot                   ext4    defaults        1 2
    /dev/mapper/cl-swap     swap                    swap    defaults        0 0
    #对文件#开头的空格进行删除
    [root@localhost ~]#sed -ri.bak '/^#[[:space:]]+/ s/^#[[:space:]]//' /etc/fstab
    #删除后
    [root@localhost ~]#cat /etc/fstab 
    
    #
    /etc/fstab
    Created by anaconda on Wed Dec  9 04:33:52 2020
    #
    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=70489617-8843-487b-be19-4d0e4dbda82b /boot                   ext4    defaults        1 2
    /dev/mapper/cl-swap     swap                    swap    defaults        0 0
    
    

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

    #取目录名
    [root@localhost ~]# echo /etc/fstab | sed -rn 's#(.*)/([^/]+)/?#\1#p'
    /etc
    
    #取基名
    [root@localhost ~]# echo /etc/fstab | sed -rn 's#(.*)/([^/]+)/?#\2#p'
    fstab
    
    

    相关文章

      网友评论

          本文标题:编译安装http、sed的用法实例

          本文链接:https://www.haomeiwen.com/subject/vblpoktx.html