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,實現(xiàn)可以正常訪問输虱,并將編譯步驟和結果提交站刑。
編譯安裝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
(這里會出現(xiàn)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
#創(chuàng)建專用用戶
[root@centos7 ~]#useradd -s /sbin/nologin -r apache
#指定運行httpd的用戶
[root@centos7 ~]#vim /apps/httpd24/conf/httpd.conf
user apache
group apache
#配置環(huán)境變量
[root@centos7 ~]#vim /etc/profile.d/httpd.sh
PATH=/apps/httpd24/bin:$PATH
#創(chuàng)建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
#瀏覽器訪問本機地址,出現(xiàn)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'