httpd编译安装及sed工具

软件安装及sed工具

一、软件安装

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

​ 1.1.1 本地源设置:

为虚拟机加载ISO文件
httpd编译安装及sed工具
httpd编译安装及sed工具

# lsblk   #查看光盘设备/dev/sr0
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  120G  0 disk
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0    2G  0 part [SWAP]
└─sda3   8:3    0  117G  0 part /
sdb      8:16   0   20G  0 disk
├─sdb1   8:17   0    2G  0 part /data/da2
├─sdb2   8:18   0    1G  0 part
└─sdb3   8:19   0    1G  0 part
sr0     11:0    1  9.6G  0 rom
# mount /dev/sr0 /mnt     #挂载光盘到/mnt
mount: /dev/sr0 is write-protected, mounting read-only
# cd /etc/yum.repos.d/
# vim CentOS-Base.repo
[CentOS-Base.repo]
name=CentOS-Base
baseurl=file:///mnt
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
CentOS-Base.repo                                                                                                             | 3.6 kB  00:00:00
(1/2): CentOS-Base.repo/group_gz                                                                                             | 153 kB  00:00:00
(2/2): CentOS-Base.repo/primary_db                                                                                           | 6.1 MB  00:00:00
repo id                                                                  repo name                                                            status
CentOS-Base.repo                                                         CentOS-Base                                                          10,070
repolist: 10,070
[root@localhost yum.repos.d]#

# yum install autofs  #安装autofs软件实现光盘自动挂载
# systemctl enable --now autofs
# vim  /etc/yum.repos.d/CentOS-Base.repo
[CentOS-Base.repo]
name=CentOS-Base
baseurl=file:///misc/cd
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

1.1.2 aliyun源设置

访问网址 https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.3e221b11p84Dq9 ,按照网站中说明运行:

​ 注:更改原说明中CentOS-Base.repo为CentOS-Base.aliyun.repo,以免文件覆盖

# wget -O /etc/yum.repos.d/CentOS-Base.aliyun.repo https://mirrors.aliyun.com/repo/Centos-7.repo
--2020-12-29 10:46:09--  https://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 42.7.48.238, 42.7.48.239, 42.7.48.248, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|42.7.48.238|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.aliyun.repo’

100%[==========================================================================================================>] 2,523       --.-K/s   in 0s

2020-12-29 10:46:09 (152 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.aliyun.repo’ saved [2523/2523]

# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
CentOS-Base.repo                                                                                                                            | 3.6 kB  00:00:00
base                                                                                                                                        | 3.6 kB  00:00:00
extras                                                                                                                                      | 2.9 kB  00:00:00
updates                                                                                                                                     | 2.9 kB  00:00:00
repo id                                                            repo name                                                                                 status
CentOS-Base.repo                                                   CentOS-Base                                                                               10,070
base/7/x86_64                                                      CentOS-7 - Base - mirrors.aliyun.com                                                      10,072
extras/7/x86_64                                                    CentOS-7 - Extras - mirrors.aliyun.com                                                       448
updates/7/x86_64                                                   CentOS-7 - Updates - mirrors.aliyun.com                                                    1,155
repolist: 21,745

增加EPEL源

# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
--2020-12-29 10:51:46--  http://mirrors.aliyun.com/repo/epel-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 42.7.48.242, 42.7.48.241, 42.7.48.243, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|42.7.48.242|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 664 [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/epel.repo’

100%[=========================================================================================================================>] 664         --.-K/s   in 0s

2020-12-29 10:51:47 (44.5 MB/s) - ‘/etc/yum.repos.d/epel.repo’ saved [664/664]

# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
epel                                                                                                                                        | 4.7 kB  00:00:00
(1/2): epel/x86_64/primary_db                                                                                                               | 6.9 MB  00:00:04
(2/2): epel/x86_64/updateinfo                                                                                                               | 1.0 MB  00:00:15
repo id                                                        repo name                                                                        status
CentOS-Base.repo                                             CentOS-Base                                                                       10,070
base/7/x86_64                                                CentOS-7 - Base - mirrors.aliyun.com                                             10,072
epel/x86_64                                          Extra Packages for Enterprise Linux 7 - x86_64                                           13,501
extras/7/x86_64                                       CentOS-7 - Extras - mirrors.aliyun.com                                                    448
updates/7/x86_64                                     CentOS-7 - Updates - mirrors.aliyun.com                                                    1,155
repolist: 35,246

1.2 编译安装http2.4,实现可以正常访问

访问网站http://httpd.apache.org/ ,下载httpd-2.4.46.tar.bz2压缩文件,并上传服务器。按INSTLL文件中说明,在http://apr.apache.org/ 网站下载apr与apr-util

# mkdir -p  /usr/src/httpd
# mkdir -p /app/httpd244
# mv  apr-1.7.0/* /usr/src/httpd/httpd-2.4.46/srclib/apr
# mv apr-util-1.6.1/* /usr/src/httpd/httpd-2.4.46/srclib/apr-util/
# cd  /usr/src/httpd
# tar xvf httpd-2.4.46.tar.bz2
# cd /usr/src/httpd/httpd-2.4.46

安装编译时使用到的软件

# yum -y install gcc make pcre-devel openssl-devel expat-devel

编译并安装

# cd /usr/src/httpd/httpd-2.4.46
# ./configure
# make && make install

后续设置

# setenforce 0
# vim /etc/sysconfig/selinux
SELINUX=disabled    #关闭Selinux

# systemctl stop firewalld.service   #关闭iptables

# vim  /etc/profile.d/httpd.sh  # 设置apachectl路径及自动启动httpd
PATH=$PATH:/app/httpd244/bin
export PATH
/app/httpd244/bin/apachectl restart

# vim /etc/man_db.conf  #设置man帮助路径
MANDATORY_MANPATH           /app/httpd244/man

# vim /app/httpd244/conf/httpd.conf  #更改httpd启动用户、用户组
User apache
Group apache

二、sed工具应用举例

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

# ifconfig|sed -n '2p'|sed -r 's/(^[^0-9]+)([0-9.]+)(.*)/\2/'

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

# sed -r 's/^#[[:space:]]+//' fstab

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

# echo /etc/fstab | sed -r 's/(^\/.*\/)(.*)/\1/'  #取出目录名
# echo /etc/fstab | sed -r 's/(^\/.*\/)(.*)/\2/'  #取出基名

猜你喜欢

转载自blog.51cto.com/12302225/2576812