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




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