1、自建yum仓库,分为网络源和本地源。
网络yum源
1、本地主机 10.0.0.162 安装httpd服务并启用(出于实验方便考虑,关闭防火墙及selinux服务);
2、虚拟机添加光驱并执行如下命令扫描识别:
alias scandisk='echo - - - >/sys/class/scsi_host/host0/scan;echo - - - >/sys/class/scsi_host/host1/scan;echo - - - > /sys/class/scsi_host/host2/scan'
[root@centos8 7]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 100G 0 part /
├─sda2 8:2 0 50G 0 part /data
├─sda3 8:3 0 2G 0 part [SWAP]
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 1G 0 part /boot
sr0 11:0 1 9.3G 0 rom /run/media/root/CentOS-8-4-2105-x86_64-dvd
sr1 11:1 1 9.5G 0 rom
3、在/var/www/html/ 目录下创建mkdir -p /var/www/html/centos/{7,8} 执行如下命令挂载:
[root@centos8 7]# mount /dev/sr1 /var/www/html/centos/7/
mount: /var/www/html/centos/7: WARNING: device write-protected, mounted read-only.
[root@centos8 7]# mount /dev/sr0 /var/www/html/centos/8/
mount: /var/www/html/centos/8: WARNING: device write-protected, mounted read-only.
[root@centos8 7]#
4、正常访问httpd服务后,在客户机 /etc/yum.repos.d/Centos7.repo 或 Centos8.repo仓库文件添加如下内容并验证:
http获取源
Centos7
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
baseurl=http://10.0.0.162/centos/7/
gpgcheck=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
gpgkey=http://10.0.0.162/centos/7/RPM-GPG-KEY-CentOS-7
enabled=1
Centos8:
[baseos]
name=CentOS Linux $releasever - BaseOS
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/
baseurl=http://10.0.0.162/centos/8/BaseOS/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[AppStream]
name=CentOS Linux $releasever - AppStream
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/
baseurl=http://10.0.0.162/centos/8/AppStream/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
#additional packages that may be useful
[extras]
name=CentOS Linux $releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch/os/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
通过刷新yum缓存后验证仓库信息:
centos7
[root@centos7 yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id repo name status
base CentOS-7 - Base 10,072
repolist: 10,072
[root@centos7 yum.repos.d]#
centos8
[root@centos8 yum.repos.d]# yum clean all
21 files removed
[root@centos8 yum.repos.d]# yum update
CentOS Linux 8 - BaseOS 89 MB/s | 2.5 MB 00:00
CentOS Linux 8 - AppStream 91 MB/s | 7.1 MB 00:00
CentOS Linux 8 - Extras - mirrors.aliyun.com 80 kB/s | 10 kB 00:00
Dependencies resolved.
Nothing to do.
Complete!
[root@centos8 yum.repos.d]# yum repolist
repo id repo name
AppStream CentOS Linux 8 - AppStream
baseos CentOS Linux 8 - BaseOS
extras CentOS Linux 8 - Extras - mirrors.aliyun.com
[root@centos8 yum.repos.d]# yum list httpd
Last metadata expiration check: 0:00:15 ago on Sun 12 Dec 2021 11:04:05 PM CST.
Installed Packages
httpd.x86_64 2.4.37-43.module_el8.5.0+1022+b541f3b1 @appstream
[root@centos8 yum.repos.d]# yum list vsftpd
Last metadata expiration check: 0:00:26 ago on Sun 12 Dec 2021 11:04:05 PM CST.
Available Packages
vsftpd.x86_64 3.0.3-33.el8 AppStream
[root@centos8 yum.repos.d]#
yum本地源形式:
命令 createrepo . 可以在当前目录生成元数据 repodata ,从而可以将当前目录作为仓库使用
centos7
1、挂载光驱 mount /dev/cdrom /mnt/cdrom
2、yum配置文件设置为:
[base]
name=CentOS-$releasever - Base
baseurl=file:///mnt/cdrom
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1
【Centos8.repo】
epel源配置已经额外的epel.repo里面配置,故Centos8.repo文件中注释掉该部分
1、安装autofs并启动服务,实现将光驱自动挂载至 /misc/cd目录下
2、编辑 /etc/yum.repos.d/Centos8.repo文件配置如下:
# Centos8.repo
[baseos]
name=CentOS Linux $releasever - BaseOS
failovermethod=priority
baseurl=file:///misc/cd/BaseOS/
https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[AppStream]
name=CentOS Linux $releasever - AppStream
failovermethod=priority
baseurl=file:///misc/cd/AppStream
https://mirrors.aliyun.com/centos/$releasever/AppStream/$basearch/os/
http://mirrors.aliyuncs.com/centos/$releasever/AppStream/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/AppStream/$basearch/os/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that may be useful
[extras]
name=CentOS Linux $releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch/os/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
#[epel]
#name=Extra Packages for Enterprise Linux $releasever - $basearch
## It is much more secure to use the metalink, but if you wish to use a local mirror
## place it's address here.
##metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-$releasever&arch=$basearch&infra=$infra&content=$contentdir
#baseurl=https://mirrors.aliyun.com/epel/$releasever/Everything/$basearch
#gpgcheck=1
#countme=1
#gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-8
##gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS Linux $releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/os/
http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[PowerTools]
name=CentOS Linux $releasever - PowerTools - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/PowerTools/$basearch/os/
http://mirrors.aliyuncs.com/centos/$releasever/PowerTools/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/PowerTools/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
enabled=1
更新yum缓存:yum clean all 和 yum update
[root@centos8 yum.repos.d]# yum clean all
73 files removed
[root@centos8 yum.repos.d]# yum update
CentOS Linux 8 - BaseOS .
.
.
Dependencies resolved.
Nothing to do.
Complete!
[root@centos8 yum.repos.d]# yum repolist
repo id repo name
AppStream CentOS Linux 8 - AppStream
PowerTools CentOS Linux 8 - PowerTools - mirrors.aliyun.com
baseos CentOS Linux 8 - BaseOS
epel Extra Packages for Enterprise Linux 8 - x86_64
epel-modular Extra Packages for Enterprise Linux Modular 8 - x86_64
extras CentOS Linux 8 - Extras - mirrors.aliyun.com
[root@centos8 yum.repos.d]#
[root@centos8 yum.repos.d]# yum list all |grep httpd
centos-logos-httpd.noarch 85.5-1.el8 baseos
dmlite-apache-httpd.x86_64 1.15.1-11.el8 epel
httpd.x86_64 2.4.37-39.module_el8.4.0+778+c970deab AppStream
httpd-devel.x86_64 2.4.37-39.module_el8.4.0+778+c970deab AppStream
.
.
.
#省略后续显示的包
[root@centos8 yum.repos.d]#
2、编译安装http2.4,实现可以正常访问,并将编译步骤和结果提交。
[root@centos8 pkgs_of_httpd]# wget https://dlcdn.apache.org//httpd/httpd-2.4.51.tar.bz2
#获取源码包
[root@centos8 pkgs_of_httpd]# tar -jxvf httpd-2.4.51.tar.bz2
#解压
[root@centos8 pkgs_of_httpd]#yum install -y apr-devel apr-util-devel pcre-devel gcc make openssl-devel redhat-rpm-config autoconf
#安装依赖包
[root@centos8 httpd-2.4.51]# ./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd --enable-ssl
checking for chosen layout... Apache
checking for working mkdir -p... yes
...
#安装配置
[root@centos8 httpd-2.4.51]# make && make install
Making all in srclib
make[1]: Entering directory '/data/pkgs_of_httpd/httpd-2.4.51/srclib'
make[1]: Leaving directory '/data/pkgs_of_httpd/httpd-2.4.51/srclib'
Making all in os
make[1]: Entering directory '/data/pkgs_of_httpd/httpd-2.4.51/os'
Making all in unix
...
make[1]: Leaving directory '/data/pkgs_of_httpd/httpd-2.4.51'
#编译安装
[root@centos8 httpd-2.4.51]# cat /etc/passwd |grep apache
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
[root@centos8 httpd-2.4.51]# usermod -d /var/www -c Apache -u 48 apache
[root@centos8 httpd-2.4.51]# cat /etc/passwd |grep apache
apache:x:48:48:Apache:/var/www:/sbin/nologin
[root@centos8 httpd-2.4.51]#echo 'PATH=/apps/httpd/bin:$PATH' > /etc/profile.d/httpd.sh
[root@centos8 httpd-2.4.51]# . /etc/profile.d/httpd.sh
#添加apache用户,并添加启动命令至PATH
[root@centos8 httpd-2.4.51]#apachectl start
#启动服务
[root@centos8 httpd-2.4.51]#vim /etc/httpd/httpd.conf
#修改 User apache
#修改 Group apache
#重启服务
[root@centos8 httpd-2.4.51]# ps aux |grep httpd
root 88225 0.0 0.3 119008 6592 ? Ss 02:21 0:00 /apps/httpd/bin/httpd -k start
apache 88604 0.0 0.4 1339632 9768 ? Sl 02:39 0:00 /apps/httpd/bin/httpd -k start
apache 88605 0.0 0.4 1339632 9768 ? Sl 02:39 0:00 /apps/httpd/bin/httpd -k start
apache 88606 0.0 0.3 1339632 7728 ? Sl 02:39 0:00 /apps/httpd/bin/httpd -k start
root 88689 0.0 0.0 12136 1160 pts/0 S+ 02:39 0:00 grep --color=auto httpd
[root@centos8 httpd-2.4.51]#
#查看进程
[root@centos8 shell-excercise]# curl http://10.0.0.162
<html><body><h1>It works!</h1></body></html>
[root@centos8 shell-excercise]#

3、利用sed取出ifocnfig命令中本机的ipv4地址。
[root@centos8 data]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.151 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::20c:29ff:fe9b:6267 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:9b:62:67 txqueuelen 1000 (Ethernet)
RX packets 251012 bytes 230084898 (219.4 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 112650 bytes 28477654 (27.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@centos8 data]#
[root@centos8 data]# ifconfig ens33|sed -nE '2s/.*inet ([0-9\.]+).*/\1/p'
10.0.0.151
4、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
1、核实/etc/fstab中满足条件的行并将内容复制到 /data/fstab 做操作测试
[root@centos8 data]# cat -An /etc/fstab
1 $
2 #$
3 # /etc/fstab$
4 # Created by anaconda on Tue Nov 16 17:12:10 2021$
5 #$
6 # Accessible filesystems, by reference, are maintained under '/dev/disk/'.$
7 # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.$
8 #$
9 # After editing this file, run 'systemctl daemon-reload' to update systemd$
10 # units generated from this file.$
11 #$
12 UUID=3dc5ae48-314d-41af-87e1-3f748c16432b / xfs defaults 0 0$
13 UUID=d8f1d916-e9b4-4f9d-8d49-6fe0042237f8 /boot ext4 defaults 1 2$
14 UUID=68d033ab-ee22-4afc-9e02-39439bfd38c1 /data xfs defaults 0 0$
15 UUID=43b2e65e-bd66-4920-9993-218f80d0bee3 none swap defaults 0 0$
[root@centos8 data]#cp -a /etc/fstab /data/fstab
2、需要操作的行数为3,4,9,10,执行如下命令:
sed -i -E 's/'^#[[:space:]]+'//g' fstab
[root@centos8 data]# sed -i -E 's/'^#[[:space:]]+'//g' fstab
[root@centos8 data]# cat -An fstab
1 $
2 #$
3 /etc/fstab$
4 Created by anaconda on Tue Nov 16 17:12:10 2021$
5 #$
6 Accessible filesystems, by reference, are maintained under '/dev/disk/'.$
7 See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.$
8 #$
9 After editing this file, run 'systemctl daemon-reload' to update systemd$
10 units generated from this file.$
11 #$
12 UUID=3dc5ae48-314d-41af-87e1-3f748c16432b / xfs defaults 0 0$
13 UUID=d8f1d916-e9b4-4f9d-8d49-6fe0042237f8 /boot ext4 defaults 1 2$
14 UUID=68d033ab-ee22-4afc-9e02-39439bfd38c1 /data xfs defaults 0 0$
15 UUID=43b2e65e-bd66-4920-9993-218f80d0bee3 none swap defaults 0 0$
[root@centos8 data]#
5、处理/etc/fstab路径,使用sed命令取出其目录名和基名
路径名:
[root@centos8 data]# echo /etc/fstab | sed -E 's/(.*\/)([^\/]*)/\1/'
/etc/
[root@centos8 data]#
基名/basename:
[root@centos8 data]# echo /etc/fstab | sed -E 's/(.*\/)([^\/]*)/\2/'
fstab
[root@centos8 data]#
6、列出Ubuntu软件管理工具apt的一些用法(自由总结)
更新ubuntu18.04 /etc/apt/sources.list 软件仓库源为阿里镜像源,更新后执行 apt update刷新缓存。
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
1、apt list查询包列表信息【安装或未安装都匹配显示】:apt list / apt list --all-versions
root@ubuntu1804-1-edu-org:~# apt list |egrep "^tree"
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
tree/bionic,now 1.7.0-5 amd64 [installed]
tree-ppuzzle/bionic 5.2-10 amd64
tree-puzzle/bionic 5.2-10 amd64
root@ubuntu1804-1-edu-org:~#
root@ubuntu1804-1-edu-org:/etc# apt list --all-versions apache2
Listing... Done
apache2/bionic-updates 2.4.29-1ubuntu4.20 amd64
apache2/bionic-security 2.4.29-1ubuntu4.18 amd64
apache2/bionic 2.4.29-1ubuntu4 amd64
root@ubuntu1804-1-edu-org:/etc#
2、安装指定软件及其依赖: apt install
root@ubuntu1804-1-edu-org:~# apt install apache2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0
ssl-cert
Suggested packages:
Enabling module setenvif.
Enabling conf serve-cgi-bin.
Enabling site 000-default.
Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /lib/systemd/system/apache2.service.
Created symlink /etc/systemd/system/multi-user.target.wants/apache-htcacheclean.service → /lib/systemd/system/apache-htcacheclean.service.
Processing triggers for libc-bin (2.27-3ubuntu1.4) ...
Processing triggers for ureadahead (0.100.0-21) ...
root@ubuntu1804-1-edu-org:~#
3、删除:apt remove 删除软件包[部分配置仍保留] / apt purge 删除软件及其配置文件
root@ubuntu1804-1-edu-org:~# apt remove apache2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 ssl-cert
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
apache2
0 upgraded, 0 newly installed, 1 to remove and 16 not upgraded.
After this operation, 536 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 117875 files and directories currently installed.)
Removing apache2 (2.4.29-1ubuntu4.20) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ufw (0.36-0ubuntu0.18.04.2) ...
root@ubuntu1804-1-edu-org:~# ls /etc/apache2/
apache2.conf conf-available conf-enabled envvars magic mods-available mods-enabled ports.conf sites-available sites-enabled
root@ubuntu1804-1-edu-org:~#root@ubuntu1804-1-edu-org:~# apt purge apache2
Reading package lists... Done
Building dependency tree
Reading state information... Done
4、根据已知特性搜索软件包【正则匹配搜索】: apt search
root@ubuntu1804-1-edu-org:~# apt search '^ftp'
Sorting... Done
Full Text Search... Done
bareftp/bionic 0.3.9-3 amd64
FTP client for GNOME
ftp/bionic,now 0.17-34 amd64 [installed,automatic]
classical file transfer client
5、显示包的安装大小、依赖、安装来源等信息:apt show
[apt depends 查看依赖的软件信息 apt rdepends 查看被依赖的软件信息]
root@ubuntu1804-1-edu-org:~# apt show tree
Package: tree
Version: 1.7.0-5
Priority: optional
Section: universe/utils
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Florian Ernst <florian@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 105 kB
Depends: libc6 (>= 2.14)
Homepage: http://mama.indstate.edu/users/ice/tree/
Task: lubuntu-qt-desktop
Supported: 9m
Download-Size: 40.7 kB
APT-Manual-Installed: yes
APT-Sources: http://mirrors.aliyun.com/ubuntu bionic/universe amd64 Packages
Description: displays an indented directory tree, in color
Tree is a recursive directory listing command that produces a depth indented
listing of files, which is colorized ala dircolors if the LS_COLORS environment
variable is set and output is to tty.
root@ubuntu1804-1-edu-org:~#
6、查看已安装的全部软件信息:apt list --installed
root@ubuntu1804-1-edu-org:~# apt list --installed | wc -l
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
641
root@ubuntu1804-1-edu-org:~#
7、查看文件来自于哪个包:dpkg -S filename
root@ubuntu1804-1-edu-org:/etc# dpkg -S crontab
cron: /usr/bin/crontab
cron: /etc/crontab
cron: /var/spool/cron/crontabs
cron: /usr/share/man/man5/crontab.5.gz
bash-completion: /usr/share/bash-completion/completions/crontab
cron: /usr/share/doc/cron/examples/crontab2english.pl
cron: /usr/share/man/man1/crontab.1.gz
vim-runtime: /usr/share/vim/vim80/syntax/crontab.vim
root@ubuntu1804-1-edu-org:/etc#