Linux學習-第六週

1、自建yum倉庫,分別爲網絡源和本地源

(1) 自建基於局域網的私有yum源
1) 倉庫服務器配置
[root@repo-server ~]#yum -y install httpd createrepo
[root@repo-server ~]#systemctl enable --now httpd
2) yum客戶端配置
[root@repo-client yum.repos.d]#vim base.repo
[base]
name=base
baseurl= http://10.0.0.205/centos/7/base/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[extra]
name=extra
baseurl=http://10.0.0.205/centos/extra/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[updates]
name=updates
baseurl=http://10.0.0.205/centos/updates/
enabled=1
gpgcheck=0
3) 下載阿里雲或者華爲雲的base、extras、updates源,製作私有yum源
首先需要保證倉庫服務器上的yum源正常,能正常訪問阿里雲或者華爲雲倉庫
[root@repo-server ~]#yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile


























  • base:
  • epel: mirrors.huaweicloud.com
  • extra: mirrors.huaweicloud.com
  • updates: mirrors.huaweicloud.com
    repo id repo name status
    base/7/x86_64 base 4,071
    epel/7/x86_64 epel 13,490
    extra/7/x86_64 extra 448
    updates/7/x86_64 updates 1,155
    repolist: 19,164





    下載base、extras、updates源
    [root@repo-server ~]reposync --repoid=base --download-metadata -p /var/www/html/centos/7
    [root@repo-server ~]reposync --repoid=extra --download-metadata -p /var/www/html/centos/
    [root@repo-server ~]reposync --repoid=updates --download-metadata -p /var/www/html/centos/


    創建元數據
    [root@repo-server ~]createrepo /var/www/html/centos/7/base
    [root@repo-server ~]createrepo /var/www/html/centos/extra
    [root@repo-server ~]createrepo /var/www/html/centos/updates


    4) yum客戶端更新yum源
    [root@repo-client ~]#yum clean all
    [root@repo-client ~]#yum repolist
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    repo id repo name status
    base base 4,071
    extra extra 448
    updates updates 778
    repolist: 5,297








(2) 自建本地私有yum源 (使用系統光盤的掛載作爲本地yum源)
[root@repo-client ~]#mount /dev/sr0 /mnt
修改yum源配置文件
[root@repo-client ~]#cat /etc/yum.repos.d/base.repo
[base]
name=base
baseurl=file:///mnt/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
更新本地yum源
[root@repo-client ~]#yum clean all
[root@repo-client ~]#yum repolist
Loaded plugins: fastestmirror
repo id repo name status
base base 4,071
repolist: 4,071















2、編譯安裝http2.4,實現可以正常訪問,並將編譯步驟和結果提交。

(0) 安裝前準備:關閉防火牆和SELinux
(1) 安裝包
[root@centos8 ~]#dnf install gcc make apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config
(2) 下載並解壓縮包
[root@centos8 ~]#tar xvf httpd-2.4.46.tar.bz2 -C /usr/local/src
(3) 配置
[root@centos8 ~]#cd /usr/local/src/httpd-2.4.46/
[root@centos8 httpd-2.4.46]#./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd --enable-ssl
(4) 編譯並安裝
[root@centos8 httpd-2.4.46]#make -j 2 && make install        (make -j 2 的意思是兩個cpu核同時執行make命令,具體應該寫幾個核,需要根據lscpu看到的結果,有幾個核就寫幾個)
(5) 配置環境
[root@centos8 ~]#echo 'PATH=/apps/httpd/bin:$PATH' > /etc/profile.d/httpd.sh
[root@centos8 ~]#. /etc/profile.d/httpd.sh
(6) 運行
[root@centos8 ~]#apachectl
(7) 指定用apache用戶運行
[root@centos8 ~]#useradd -r -s /sbin/nologin -d /var/www -c Apache -u 48 apache
[root@centos8 ~]#vim /etc/httpd/httpd.conf
user apache
group apache
(8)生效和驗證
[root@centos8 ~]#apachectl restart
#查看
[root@centos8 ~]#ps aux

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

法1:ifconfig eth0|sed -En '2s#^([^0-9]+)([0-9.]+)( .)$#\2#p'
法2:ifconfig eth0|sed -En '2s#^[^0-9]+([0-9.]+) .
$#\1#p'

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

[root@repo-client ~]#sed -Ei.bak 's/^(#[[:blank:]]+)(.*)$/\2/' fstab
執行後結果:
[root@repo-client data]#cat fstab

#
/etc/fstab
Created by anaconda on Sun Nov 8 23:17:14 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
#
UUID=97c3dc2f-b9d3-4b1b-9553-f3ff27ec3094 / xfs defaults 0 0
UUID=eba488ff-d5ab-4fe7-8885-27947c7d1e01 /boot xfs defaults 0 0
UUID=85a59201-e34c-46f6-8598-d418dadd9254 /data xfs defaults 0 0
UUID=5796fdaf-ddbe-4c54-abeb-8f0e79ec0840 swap swap defaults 0









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

取目錄名
[root@repo-client data]#echo "/etc/fstab" |sed -En 's#^(/./).$#\1#p'
/etc/
取基名
[root@repo-client network-scripts]#echo "/etc/fstab" |sed -En 's#^(/./)(.)$#\2#p'
fstab




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章