1、自建yum仓库,分别为网络源和本地源
网络源yum仓库:
Linux版本:Centos7
网络yum源:阿里云
[root@centos7 ~]#vim /etc/yum.repo.d/network.repo
[base]
name=Centos7-base-aliyun
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[epel]
name=Centos7-epel-aliyun
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
enabled=1
gpgcheck=0
本地源yum仓库:
Linux版本:Centos7
本地yum源:Centos7自带光盘
(虚拟机挂载Centos7光盘)
①将光盘挂载到指定的地方
方法一:
(每次开机后手动挂载)
[root@centos7 ~]#mkdir /mnt/cdrom -p
[root@centos7 ~]#mount sr0 /mnt/cdrom
方法二:
(每次开机后自动挂载)
[root@centos7 ~]#mkdir /mnt/cdrom -p
[root@centos7 ~]#blkid | tail -1 >> /etc/fstab
[root@centos7 ~]#vim /etc/fstab
(修改最后一行)
UUID=2b4978b9-1ea5-4268-bc10-f31625276cbf / xfs defaults 0 0
UUID=1bedf075-96fd-4c0f-a85b-da83e5a0ce3e /boot xfs defaults 0 0
UUID=85ac2fe0-8a18-42ad-b8b9-e56bfe3f4dd7 /data xfs defaults 0 0
UUID=5ad244b3-ca40-4868-ba49-5e55a50b228e swap swap defaults 0 0
UUID=2017-09-06-10-51-00-00 /mnt/cdrom iso9660 auto 0 0 (这里是最后一行)
[root@centos7 ~]#mount -a
②编辑repo文件
[root@centos7 ~]#vim /etc/yum.repo.d/local.repo
[base]
name=Centos7-cdrom
baseurl=file:///mnt/cdrom
gpgcheck=0
enabled=1
③保存退出
2、编译安装http2.4,实现可以正常访问,并将编译步骤和结果提交。
编译安装httpd-2.4准备
#安装相关包:
[root@centos7 ~]#yum -y install gcc make pcre-devel openssl-devel expat-devel
#下载源代码并解压缩:
[root@centos7 ~]#wget https://downloads.apache.org//apr/apr-1.7.0.tar.bz2
[root@centos7 ~]#wget https://downloads.apache.org//apr/apr-util-1.6.1.tar.bz2
[root@centos7 ~]#wget https://downloads.apache.org//httpd/httpd-2.4.46.tar.bz2
[root@centos7 ~]#ls
httpd-2.4.46.tar.bz2,apr-1.7.0.tar.bz2,apr-util-1.6.1.tar.bz2
[root@centos7 ~]#tar xvf apr-1.7.0.tar.bz2
[root@centos7 ~]#tar xvf apr-util-1.6.1.tar.bz2
[root@centos7 ~]#tar xvf httpd-2.4.46.tar.bz2
#编译安装apr
[root@centos7 ~]#cd apr-1.7.0
[root@centos7 ~]#./configure --prefix=/apps/apr
(这里会出现rm: cannot remove ‘libtoolT‘: No such file or directory的问题)
(解决思路:1.手动建一个libtoolT文件 2.注释此行 vim configure # $RM "$cfgfile")
[root@centos7 ~]#make && make install
#编译安装apr-util
[root@centos7 ~]#cd ../apr-util-1.6.1
[root@centos7 ~]#./configure --prefix=/apps/apr-util --with-apr=/apps/apr/
[root@centos7 ~]#make && make install
#编译安装 httpd-2.4
[root@centos7 ~]#cd ../httpd-2.4.46
[root@centos7 ~]#./configure --prefix=/apps/httpd24
--enable-so
--enable-ssl
--enable-cgi
--enable-rewrite
--with-zlib
--with-pcre
--with-apr=/apps/apr/
--with-apr-util=/apps/apr-util/
--enable-modules=most
--enable-mpms-shared=all
--with-mpm=prefork
[root@centos7 ~]#make && make install
#创建专用用户
[root@centos7 ~]#useradd -s /sbin/nologin -r apache
#指定运行httpd的用户
[root@centos7 ~]#vim /apps/httpd24/conf/httpd.conf
user apache
group apache
#配置环境变量
[root@centos7 ~]#vim /etc/profile.d/httpd.sh
PATH=/apps/httpd24/bin:$PATH
#创建service unit文件(CentOS 7 以上版本)
[root@centos7 ~]#vim /usr/lib/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)
[Service]
Type=forking
#EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/apps/httpd24/bin/apachectl start
#ExecStart=/apps/httpd24/bin/httpd $OPTIONS -k start
ExecReload=/apps/httpd24/bin/apachectl graceful
#ExecReload=/apps/httpd24/bin/httpd $OPTIONS -k graceful
ExecStop=/apps/httpd24/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#开启httpd
[root@centos7 ~]#systemctl start httpd
#查看结果
apache 46584 46583 0 22:16 ? 00:00:00 /apps/httpd24/bin/httpd -k start
apache 46585 46583 0 22:16 ? 00:00:00 /apps/httpd24/bin/httpd -k start
apache 46586 46583 0 22:16 ? 00:00:00 /apps/httpd24/bin/httpd -k start
apache 46587 46583 0 22:16 ? 00:00:00 /apps/httpd24/bin/httpd -k start
apache 46588 46583 0 22:16 ? 00:00:00 /apps/httpd24/bin/httpd -k start
apache 46591 46583 0 22:18 ? 00:00:00 /apps/httpd24/bin/httpd -k start
#浏览器访问本机地址,出现It works!
3、利用sed 取出ifconfig命令中本机的IPv4地址
[root@centos7 ~]#ifconfig eth0 | sed -n 's/inet //p' | sed -n 's/netmask.*//p'
[root@centos7 ~]#ifconfig eth0 | sed -n 's/inet //;s/netmask.*//p'
4、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
[root@centos7 ~]#sed -r 's/^#[[:space:]]+(.*)/\1/g' /etc/fstab
5、处理/etc/fstab路径,使用sed命令取出其目录名和基名
目录名:
[root@centos7 ~]# echo /etc/fstab | sed -nr 's@^(/.*)/([^/]+)/?@\1@p'
基名
[root@centos7 ~]# echo /etc/fstab | sed -nr 's@^(/.*)/([^/]+)/?$@\2@p'