第四周作業(yè)

1、自建yum倉庫,分別為網(wǎng)絡(luò)源和本地源

自建YUM倉庫

 1012  cd /var/www/html/centos8/AppStream/
 1013  ls
 1014  cd Packages/
 1015  ls
 1016  find . -name *http*
 1017  find . -name "*http*"
 #拷貝軟件包,沒具體查列表和依賴,只是把關(guān)聯(lián)的http、apr、lib全搜索復(fù)制了
 1018  mkdir /data/testrepo;find . -name "*http*" -exec cp -r -p {} /data/testrepo \;
 1042  find . -name "apr*" -exec cp -r -p {} /data/testrepo \;
 1050  find /mnt/hgfs/AppStream/ -name "lib*" -exec cp -r -p {} /data/testrepo \;
 #生成repodata數(shù)據(jù)
 1023  yum -y install createrepo
 1024  createrepo .
 #配置軟鏈接提供http服務(wù)
 1025  ln -s /data/testrepo /var/www/html/centos8/testrepo

yum客戶端使用自建倉庫安裝httpd(只自建了AppStream,BaseOS使用的光驅(qū)掛載的):

[root@localhost ~]# vim /etc/yum.repos.d/yumfiles.repo 
[AppStream]
name=AppStream
#baseurl=file:///opt/rhel8/AppStream
#baseurl=http://192.168.1.200/centos8/AppStream
baseurl=http://192.168.1.200/centos8/testrepo
gpgcheck=0
enabled=1

[BaseOS]
name=BaseOS
#baseurl=file:///opt/rhel8/BaseOS
baseurl=http://192.168.1.200/centos8/BaseOS
gpgcheck=0
enabled=1
[root@localhost ~]# yum -y install httpd
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
AppStream                                                                                              1.1 MB/s | 3.0 kB     00:00    
BaseOS                                                                                                 1.5 MB/s | 3.9 kB     00:00    
Dependencies resolved.
                                                    <--ommited-->
                                                         ...
Installed products updated.

Installed:
  httpd-2.4.37-39.module_el8.4.0+778+c970deab.x86_64              apr-util-bdb-1.6.1-6.el8.x86_64                                     
  apr-util-openssl-1.6.1-6.el8.x86_64                             apr-1.6.3-11.el8.x86_64                                             
  apr-util-1.6.1-6.el8.x86_64                                     httpd-filesystem-2.4.37-39.module_el8.4.0+778+c970deab.noarch       
  httpd-tools-2.4.37-39.module_el8.4.0+778+c970deab.x86_64        mod_http2-1.15.7-3.module_el8.4.0+778+c970deab.x86_64               
  centos-logos-httpd-85.5-1.el8.noarch                           

Complete!
[root@localhost ~]# 

配置本地源,將linux安裝光盤內(nèi)的yum文件保存到本地目錄下:

[root@localhost ~]# cat /etc/yum.repos.d/yumfiles.repo
[AppStream]
name=AppStream
baseurl=file:///opt/rhel8/AppStream
gpgcheck=0
enable=1

[BaseOS]
name=BaseOS
baseurl=file:///opt/rhel8/BaseOS
gpgcheck=0
enable=1
[root@localhost ~]# yum repolist
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:00:31 ago on Tue 21 Sep 2021 12:42:36 AM PDT.
repo id                                                         repo name                                                        status
AppStream                                                       AppStream                                                        4,820
BaseOS                                                          BaseOS                                                           1,661
[root@localhost ~]# 

配置網(wǎng)絡(luò)源

Centos8掛載光驅(qū),安裝httpd軟件包,創(chuàng)建軟鏈接將光驅(qū)下AppStream和BaseOS鏈接到/var/www/html/centos8目錄下:

[root@cenos8 html]# ln -s /mnt/hgfs/AppStream /var/www/html/centos8/AppStream
[root@cenos8 html]# ls centos8/
AppStream
[root@cenos8 html]# ln -s /mnt/hgfs/BaseOS /var/www/html/centos8/BaseOS
[root@cenos8 html]# cd centos8/
[root@cenos8 centos8]# ls
AppStream  BaseOS

其他主機(jī)可以直接通過http訪問這個(gè)地址:

[root@localhost yum.repos.d]# vim yumfiles.repo 
[AppStream]
name=AppStream
#baseurl=file:///opt/rhel8/AppStream
baseurl=http://192.168.1.200/centos8/AppStream
gpgcheck=0
enabled=1

[BaseOS]
name=BaseOS
#baseurl=file:///opt/rhel8/BaseOS
baseurl=http://192.168.1.200/centos8/BaseOS
gpgcheck=0
enabled=1
[root@localhost yum.repos.d]# yum repolist
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:00:33 ago on Tue 21 Sep 2021 12:45:13 AM PDT.
repo id                                                         repo name                                                        status
AppStream                                                       AppStream                                                        5,150
BaseOS                                                          BaseOS                                                           1,708
[root@localhost yum.repos.d]# 

image.png

2、編譯安裝http2.4,實(shí)現(xiàn)可以正常訪問,并將編譯步驟和結(jié)果提交。

  1. rpm -qi httpd,查看軟件包信息,找到apache官網(wǎng)鏈接:
  1. wget https://dlcdn.apache.org//httpd/httpd-2.4.49.tar.bz2,從官網(wǎng)下載2.4版本的tar.bz2壓縮包

  2. tar -xf httpd-2.4.49.tar.bz2 -C /usr/local/src,壓縮包解壓到/usr/local/src目錄

  3. 安裝編譯相關(guān)的依賴的軟件包:

  • yum -y install gcc make autoconf apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config
  1. 查看INSTALL文件,確認(rèn)應(yīng)該如何執(zhí)行configure,或者直接執(zhí)行./configure --help確認(rèn)

  2. ./configure --prefix=/opt/httpd --sysconfdir=/opt --enable-ssl

  • --prefix,指定安裝目錄

  • --sysconfdir,指定配置文件安裝目錄

  • --enable-ssl,啟用https支持

  1. make -j 4 && make install,編譯并安裝

  2. 失敗,提示缺少bison,yum provides bison可以看到應(yīng)該安裝哪個(gè)軟件包

  3. 失敗,缺少flex,同樣方式查看并安裝

  4. echo $?輸出為0,成功

  5. 在PATH變量前面添加httpd的目錄,同時(shí)執(zhí)行該腳本讓變量立即生效:

  • echo 'PATH=/opt/httpd/bin:$PATH' > /etc/profile.d/httpd.sh

  • . /etc/profile.d/httpd.sh

  • 確認(rèn)變量修改成功:

[root@cenos8 ~]# echo $PATH
/opt/httpd/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
  1. 執(zhí)行apachectl start彈出錯(cuò)誤提示,需要設(shè)置ServerName,進(jìn)入在--sysconfdir中指定的配置文件,修改ServerName項(xiàng),重啟apache;

最終結(jié)果,從其他主機(jī)也可以訪問

image.png

3、利用sed 取出ifconfig命令中本機(jī)的IPv4地址

[root@cenos8 ~]# ifconfig | sed -n '/ens33/,/inet/p' | sed -r -n '/2/s@(^[[:space:]]+inet[[:space:]]+)([[:digit:].]+)(.*$)@\2@p' | cat -A
192.168.1.200$
[mxx@Ubuntu01:~$]ifconfig | sed -n '/ens33/,/inet/p' | sed -r -n '/2/s@(^[[:space:]]+inet[[:space:]]+)([[:digit:].]+)(.*$)@\2@p' | cat -A
192.168.1.100$

4、刪除/etc/fstab文件中所有以#開頭,后面至少跟一個(gè)空白字符的行的行首的#和空白字符

改成-ri則直接修改文件內(nèi)容:

[mxx@Ubuntu01:~$]cat /etc/fstab | sed -r 's/(^#[[:space:]]+)//' | cat -A
/etc/fstab: static file system information.$
#$
Use 'blkid' to print the universally unique identifier for a$
device; this may be used with UUID= as a more robust way to name devices$
that works even if disks are added and removed. See fstab(5).$
#$
<file system> <mount point>   <type>  <options>       <dump>  <pass>$
/ was on /dev/sda2 during curtin installation$
/dev/disk/by-uuid/81ae8282-7d2f-4b0f-9c42-b381c51dd581 / xfs defaults 0 0$
/boot was on /dev/sda3 during curtin installation$
/dev/disk/by-uuid/e5361f38-c31b-42c5-88e0-bad5ec373758 /boot ext4 defaults 0 0$
/dev/disk/by-uuid/7249852c-c9e9-47f6-a9a1-577f87e6651e none swap sw 0 0$
/data was on /dev/sda5 during curtin installation$
/dev/disk/by-uuid/757532f5-1774-4ed6-8c5a-903229115663 /data xfs defaults 0 0$
/swap.img^Inone^Iswap^Isw^I0^I0$
[root@cenos8 yum.repos.d]# cat /etc/fstab | sed -r 's/(^#[[:space:]]+)//' | cat -A
$
#$
/etc/fstab$
Created by anaconda on Sun Aug 22 12:58:50 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.$
#$
UUID=b6913f81-757b-4253-b8ae-25445dc0d41f /                       xfs     defaults        0 0$
UUID=5372c2a0-9b40-473a-9199-0357f545d8d4 /boot                   ext4    defaults        1 2$
UUID=8d8546c1-f22b-43c6-9e28-1e8cc8dfd934 /data                   xfs     defaults        0 0$
UUID=3d13c06c-3888-4a33-93c5-c5251b2073f8 none                    swap    defaults        0 0$

5、處理/etc/fstab路徑,使用sed命令取出其目錄名和基名

[root@cenos8 yum.repos.d]# echo "/etc/fstab" | sed -n -r 'h;s/^(\/\w+\/)(\w+)/\1/p;g;s//\2/p'
/etc/
fstab
[mxx@Ubuntu01:~$]echo "/etc/fstab" | sed -n -r 'h;s/^(\/\w+\/)(\w+)/\1/p;g;s//\2/p'
/etc/
fstab

6、列出ubuntu軟件管理工具apt的一些用法(自由總結(jié))

任務(wù) Ubuntu
基本信息
軟件包后綴 *.deb
軟件源配置文件 /etc/apt/sources.list
安裝、刪除、升級(jí)軟件包
更新軟件包列表 apt-get update
apt update
從軟件倉庫軟件安裝軟件 apt-get install package
安裝一個(gè)已下載的軟件包 dpkg -i pkg.debpkg --install pkg.deb
刪除軟件包 apt-get remove package
軟件包升級(jí)檢查/測(cè)試 apt-get -s upgradeapt-get -s dist-upgrade
升級(jí)軟件包 apt-get upgrade
升級(jí)整個(gè)系統(tǒng) apt-get dist-upgrade
軟件包信息
獲取某軟件包的信息 apt-cache show package
檢查軟件包的可用版本和依賴 apt-cache showpkg my_pkg
獲取所有軟件包的信息 apt-cache dumpavail
顯示所有已安裝的軟件 dpkg -ldpkg --list
apt list --installed
顯示可安裝的模塊 apt list
顯示可安裝的包組
獲取某個(gè)已安裝軟件包的信息 dpkg --status package
列出某個(gè)已安裝軟件包所包含的文檔
列出所有已安裝的軟件 dpkg -l
grep -v是反轉(zhuǎn)標(biāo)記,反向匹配,類似exclude
dpkg --get-selections | grep -v deinstall
dpkg --get-selections | grep -v install--匹配未安裝
apt list --installed | grep ssh
列出某個(gè)已安裝軟件包所包含的文件列表 dpkg -S package-name
sudo dpkg -L 軟件名稱--顯示安裝路徑
列出某個(gè)已安裝軟件包所包含的配置文件 無apt命令
顯示某個(gè)軟件包所依賴的軟件包列表 apt-cache depends package
顯示某個(gè)軟件包的反向依賴關(guān)系 apt-cache rdepends package
軟件包文件信息
獲取某個(gè)軟件包文件的信息 dpkg --info pkg.deb
獲取某個(gè)軟件包文件所包含的文件列表 dpkg --contents pkg.deb
獲取某個(gè)軟件包文件所包含的文檔 無apt命令
獲取某個(gè)軟件包文件所包含的配置文件 無apt命令
軟件包解壓 dpkg-deb --extract pkg.deb
搜索某個(gè)文件是由哪個(gè)軟件包安裝的 dpkg -S /file/name
dpkg --search /file/name
搜索所有提供某個(gè)文件的軟件包 apt-file search /file/name
apt search file-name
需安裝apt-file軟件包
雜項(xiàng)
顯示本地軟件包緩存的狀態(tài) apt-cache stats
校驗(yàn)所有已安裝的軟件包 debsums
刪除本地緩存的所有軟件包 apt-get clean
僅刪除本地緩存中過時(shí)的軟件包 apt-get autoclean
刪除所有軟件包信息 apt-file purge
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容