Import Oracle public key:
# wget -q https://www.virtualbox.org/download/oracle_vbox.asc sudo rpm --import oracle_vbox.ascadd EPEL repository:
# dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm Install VirtualBox on RHEL 8 / CentOS 8 # dnf -y install binutils kernel-devel kernel-headers libgomp make patch gcc glibc-headers glibc-devel dkms该步骤会出现kernel部分组件缺失或者版本不匹配情况,可以直接手动进行安装:
访问: https://rpmfind.net/linux/rpm2html/search.php?query=kernel-headers&submit=Search+...&system=&arch= 下载对应的kernel插件 wget [kerver-needs-plugin.rpm] 安装插件 rpm -i [kerver-needs-plugin.rpm]install virtualbox:
# dnf install -y VirtualBox-6.1To manually add VirtualBox user must to be a member of the group.
# usermod -aG vboxusers $USERTo install otther plugins
# yum install gcc gcc-c++ # dnf install elfutils-libelf-devel // 如果elfutils-libelf-devel无法找到,试试以下的库 elfutils elfutils-libelf-devel libelf-dev libelf-develTo rebuild Kernel modules, run:
# /usr/lib/virtualbox/vboxdrv.sh setup Starting VirtualBox on CentOS 8 / RHEL 8 Linux完全按照【Oracle VirtualBox安装CentOS 8】进行即可。
注意:最后安装完成,先将虚拟机关机,再将系统设置中的光驱镜像移除,再启动,否则还会出现第一步的安装画面
宿主机查看端口是否开启【虚拟机需要开机】:
$ netstat -ntl | grep 22015 tcp 0 0 0.0.0.0:22015 0.0.0.0:* LISTEN测试是否ssh能登录成功:
$ ssh root@127.0.0.1 -p 22015 root@127.0.0.1's password: Last login: Thu Sep 3 02:20:31 2020 from 10.0.2.2 [root@localhost ~]#将上述的宿主机映射到虚拟机的端口22015加入到防火墙开启端口中
$ sudo firewall-cmd --permanent --zone=public --add-port=3389/tcp $ sudo firewall-cmd --reload将上述的宿主机映射到虚拟机的端口22015加入到防火墙开启端口中
$ sudo firewall-cmd --permanent --zone=public --add-port=22015/tcp $ sudo firewall-cmd --reloadvirtualbox 版本是:6.1
因为VirtualBox通过nat模式建立的所有虚拟机的ip都是10.0.2.15,且只能虚拟机ping通宿主机和外网,上一节已经实现了宿主机ping通虚拟机,这一节实现虚拟机之间的互ping,这样方便进行分布式部署。
添加nat network网络(这在网上的许多资源里面都没有介绍这一步) 在VirtualBox主界面依次选择:File > Preferences > Network,打开网卡设置界面,创建Nat网络 :(2)修改nat网络属性:
名称可以保持默认,也可以自己修改。同时根据自己的IP段修改IP信息,保存退出
(3)保存退出
设置虚拟机网络 (1)关闭虚拟机 (2)将创建的Nat network添加到Adapter 2里面(3)启动虚拟机,通过ip addr 或 ifconfig 命令查看IP信息
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:25:6f:d3 brd ff:ff:ff:ff:ff:ff inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic noprefixroute enp0s3 valid_lft 85727sec preferred_lft 85727sec 3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:43:d6:39 brd ff:ff:ff:ff:ff:ff inet 192.168.100.10/24 brd 192.168.100.255 scope global dynamic noprefixroute enp0s8 valid_lft 526sec preferred_lft 526sec 4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default link/ether 02:42:9e:e1:3f:10 brd ff:ff:ff:ff:ff:ff inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0 valid_lft forever preferred_lft forever(4)相同方法设置其他的虚拟机,最后通过ping 192.168.100.x进行检测
[root@k8s-002 ~]# ping 192.168.100.11 PING 192.168.100.11 (192.168.100.11) 56(84) bytes of data. 64 bytes from 192.168.100.11: icmp_seq=1 ttl=64 time=1.00 ms 64 bytes from 192.168.100.11: icmp_seq=2 ttl=64 time=0.718 ms 64 bytes from 192.168.100.11: icmp_seq=3 ttl=64 time=0.779 ms【TODO】