虚拟机搭建过程
https://pmlpml.github.io/ServiceComputingOnCloud/ex-install-cloud
网卡配置
为了使虚拟机能够上网,需要修改一下配置。
$ cd /etc/sysconfig/network-scripts/
$ ls
#找到类似ifcfg-en开头的网卡,我的其中一个为ifcfg-enp0s3
$ vi ifcfg-enp0s3
将里面的ONBOOT=no
改为ONBOOT=yes
,保存。多个网卡都要修改。
重启网络使修改生效
$ service network restart
安装openssh-server
如果没有openssh-server就需要安装。
$ yum install openssh-server
sshd服务配置
$ sudo vi /etc/ssh/sshd_config
将相关行行首的#
都去掉,去掉后如下。
Port 22
#AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::
...
#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
开启sshd服务使修改生效
$ sudo /bin/systemctl start sshd.service
设置VirtualBox端口转发
在Centos虚拟机中按⌘S
快捷键打开设置,点击端口转发。
将宿主机一个端口(这里是2222)映射到虚拟机的22端口。
点击OK后立即生效,不需要重启。
连接成功
在宿主机的终端SSH连接。
$ ssh -p 2222 root@localhost
# 如果有Are you sure you want to continue connecting(yes/no)?提示,输入yes
root@localhost's password: #再输入密码就可以登录了
[root@localhost ~]#
这里也可以在宿主机通过ifconfig
查看VirtualBox虚拟网卡的IP,通过这个IP(这里是192.168.100.1)来访问。
$ ifconfig
...
vboxnet0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
ether 0a:00:27:00:00:00
inet 192.168.100.1 netmask 0xffffff00 broadcast 192.168.100.255
...
$ ssh -p 2222 root@192.168.100.1
这个IP的来历: