跳到主要内容

3 篇博文 含有标签「Centos7」

查看所有标签

· 12 分钟阅读
CheverJohn

本篇博客第一部分受到了这篇博文的启发。

TL; DR

将结论写在前头

事实上,为什么我们很多人在接触一个新的项目时候会遇到各种各样的坑呢?

根据这一次的经历来看,其中的主要原因还是在于本地部署环境的不完备。本次踩坑经历,其实问题就是在 git 啦、gcc 啦等之类看似很常见的东西,实际并没有配置好,然后咱们的项目文档书写者呢,默认了你已经完全配置好这些基本的东西了。唉,但是谁能想到大多数人都会是在虚拟机、wsl、docker上配置,看来 docker 其实更具有实用性,可以当做乐高组件一样,什么时候想用哪几个,直接拼凑起来,就是一个了,不扯远了。

这边先说清楚成功部署APISIX项目,系统需要具备的最基本的东西:

  • git的安装
    • 与Github进行ssh连接得做好
    • git 代理得做好
  • 本地的ssh公钥密钥得有(具体查看.ssh文件夹)
  • centos7应该安装的基本库
    • wget
    • unzip
    • git
    • gcc
    • yum update(重要!!!)

第一部分:安装

安装 APISIX 运行环境依赖

基本方法内容来自于官方文档;

安装 etcd

命令:

wget https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz
tar -xvf etcd-v3.4.13-linux-amd64.tar.gz && \
cd etcd-v3.4.13-linux-amd64 && \
sudo cp -a etcd etcdctl /usr/bin/

安装 OpenResty

命令:

sudo yum install yum-utils
sudo yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo

# 安装 OpenResty 和 编译工具
sudo yum install -y openresty curl git gcc openresty-openssl111-devel unzip pcre pcre-devel

# 安装 LuaRocks
curl https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh -sL | bash -

然后才能正常启动 etcd

nohup etcd &

第二部分:踩坑

问题一:

LUAROCKS_1

[root@MiWiFi-R4CM-srv apisix-2.10.3]# LUAROCKS_SERVER=https://luarocks.cn make deps
/bin/bash: luarocks: command not found
WARN: You're not using LuaRocks 3.x, please add the following items to your LuaRocks config file:
variables = {
OPENSSL_LIBDIR=/usr/local/openresty/openssl111/lib
OPENSSL_INCDIR=/usr/local/openresty/openssl111/include
}
luarocks install rockspec/apisix-master-0.rockspec --tree=deps --only-deps --local --server https://luarocks.cn
/bin/bash: luarocks: command not found
make: *** [deps] Error 127
[root@MiWiFi-R4CM-srv apisix-2.10.3]# ^C

解决方法

curl https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh -sL | bash -

问题二(接问题一):

当运行了上面的命令后,又出现新的问题,看来是治标不治本啊

Solved_crul_by_installing_sth

[root@MiWiFi-R4CM-srv apisix-2.10.3]# curl https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh -sL | bash -
+ '[' -z ']'
+ OPENRESTY_PREFIX=/usr/local/openresty
+ LUAROCKS_VER=3.8.0
+ wget https://github.com/luarocks/luarocks/archive/v3.8.0.tar.gz
--2022-01-18 04:53:17-- https://github.com/luarocks/luarocks/archive/v3.8.0.tar.gz
Resolving github.com (github.com)... 20.205.243.166
Connecting to github.com (github.com)|20.205.243.166|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/luarocks/luarocks/tar.gz/v3.8.0 [following]
--2022-01-18 04:53:18-- https://codeload.github.com/luarocks/luarocks/tar.gz/v3.8.0
Resolving codeload.github.com (codeload.github.com)... 20.205.243.165
Connecting to codeload.github.com (codeload.github.com)|20.205.243.165|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5389112 (5.1M) [application/x-gzip]
Saving to: ‘v3.8.0.tar.gz’

100%[====================================================================================================================================================================>] 5,389,112 1.71MB/s in 3.0s

2022-01-18 04:53:22 (1.71 MB/s) - ‘v3.8.0.tar.gz’ saved [5389112/5389112]

+ tar -xf v3.8.0.tar.gz
+ cd luarocks-3.8.0
+ OR_BIN=/usr/local/openresty/bin/openresty
++ /usr/local/openresty/bin/openresty -v
++ awk -F / '{print $2}'
++ awk -F . '{print $1"."$2}'
+ OR_VER=1.19
+ [[ -e /usr/local/openresty/bin/openresty ]]
+ [[ 1.19 == 1.19 ]]
+ WITH_LUA_OPT=--with-lua=/usr/local/openresty/luajit
+ ./configure --with-lua=/usr/local/openresty/luajit
+ cat build.log

Configuring LuaRocks version 3.8.0...

Lua version detected: 5.1
Lua interpreter found: /usr/local/openresty/luajit/bin/luajit
lua.h found: /usr/local/openresty/luajit/include/luajit-2.1/lua.h
Could not find 'unzip'.
Make sure it is installed and available in your PATH.

configure failed.

+ exit 1
[root@MiWiFi-R4CM-srv apisix-2.10.3]# sudo yum install wget sudo unzip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.163.com
* updates: mirrors.163.com

解决方法:

sudo yum install wget sudo unzip

问题三(接问题二):

继续运行

[root@MiWiFi-R4CM-srv apisix-2.10.3]# curl https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh -sL | bash -

发现还有问题

install_gcc

解决方法:

yum -y install gcc

直接解决了问题

[root@MiWiFi-R4CM-srv apisix-2.10.3]# yum -y install gcc
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.163.com
* updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package gcc.x86_64 0:4.8.5-44.el7 will be installed
--> Processing Dependency: cpp = 4.8.5-44.el7 for package: gcc-4.8.5-44.el7.x86_64
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.8.5-44.el7.x86_64
--> Processing Dependency: libmpfr.so.4()(64bit) for package: gcc-4.8.5-44.el7.x86_64
--> Processing Dependency: libmpc.so.3()(64bit) for package: gcc-4.8.5-44.el7.x86_64
--> Running transaction check
---> Package cpp.x86_64 0:4.8.5-44.el7 will be installed
---> Package glibc-devel.x86_64 0:2.17-325.el7_9 will be installed
--> Processing Dependency: glibc-headers = 2.17-325.el7_9 for package: glibc-devel-2.17-325.el7_9.x86_64
--> Processing Dependency: glibc = 2.17-325.el7_9 for package: glibc-devel-2.17-325.el7_9.x86_64
--> Processing Dependency: glibc-headers for package: glibc-devel-2.17-325.el7_9.x86_64
---> Package libmpc.x86_64 0:1.0.1-3.el7 will be installed
---> Package mpfr.x86_64 0:3.1.1-4.el7 will be installed
--> Running transaction check
---> Package glibc.x86_64 0:2.17-317.el7 will be updated
--> Processing Dependency: glibc = 2.17-317.el7 for package: glibc-common-2.17-317.el7.x86_64
---> Package glibc.x86_64 0:2.17-325.el7_9 will be an update
---> Package glibc-headers.x86_64 0:2.17-325.el7_9 will be installed
--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.17-325.el7_9.x86_64
--> Processing Dependency: kernel-headers for package: glibc-headers-2.17-325.el7_9.x86_64
--> Running transaction check
---> Package glibc-common.x86_64 0:2.17-317.el7 will be updated
---> Package glibc-common.x86_64 0:2.17-325.el7_9 will be an update
---> Package kernel-headers.x86_64 0:3.10.0-1160.49.1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================================================================
Installing:
gcc x86_64 4.8.5-44.el7 base 16 M
Installing for dependencies:
cpp x86_64 4.8.5-44.el7 base 5.9 M
glibc-devel x86_64 2.17-325.el7_9 updates 1.1 M
glibc-headers x86_64 2.17-325.el7_9 updates 691 k
kernel-headers x86_64 3.10.0-1160.49.1.el7 updates 9.0 M
libmpc x86_64 1.0.1-3.el7 base 51 k
mpfr x86_64 3.1.1-4.el7 base 203 k
Updating for dependencies:
glibc x86_64 2.17-325.el7_9 updates 3.6 M
glibc-common x86_64 2.17-325.el7_9 updates 12 M

Transaction Summary
==============================================================================================================================================================================================================
Install 1 Package (+6 Dependent packages)
Upgrade ( 2 Dependent packages)

Total download size: 48 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/9): cpp-4.8.5-44.el7.x86_64.rpm | 5.9 MB 00:00:04
(2/9): glibc-headers-2.17-325.el7_9.x86_64.rpm | 691 kB 00:00:00
(3/9): glibc-devel-2.17-325.el7_9.x86_64.rpm | 1.1 MB 00:00:05
(4/9): libmpc-1.0.1-3.el7.x86_64.rpm | 51 kB 00:00:00
(5/9): mpfr-3.1.1-4.el7.x86_64.rpm | 203 kB 00:00:00
(6/9): glibc-common-2.17-325.el7_9.x86_64.rpm | 12 MB 00:00:08
(7/9): gcc-4.8.5-44.el7.x86_64.rpm | 16 MB 00:00:08
(8/9): kernel-headers-3.10.0-1160.49.1.el7.x86_64.rpm | 9.0 MB 00:00:04
(9/9): glibc-2.17-325.el7_9.x86_64.rpm | 3.6 MB 00:00:10
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 4.7 MB/s | 48 MB 00:00:10
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : glibc-2.17-325.el7_9.x86_64 1/11
Updating : glibc-common-2.17-325.el7_9.x86_64 2/11
Installing : mpfr-3.1.1-4.el7.x86_64 3/11
Installing : libmpc-1.0.1-3.el7.x86_64 4/11
Installing : cpp-4.8.5-44.el7.x86_64 5/11
Installing : kernel-headers-3.10.0-1160.49.1.el7.x86_64 6/11
Installing : glibc-headers-2.17-325.el7_9.x86_64 7/11
Installing : glibc-devel-2.17-325.el7_9.x86_64 8/11
Installing : gcc-4.8.5-44.el7.x86_64 9/11
Cleanup : glibc-2.17-317.el7.x86_64 10/11
Cleanup : glibc-common-2.17-317.el7.x86_64 11/11
Verifying : mpfr-3.1.1-4.el7.x86_64 1/11
Verifying : glibc-devel-2.17-325.el7_9.x86_64 2/11
Verifying : gcc-4.8.5-44.el7.x86_64 3/11
Verifying : glibc-headers-2.17-325.el7_9.x86_64 4/11
Verifying : kernel-headers-3.10.0-1160.49.1.el7.x86_64 5/11
Verifying : libmpc-1.0.1-3.el7.x86_64 6/11
Verifying : glibc-common-2.17-325.el7_9.x86_64 7/11
Verifying : glibc-2.17-325.el7_9.x86_64 8/11
Verifying : cpp-4.8.5-44.el7.x86_64 9/11
Verifying : glibc-2.17-317.el7.x86_64 10/11
Verifying : glibc-common-2.17-317.el7.x86_64 11/11

Installed:
gcc.x86_64 0:4.8.5-44.el7

Dependency Installed:
cpp.x86_64 0:4.8.5-44.el7 glibc-devel.x86_64 0:2.17-325.el7_9 glibc-headers.x86_64 0:2.17-325.el7_9 kernel-headers.x86_64 0:3.10.0-1160.49.1.el7 libmpc.x86_64 0:1.0.1-3.el7 mpfr.x86_64 0:3.1.1-4.el7

Dependency Updated:
glibc.x86_64 0:2.17-325.el7_9 glibc-common.x86_64 0:2.17-325.el7_9

Complete!

Complete_by_install_gcc

问题四(搁浅中......):

这边的LUAROCKS是针对于

开始LUAROCKS_SERVER......

[root@MiWiFi-R4CM-srv apisix-2.10.3]# LUAROCKS_SERVER=https://luarocks.cn make deps

爆出问题

solve

分析问题:

[root@MiWiFi-R4CM-srv apisix-2.10.3]# LUAROCKS_SERVER=https://luarocks.cn make deps
…………………………………………………………………………………………………………………………………………………………………………
lua-resty-dns-client 5.2.0-1 depends on luaxxhash >= 1.0 (not installed)
Installing https://luarocks.cn/luaxxhash-1.0.0-1.rockspec

Error: Failed installing dependency: https://luarocks.cn/lua-resty-dns-client-5.2.0-1.src.rock - Failed installing dependency: https://luarocks.cn/luaxxhash-1.0.0-1.rockspec - 'git' program not found. Make sure Git is installed and is available in your PATH (or you may want to edit the 'variables.GIT' value in file '/root/.luarocks/config-5.1.lua')
make: *** [deps] Error 1
[root@MiWiFi-R4CM-srv apisix-2.10.3]# yum install -y git

很明显就是没有安装配置好git嘛

config_git

lua-resty-dns-client 5.2.0-1 depends on lua >= 5.1, < 5.4 (5.1-1 provided by VM)
lua-resty-dns-client 5.2.0-1 depends on penlight ~> 1 (1.12.0-1 installed)
lua-resty-dns-client 5.2.0-1 depends on lrandom (20180729-1 installed)
lua-resty-dns-client 5.2.0-1 depends on lua-resty-timer ~> 1 (1.1.0-1 installed)
lua-resty-dns-client 5.2.0-1 depends on binaryheap >= 0.4 (0.4-1 installed)
lua-resty-dns-client 5.2.0-1 depends on luaxxhash >= 1.0 (not installed)
Installing https://luarocks.cn/luaxxhash-1.0.0-1.rockspec
Cloning into 'luaxxhash'...
error: RPC failed; result=35, HTTP code = 0
fatal: The remote end hung up unexpectedly

Error: Failed installing dependency: https://luarocks.cn/lua-resty-dns-client-5.2.0-1.src.rock - Failed installing dependency: https://luarocks.cn/luaxxhash-1.0.0-1.rockspec - Failed cloning git repository.
make: *** [deps] Error 1
[root@MiWiFi-R4CM-srv apisix-2.10.3]# ls
apisix bin CHANGELOG.md CODE_OF_CONDUCT.md CODE_STYLE.md conf CONTRIBUTING.md deps LICENSE Makefile NOTICE powered-by.md README.md rockspec v3.8.0.tar.gz v3.8.0.tar.gz.1
[root@MiWiFi-R4CM-srv apisix-2.10.3]#
[root@MiWiFi-R4CM-srv apisix-2.10.3]# cd ..
[root@MiWiFi-R4CM-srv api7]# ls
apache-apisix-2.10.3-src.tgz apisix-2.10.3
[root@MiWiFi-R4CM-srv api7]# git clone git@github.com:Chever-John/JohnChever-Blog.git
Cloning into 'JohnChever-Blog'...
The authenticity of host 'github.com (20.205.243.166)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
ECDSA key fingerprint is MD5:7b:99:81:1e:4c:91:a5:0d:5a:2e:2e:80:13:3f:24:ca.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,20.205.243.166' (ECDSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
[root@MiWiFi-R4CM-srv api7]# git clone git@github.com:Chever-John/JohnChever-Blog.git
Cloning into 'JohnChever-Blog'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
[root@MiWiFi-R4CM-srv api7]# git config --global user.name "CheverJohn"
[root@MiWiFi-R4CM-srv api7]# git config --global user.email "cheverjonathan@gmail.com"
[root@MiWiFi-R4CM-srv api7]# git config --list
user.name=CheverJohn
user.email=cheverjonathan@gmail.com
[root@MiWiFi-R4CM-srv api7]# ssh-keygen -t rsa -C "cheverjonathan@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:XVvMrYv9c92MVJm8CMUmZA44WgYv+atEOydMkpWc0I8 cheverjonathan@gmail.com
The key's randomart image is:
+---[RSA 2048]----+
| .... ...o. |
| o.== +. * . |
| B*.. .= = +|
| oEo. . o o =.|
| o o .S . o o..|
| = . . +.o |
| * o ..ooo|
| . = .o=|
| . +|
+----[SHA256]-----+
[root@MiWiFi-R4CM-srv api7]# cat /root/.ssh
cat: /root/.ssh: Is a directory
[root@MiWiFi-R4CM-srv api7]# ls
apache-apisix-2.10.3-src.tgz apisix-2.10.3
[root@MiWiFi-R4CM-srv api7]# cd /root/.ssh
[root@MiWiFi-R4CM-srv .ssh]# ls
id_rsa id_rsa.pub known_hosts
[root@MiWiFi-R4CM-srv .ssh]# cat id_rsa.pub
接下来显示就是生成的ssh密钥了,将其复制到github上的ssh里即可

继续LUAROCKS_SERVER......

LUAROCKS_SERVER=https://luarocks.cn make deps

还是出现了问题

maybe_git_proxy

怀疑是git代理的问题!!!

这边开始暂时不搞apisix中的LUAROCKS了,开始按照官网的需求准备

未解决!!!

问题五:前提需求准备中的wget问题

然后遇到了wget问题

如果使用wget的话,会出现一个

just_yum_update

遇到Unable to establish SSL connection的报错

这个时候,只需要轻轻yum update即可,原因是未更新前的centos里的库大部分是老旧的,特别是导致这个问题的openssl。

此处(指yum update)收到了该链接的灵感。

当我们yum update之后,即可成功

然后运行wget,至此wget https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz完美解决,结束了。

成功结束的样子

finish

问题六:继续回到问题四

LUAROCKS_SERVER继续在apisix-2.10.3文件中进行运行

// 遇到问题!
apisix master-0 depends on lua-resty-ngxvar 0.5.2 (not installed)
Installing https://luarocks.cn/lua-resty-ngxvar-0.5.2-0.rockspec
Cloning into 'lua-var-nginx-module'...
fatal: unable to access 'https://github.com/api7/lua-var-nginx-module/': Encountered end of file

Error: Failed installing dependency: https://luarocks.cn/lua-resty-ngxvar-0.5.2-0.rockspec - Failed cloning git repository.
make: *** [deps] Error 1
[root@MiWiFi-R4CM-srv apisix-2.10.3]#

完成etcd的安装

finish_etcd

这边根据链接讲的东西从而进行etcd的安装。

All Done

上一张证明自己All Done的截图照片

All-Done-Solved_Problems

试试证明确实使用git proxy代理好,一下子就能解决所有问题了。

git_proxy

列出一些算是对我有所帮助的链接地址吧

https://www.mihu.live/archives/208/ https://zhuanlan.zhihu.com/p/120038973

晚上再来把文字搞好看一点

请忽略的etcd文件夹目录,刚刚运行起etcd了。so就急匆匆curl咯,根据这处链接及其提供的命令和结果,得以判断咱们的Apache APISIX是否已经成功启动。

· 2 分钟阅读
CheverJohn

本文由 简悦 SimpRead 转码, 原文地址 blog.csdn.net

现象说明
在安装 CentOS 系统后,有可能出现无法联网的问题,虚拟机中的网络配置并没有问题,而系统却无法联网, 也 ping 不同。

原因描述
CentOS 默认开机不启动网络,因此需要对网络进行配置,开启网络开机启动。

解决方法

  1. 打开终端,使用ip addr命令查看一下网络信息
    findMyNIC
    图中圈出的是系统网络名称,我们稍后会用到它,有的系统是 ens33,有的是 eth0 等
  2. 切换至 root 用户,输入命令vi /etc/sysconfig/network-scripts/ifcfg-<系统网络名称>,我的是 eth33,所以输入vi /etc/sysconfig/network-scripts/ifcfg-ens33命令
    login
  3. 进入 vi 界面,可以看到,ONBOOT 的值是 no
    changeConfig
  4. 将 ONBOOT 的值改为 yes(不会使用 vi 的可以百度一下,很容易上手的)
    afterChange
  5. 保存后退出,重启系统(可以reboot命令重启)。重启完成后,可以使用浏览器打开个网页看看,也可以使用ping命令测试网络连通性
    testNetwork

· 26 分钟阅读
CheverJohn

TL; DR :)

文章内容描述

本篇文章主要聚焦一个实操点:虚拟机(VMware)中Centos-7系统的网络配置以及如何从宿主机使用功能ssh工具连接到虚拟机(VMware)中的Centos-7系统。

本篇文章主要涉及到的原理知识为:

  • 计算机网络中的子网掩码网关是什么
  • VMware主要的网络通信方式:桥接、NAT

所以,阅读完本篇文章,你将会收获......

计算机网络中两个基础知识——子网掩码网关,以及VMware的网络方案架构

感慨啊~真的是好久没有接触这个东西,然后又因为我的计算机网络知识基础也太不牢固了叭,居然老是忘记配置centos的子网掩码和 网关,就用这篇文章好好的巩固一下吧。

看是解决不了问题的,要实操! 韶光易逝,劝君惜取少年时! ——笔者(CheverJohn)疯狂寄语hhhh

实际操作

本地环境说明

windows version: 21H1(OS Build 19043.1415)

远程连接工具: Mobaxterm

安装centos(主要是指网络配置)

我们在安装Centos的时候,会经历一个网络环境配置的问题。

当然安装Centos的过程我就不讲了,这边重点还是给Centos进行网络配置的过程。

VMware中的linux网络配置从VMware本身层面来讲,有三种

1. Bridged   桥接模式
2. NAT NAT模式
3. Host-only

就先这么叫着,我这边介绍一种方法——Bridged 桥接模式(我认为很简单的方法)。

桥接模式(wifi下也可以用)

简单介绍一下桥接模式

桥接网络是指本地物理网卡和虚拟网卡通过VMnet0虚拟交换机进行桥接,物理网卡和虚拟网卡在拓扑图上处于同等地位,那么物理网卡和虚拟网卡就相当于处于同一个网段,虚拟交换机就相当于一台现实网络中的交换机,所以两个网卡的IP地址也要设置为同一网段。

所以当我们要在局域网使用虚拟机,对局域网其他pc提供服务时,例如提供ftp,提供ssh,提供http服务,那么就要选择桥接模式。

例如大学宿舍里有一个路由器,宿舍里四个人连接这个路由器,路由器的wanip就不理会了,这个ip是动态获取的,而lanip默认是192.168.1.1,子网掩码是255.255.255.0。而其他四个人是自动获取ip,假设四个人的ip是:

A:192.168.1.100/255.255.255.0, B:192.168.1.101/255.255.255.0, C:192.168.1.102/255.255.255.0, D:192.168.1.103/255.255.255.0

那么虚拟机的ip可以设置的ip地址是192.168.1.2-192.168.1.99,192.168.1.104-192.168.1.254(网络地址全0和全1的除外,再除去ABCD四个人的ip地址)

那么虚拟机的ip地址可以设置为192.168.1.98/255.255.255.0,设置了这个ip地址,ABCD这四个人就可以通过192.168.1.98访问虚拟机了,如果虚拟机需要上外网,那么还需要配置虚拟机的路由地址,就是192.168.1.1了,这样,虚拟机就可以上外网了,但是,上网我们一般是通过域名去访问外网的,所以我们还需要为虚拟机配置一个dns服务器,我们可以简单点,把dns服务器地址配置为google的dns服务器:8.8.8.8,到此,虚拟机就可以上网了。

来源自链接

具体的原理见下面的详细讲解

配置桥接模式

emmmmm,还是看B站CodeSheep的视频叭,因为我发现我的配置好了,截图好像发出来不是桥接模式的截图,是NAT的,就很迷。

固定住centos的IP地址

当我们刚安装好,centos的网卡配置文件有几项是关闭的,我们需要打开一下,然后设置成如下图所示:

centos的网卡配置文件

没错这边,我的固定ip地址为192.168.2.233,然后我为其配置的网关为192.168.2.1。

至于我为什么这么配置,还请看下面的原理讲解。

然后配置完成后,就得重启网卡咯

# centos7
systemctl restart network

PS: 这边其实还需要注意一点,因为选择了桥接模式,那么我们的虚拟机其实是和宿主机是在同一个网段的,我宿主机的IP地址是192.168.2.228,然后我的虚拟机里的IP地址是192.168.2.233,前三个网段很明显,我设置的静态IP很明显。

测试是否ping通

在虚拟机里ping宿主机

虚拟机ping宿主机

在宿主机里ping虚拟机

宿主机ping虚拟机

原理讲述

VMware网络连接原理

来源

提前声明,本部分内容大部分来自于官方文档

官方文档,yyds,永远的神!

此外我加入了我个人的理解,就是这样。

Bridged Networking(桥接网络)

原理讲解

首先介绍的就是我们的桥接网络配置。

先干上一大段来自官方文档的说明

When you install Workstation Pro on a Windows or Linux host system, a bridged network (VMnet0) is set up for you. Bridged networking connects a virtual machine to a network by using the network adapter on the host system. If the host system is on a network, bridged networking is often the easiest way to give the virtual machine access to that network.

With bridged networking, the virtual network adapter in the virtual machine connects to a physical network adapter in the host system. The host network adapter enables the virtual machine to connect to the LAN that the host system uses. Bridged networking works with both wired and wireless host network adapters.

Bridged networking configures the virtual machine as a unique identity on the network, separate from and unrelated to the host system. The virtual machine is a full participant in the network. It has access to other machines on the network, and other machines on the network can contact it as if it were a physical computer on the network.

看到大段英文不要怕哈,要么勇敢地读下去,要么直接转去百度翻译hhhh

上面来自官方文档的开场白,主要说的就是桥接模式是一种最简单的联网模式。而且使用了桥接模式之后,虚拟机就相当于独立的一台物理机在局域网中(如下图所示),就相当于和宿主机同时连接在了一台网络交换机上的两个不同的端口上。虽然这俩其实都在一台实体的电脑上hhhh,就很神奇是不是。但我想如果你能够理解网卡就相当于一台设备在网络中的“唯一标识“之后,这点就很容易理解啦!

Bridged Networking Configuration

Bridged Networking Configuration

You can view and change the settings for bridged networking on the host system, determine which network adapters to use for bridged networking, and map specific host network adapters to specific virtual switches.

你也可以在主机系统上查看和更改桥接网络的设置,确定使用哪些网络适配器进行桥接网络,并将特定的主机网络适配器映射到特定的虚拟交换机。

唉,就相当于是说在宿主机上进行网卡的相关配置。我命令哪些网卡去做与哪些虚拟机系统相关的操作尔尔。

提供各种玩法

Assigning IP Addresses in a Bridged Networking Environment

A virtual machine must have its own identity on a bridged network. For example, on a TCPIP network, the virtual machine needs its own IP address. Your network administrator can tell you whether IP addresses are available for virtual machines and which networking settings to use in the guest operating system.

虚拟机在桥接网络上必须有自己的标识。例如,在TCPIP网络中,虚拟机需要自己的IP地址。网络管理员可以告诉您虚拟机的IP地址是否可用,以及在客户操作系统中使用哪些网络设置。

我理解哈,如果要让虚拟机的网络能够正常使用,那么就得按照我上头讲的配置(固定系统IP),然后就能跑通啦。

关于这一大段话的详细解释在这个链接我觉得我的理解也没啥问题。

Add a Bridged Network

When you install Workstation Pro on a Windows or Linux host system, a bridged network (VMnet0) is set up for you. If you install Workstation Pro on a host system that has multiple network adapters, you can configure multiple bridged networks.

啊这这这这~总感觉这段是废话,有种那种说了半天还是废话的感觉。。。

Configure Bridged Networking for an Existing Virtual Machine

You can configure bridged networking for an existing virtual machine.[了解更多内容]

emmm,这个我该咋说呢?字面意思啊,你可以为一个已存在的虚拟机配置桥接,自己个点了解更多内容去看叭。

Change VMnet0 Bridged Networking Settings

By default, VMnet0 is set to use auto-bridging mode and is configured to bridge to all active network adapters on the host system. You can use the virtual network editor to change VMnet0 to bridge to one specific host network adapter, or restrict the host network adapters that VMnet0 auto-bridges to. The changes you make affect all virtual machines that use bridged networking on the host system.[了解更多内容]

我们还可以改变VMnet0的设置哦,去和自己想要的宿主机网卡适配器进行配置呢。详情请点击上方链接噻。

Network Address Translation(NAT模式)

原理讲解

字面意思哦,网络地址翻译,大家可以这么理解,相当于一种绑定,键值对的绑定hhhh。拿数据库的东西来理解呢。

首先开始一波官方的自我介绍

When you install Workstation Pro on a Windows or Linux host system, a NAT network (VMnet8) is set up for you. When you use the New Virtual Machine wizard to create a typical virtual machine, the wizard configures the virtual machine to use the default NAT network.

With NAT, a virtual machine does not have its own IP address on the external network. Instead, a separate private network is set up on the host system. In the default configuration, virtual machines get an address on this private network from the virtual DHCP server.

这边开始要出现“真东西”咯,虚拟出一个DHCP server

我直接说 好处:独立出一个DHCP服务器来分配域名,虚拟机不会占用宿主机的IP,不会有IP冲突的风险,当然你的使用程度过少(用到的虚拟机太少,体现不了这种差距) 缺点:内网中的其他人无法和虚拟机通讯(或者说很难进行通信,实际上我还没有成功配置过NAT模式下宿主机与虚拟之间的通信呢)

NAT Configuration

NAT Configuration

The virtual machine and the host system share a single network identity that is not visible on the external network. NAT works by translating the IP addresses of virtual machines in the private network to the IP address of the host system. When a virtual machine sends a request to access a network resource, it appears to the network resource as if the request is coming from the host system.

虚拟机和主机系统共享一个在外部网络中不可见的网络标识。NAT的工作原理是将私有网络中的虚拟机的IP地址转换为主机系统的IP地址。当虚拟机发送访问网络资源的请求时,网络资源会认为这个请求来自主机系统。

NAT 模式主要还是起到了一个翻译的中转站功能,和桥接相比,他比较能够避免跟宿主机抢IP地址。桥接模式可是直接跟宿主机“”IP地址了呢。

The host system has a virtual network adapter on the NAT network. This adapter enables the host system and virtual machines to communicate with each other. The NAT device passes network data between one or more virtual machines and the external network, identifies incoming data packets intended for each virtual machine, and sends them to the correct destination.

主机系统在NAT网络中存在一个虚拟网卡。这个适配器使主机系统和虚拟机能够相互通信。NAT设备负责在一台或多台虚拟机与外部网络之间传递网络数据,识别接收到每个虚拟机的数据包,并将这些数据包发送到正确的目的地。

详细举了个例子解释了NAT的工作能力。

提供各种玩法

Features and Limitations of NAT Configurations

NAT is useful when the number of IP addresses is limited or the host system is connected to the network through a non-Ethernet adapter.[了解更多内容]

当IP地址数量有限或主机系统通过非以太网适配器连接到网络时,NAT很有用

这不就正好呼应了我的开头嘛,NAT不跟宿主机抢IP地址,是位好同志!

Change NAT Settings

You can change the gateway IP address, configure port forwarding, and configure advanced networking settings for NAT networks. [了解更多内容]

您可以修改网关地址、配置端口转发、配置NAT网络的高级组网设置。

自己去探索琢磨叭,我也是新手,不了解呢。

Editing the NAT Configuration File

If you are an advanced user, you can edit the NAT configuration file to modify NAT settings. [了解更多内容]

如果您是高级用户,您可以通过编辑NAT配置文件来修改NAT设置。

这不是废话嘛。没试过,你们加油。

Using NAT with NetLogon

If you use NAT networking in a Windows virtual machine running on a Windows host system, you can use NetLogon to log in to a Windows domain from the virtual machine and access file shares that the WINS server knows.[了解更多内容]

如果在Windows主机系统的Windows虚拟机上使用NAT组网,可以通过NetLogon在虚拟机上登录Windows域,访问WINS服务器知道的文件共享。

确实,能够访问windows,而windows无法访问虚拟机,这个我确实实操过,就挺离谱的。

Specifying Connections from Source Ports Below 1024

If a virtual machine that uses NAT attempts to connect to a server that requires the client to use a source port below 1024, the NAT device must forward the request from a port below 1024. For security reasons, some servers accept connections only from source ports below 1024.[了解更多内容]

如果使用NAT的虚拟机尝试连接服务器,而服务器要求客户端使用1024以下的源端口,NAT设备必须转发1024以下的源端口请求。出于安全原因,一些服务器只接受来自源端口小于1024的连接。

长知识了呢!

Host-Only Networking Configuration

原理讲解

When you install Workstation Pro on a Windows or Linux host system, a host-only network (VMnet1) is set up for you. Host-only networking is useful if you need to set up an isolated virtual network. In a host-only network, the virtual machine and the host virtual network adapter are connected to a private Ethernet network. The network is completely contained within the host system.

当您在Windows或Linux主机系统上安装Workstation Pro时,会为您设置一个仅供主机使用的网络(VMnet1)。如果您需要设置一个隔离的虚拟网络,那么仅供主机使用的网络非常有用。在仅供主机使用的网络中,虚拟机和主机虚拟网卡连接到专用以太网网络。网络完全包含在主机系统中。

The network connection between the virtual machine and the host system is provided by a virtual network adapter that is visible on the host operating system. The virtual DHCP server provides IP addresses on the host-only network.

虚拟机和主机系统之间的网络连接是由主机操作系统上可见的虚拟网络适配器提供的。虚拟DHCP服务器在主机专用网络中提供IP地址。

看了一大段官方的开场白

直接上我的结论:

Host-Only网络配置能实现的网络效果描述如下: 单独的一台机器,全封闭的网络,虚拟机唯一能够访问的就是主机。当然多个虚拟机之间也可以互相访问。如果想要虚拟机上外网则需要主机联网并且网络共享。

Host-Only Networking Configuration

Host-Only Networking Configuration

In the default configuration, a virtual machine in a host-only network cannot connect to the Internet. If you install the proper routing or proxy software on the host system, you can establish a connection between the host virtual network adapter and a physical network adapter on the host system to connect the virtual machine to a Token Ring or other non-Ethernet network.

默认情况下,主机专用网络中的虚拟机不能连接到Internet。如果在主机系统上安装了合适的路由或代理软件,可以在主机虚拟网卡和主机系统的物理网卡之间建立连接,将虚拟机连接到令牌环或其他非以太网网络。

这一块触及到我的盲区了,令牌环emmmm,应该是token连接那一块的,希望以后补充。

On a Windows host computer, you can use host-only networking in combination with the Internet Connection Sharing feature in Windows to allow a virtual machine to use the dial-up networking adapter or other connection to the Internet on the host system. See Microsoft documentation for information on configuring Internet Connection Sharing.

在Windows主机计算机上,您可以结合使用Windows中的Internet连接共享特性,以允许虚拟机使用拨号网络适配器或其他连接到主机系统上的Internet。有关配置Internet连接共享的信息,请参阅Microsoft文档。

我直接直译咯!

提供各种玩法

Add a Host-Only Network

When you install Workstation Pro on a Windows or Linux host system, a host-only network (VMnet1) is set up for you. You might want to configure multiple host-only networks to manage network traffic between virtual machines in specific ways. [了解更多内容]

配置多个Host-Only方式的虚拟机实现共通通讯。

Configure Host-Only Networking for an Existing Virtual Machine

You can configure host-only networking for an existing virtual machine. You can connect a virtual network adapter to the default host-only network (VMnet1) or to a custom host-only network. If a virtual machine has two virtual network adapters, you can connect it to two host-only networks. [了解更多内容]

默认的或自定义的网络。一个虚拟机还可以同时连接至两个Host-Only模式的网络呢。新增玩法,GET!

Set Up Routing Between Two Host-Only Networks

If you are setting up a complex test network that uses virtual machines, you might want to have two independent host-only networks with a router between them. [了解更多内容]

一种Host-Only的应用场景

Avoiding IP Packet Leakage in Host-Only Networks

Each host-only network should be confined to the host system on which it is set up. Packets that virtual machines send on this network should not leak out to a physical network attached to the host system. Packet leakage can occur only if a machine actively forwards packets.[了解更多内容]

每个Host-Only网络应该被限制在它所建立的主机系统中。虚拟机在这个网络上发送的数据包不应该泄漏到连接到主机系统的物理网络上。只有当机器主动转发数据包时,才会发生数据包泄漏。

网络被限制住了噻。非允许,不可以向物理机(宿主机)发送数据包(数据包泄露)

Controlling Routing Information for Host-Only Networks on Linux

A host-only network has a network interface associated with it (vmnet1) that is marked up when the host operating system is booted. Routing server processes that operate on the host operating system automatically discover the host-only network and propagate information on how to reach the network, unless you explicitly configure them not to do so.[了解更多内容]

仅供主机使用的网络有一个与之关联的网络接口(vmnet1),该接口在主机操作系统启动时被标记出来。在主机操作系统上运行的路由服务器进程会自动发现主机专用网络,并传播关于如何到达网络的信息,除非您显式地将它们配置为不这样做。

Using DHCP and DDNS with Host-Only Networking on Linux

The virtual DHCP server in Workstation Pro cannot update a DNS server by using a Dynamic Domain Name Service (DDNS). For this reason, you should use DHCP to supply IP addresses as well as other information, such as the identity of a host running a name server and the nearest router or gateway. [了解更多内容]

“工作站专业版”中的虚拟DHCP服务器无法通过DDNS (Dynamic Domain Name Service)更新DNS服务器。由于这个原因,您应该使用DHCP来提供IP地址以及其他信息,例如运行名称服务器的主机的标识以及最近的路由器或网关。

计网基础知识

唉,太晚了不写了,2022年1月12日00:49:04

放个我颇受感慨,且认为还不错的视频链接叭

https://www.bilibili.com/video/BV1xu411f7UW?spm_id_from=333.1007.top_right_bar_window_history.content.click

yyds,通俗易懂呢!