自建私有yum仓库,实现本地源和网络源
#虚拟机(IP:10.0.0.150) [root@daben ~]#rpm -qi httpd || yum install -y httpd [root@daben ~]#systemctl enable --now httpd #启动httpd并设置开机启动 [root@daben ~]#mount /dev/sr0 /mnt #挂载光盘 [root@daben ~]#cp -a /mnt/* /var/www/html/centos/7/ #拷贝光盘文件以实现网络源
宿主机(IP:10.0.0.1)浏览器访问测试HTTP共享是否正常
#yum仓库配置 [root@daben ~]# cat /etc/yum.repos.d/test.repo [test_local] name="本地镜像源..." baseurl=http://10.0.0.150/centos/7/ enable=1 [test_network] name="HTTP网络源..." baseurl=file:///var/www/html/centos/7/ enable=1
验证配置结果
编译安装http2.4,实现正常访问
#提前关闭防火墙和SELinux #安装编译工具 [root@daben ~]# yum install -y gcc make autoconf apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config wget #下载并解压源码包 [root@daben httpd-2.4.53]# wget --no-check-certificate https://dlcdn.apache.org/httpd/httpd-2.4.53.tar.gz [root@daben httpd-2.4.53]# tar xf httpd-2.4.53.tar.gz -C /usr/local/src/ #配置安装路径、指定配置文件路径、启动ssl加密模块 [root@daben ~]# cd /usr/local/src/httpd-2.4.53/ [root@daben httpd-2.4.53]# ./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd --enable-ssl #查看CPU核心数,加速编译安装 [root@daben httpd-2.4.53]# cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l 2 [root@daben httpd-2.4.53]# make -j 2 && make install ... mkdir /apps/httpd/man/man1 mkdir /apps/httpd/man/man8 mkdir /apps/httpd/manual make[1]: Leaving directory '/usr/local/src/httpd-2.4.53' [root@daben httpd-2.4.53]# #配置环境变量 [root@daben ~]# echo 'PATH=/apps/httpd/bin:$PATH' > /etc/profile.d/httpd.sh [root@daben ~]# . /etc/profile.d/httpd.sh #运行httpd [root@daben ~]# apachectl start AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message' #添加用户账号以启动httpd [root@daben ~]# useradd -r -s /sbin/nologin -d /var/www -c Apache -u 48 apache [root@daben ~]# cat >> /etc/httpd/httpd.conf <<EOF > user apache > group apache > EOF #重启服务验证结果 [root@daben ~]# apachectl restart AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message' [root@daben ~]# ps aux | grep apache apache 38913 0.0 0.2 499272 4908 ? Sl 19:53 0:00 /apps/httpd/bin/httpd -k start apache 38914 0.0 0.2 368200 4244 ? Sl 19:53 0:00 /apps/httpd/bin/httpd -k start apache 38915 0.0 0.2 368200 4244 ? Sl 19:53 0:00 /apps/httpd/bin/httpd -k start apache 38997 0.0 0.2 433736 4228 ? Sl 19:53 0:00 /apps/httpd/bin/httpd -k start root 39026 0.0 0.0 112812 980 pts/2 S+ 19:54 0:00 grep --color=auto apache #虚拟机访问结果 [root@daben ~]# curl localhost <html><body><h1>It works!</h1></body></html>
浏览器访问结果(虚拟机IP10.0.0.150)
利用sed配合ifconfig获取IP
[root@daben ~]# ifconfig ens33 |sed -nr "2s/[^0-9]+([0-9.]+).*/\1/p" #ens33为网卡名 10.0.0.150
删除/etc/fstab文件中所有的空白行和以#开头的行的行首的#和空白符(取消注释)
#源文件 [root@daben ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Fri Mar 18 22:59:00 2022 # # 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=b842db9d-2d32-4267-b2a5-31d4fc22c08f / xfs defaults 0 0 UUID=c65490e5-72c8-4087-a39a-bcb3d8c6f9fb /boot xfs defaults 0 0 UUID=36b28cbb-1e1e-46aa-8ac3-e6783b70ef18 /data xfs defaults 0 0 UUID=1f3d451e-2d37-47d3-b70f-27ad7dca3ecb swap swap defaults 0 0 #删除#和空白行 [root@daben ~]# cat /etc/fstab |sed -re 's/^#\ ?(.*)/\1/' -e '/^$/d' /etc/fstab Created by anaconda on Fri Mar 18 22:59:00 2022 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=b842db9d-2d32-4267-b2a5-31d4fc22c08f / xfs defaults 0 0 UUID=c65490e5-72c8-4087-a39a-bcb3d8c6f9fb /boot xfs defaults 0 0 UUID=36b28cbb-1e1e-46aa-8ac3-e6783b70ef18 /data xfs defaults 0 0 UUID=1f3d451e-2d37-47d3-b70f-27ad7dca3ecb swap swap defaults 0 0 [root@daben ~]#
处理/etc/fstab路径,使用sed命令取出其目录名和基名
[root@daben ~]# echo /etc/fstab|sed -r 's@^(/.*/)(.*)@path:\1 basename:\2@' path:/etc/ basename:fstab
ubuntu软件管理工具apt的一些用法
#卸载单个软件包但是保留配置⽂件 apt remove apache2 #卸载单个软件包删除配置⽂件 apt purge apache2(彻底删除) #编辑source源⽂件 apt edit-sources #查看仓库中软件包有哪些版本可以安装 apt-cache madison nginx #安装软件包的时候指定安装具体的版本 apt install nginx=1.14.0-0ubuntu1.6 范例: 查找存在的文件来自于哪个包 #dpkg -S filename :在当前安装的包里查找文件 root@daben:~# dpkg -S /bin/ls coreutils: /bin/ls 范例: 查找不存在的文件存在于哪个包 #查看文件来自于哪个包,类似redhat中的yum provides <filename> #apt-file search 'string' #默认是包含此字符串的文件 #apt-file search -x '正则表达式' #apt-file search -F /path/file root@daben:~#apt -y install apt-file root@daben:~##apt update root@daben:~##apt-file search -x '/sl$' espeak-data: /usr/lib/x86_64-linux-gnu/espeak-data/voices/test/sl espeak-ng-data: /usr/lib/x86_64-linux-gnu/espeak-ng-data/lang/zls/sl language-pack-sl-base: /var/lib/locales/supported.d/sl python-langdetect: /usr/lib/python2.7/dist-packages/langdetect/profiles/sl python3-langdetect: /usr/lib/python3/dist-packages/langdetect/profiles/sl qemu-system-common: /usr/share/qemu/keymaps/sl rdesktop: /usr/share/rdesktop/keymaps/sl sl: /usr/games/sl virtualbox: /usr/share/virtualbox/rdesktop-vrdp-keymaps/sl root@daben:~#apt-file search -F /usr/games/sl sl: /usr/games/sl
OSI七层模式和TCP/IP五层模型
OSI 模型的七层结构
第7层 应用层
第6层 表示层
第5层 会话层
第4层 传输层
第3层 网络层
第2层 数据链接层
第1层 物理层
PDU: Protocol Data Unit,协议数据单元是指对等层次之间传递的数据单位
TCP/IP 分层
TCP/IP和OSI模型的比较
TCP三次握手四次挥手(参考链接 http://www.yunweipai.com/36410.html)
TCP和UDP区别(参考链接 http://www.yunweipai.com/36410.html)
连接和无连接:TCP 是面向连接的协议,而 UDP 是无连接协议。TCP 可以在发送数据之前在发送方和接收方之间建立连接。而 UDP 在发送数据之前不会先建立连接。
可靠性:TCP 是可靠的。使用 TCP 协议发送的数据可以保证传递到接收。如果数据在传输过程中丢失,它会恢复数据并重新发送。TCP 还将检查数据包中的错误并跟踪数据包,以保证数据不会丢失或损坏。而 UDP 是不可靠的,它不能提供有保证质量的传递,并且数据报包可能会在传输中损坏或丢失。
流量控制:TCP 使用流控制机制来确保发送者不会一次发送太多数据包而压倒接收者。TCP 将数据存储在发送缓冲区中,并在接收缓冲区中接收数据。当应用程序准备就绪时,它将从接收缓冲区读取数据。如果接收缓冲区已满,则接收器将无法处理更多数据并将其丢弃。为了保持可以发送给接收方的数据量,接收方会告诉发送方接收缓冲区中有多少剩余空间(接收窗口)。每次接收到数据包时,都会使用当前接收窗口的值向发送方发送一条消息。UDP 不提供流控制。使用 UDP,数据包以连续流的形式到达或被丢弃。
速度:TCP 比 UDP 慢,因为它“顾虑”比较多:TCP 必须建立连接,进行错误检查,并确保按照发送顺序接收文件。而 UDP 则更简单,更高效。
使用场景:
TCP 最适合用于对时序不太关心的,且要求高可靠性的应用程序。
UDP 最适合需要速度和效率的应用程序。
网卡绑定bond0的实现
系统版本
[root@daben ~]# cat /etc/redhat-release CentOS Linux release 7.8.2003 (Core)
准备两张网卡(ens33和ens36)
创建bonding设备的配置文件
[root@daben ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0 NAME=bond0 TYPE=bond DEVICE=bond0 BOOTPROTO=none IPADDR=10.0.0.200 PREFIX=8 [root@daben ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 NAME=ens33 DEVICE=ens33 BOOTPROTO=none MASTER=bond0 SLAVE=yes ONBOOT=yes [root@daben ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens36 NAME=ens33 DEVICE=ens33 BOOTPROTO=none MASTER=bond0 SLAVE=yes ONBOOT=yes
验证结果
关闭其中一个网卡(ens33)后网络正常