Article Directory
- Vagrant installation
- How to ensure that the network host host and virtual machines to share
- How can log virtual machine via SFTP
- View the current configuration of the virtual machine
- Check into the virtual machine virtual machine IP
- Design of the virtual machine root account can log in via password
- The above configuration takes effect so
- In the form of a virtual machine sftp login as root account
- Incidentally change the current password for the root account
- How to ensure the synchronization of the server's local folder contents with Vagrant created in the folder contents of the file
Vagrant installation
Vagrant 的安装不再赘述,可以参考下面的地址
https://blog.csdn.net/u014636209/article/details/103052261#2vagrant_7
How to ensure that the network host host and virtual machines to share
VagrantFile modify file attributes
localhost:centos7 gaoxinfu$ pwd
/Users/gaoxinfu/docker/centos7
localhost:centos7 gaoxinfu$ ls
Vagrantfile
The comments below this line VagrantFile file to open
config.vm.network "public_network"
Test whether the network can ping
Login Vagrant centos machine created to view centos machines ip
localhost:centos7 gaoxinfu$ vagrant ssh
Last login: Sat Nov 23 23:28:15 2019
[vagrant@localhost ~]$ ip a
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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 52:54:00:8a:fe:e6 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global noprefixroute dynamic eth0
valid_lft 85003sec preferred_lft 85003sec
inet6 fe80::5054:ff:fe8a:fee6/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:cc:9d:4d brd ff:ff:ff:ff:ff:ff
inet 192.168.1.7/24 brd 192.168.1.255 scope global noprefixroute dynamic eth1
valid_lft 257811sec preferred_lft 257811sec
inet6 fe80::a00:27ff:fecc:9d4d/64 scope link
valid_lft forever preferred_lft forever
[vagrant@localhost ~]$
如上,当前创建的centos虚拟机的ip为 192.168.1.7
Test ping the virtual machines on the host host (your local computer machines) ip
localhost:~ gaoxinfu$ ping 192.168.1.7
PING 192.168.1.7 (192.168.1.7): 56 data bytes
64 bytes from 192.168.1.7: icmp_seq=0 ttl=64 time=0.376 ms
64 bytes from 192.168.1.7: icmp_seq=1 ttl=64 time=0.513 ms
64 bytes from 192.168.1.7: icmp_seq=2 ttl=64 time=0.411 ms
64 bytes from 192.168.1.7: icmp_seq=3 ttl=64 time=0.365 ms
如上,已经能够ping通
这样后面,我们在自己的本地,如果需要访问虚拟机里的应用服务,就可以使用虚拟机的ip+端口就可以访问了
How can log virtual machine via SFTP
View the current configuration of the virtual machine
进入我们创建的虚拟机的目录,使用vagrant ssh-config 查看虚拟机的ssh的配置
(前提是你肯定要启动当前的虚拟机)
如下:
localhost:centos7 gaoxinfu$ pwd
/Users/gaoxinfu/docker/centos7
localhost:centos7 gaoxinfu$ vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/gaoxinfu/docker/centos7/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
localhost:centos7 gaoxinfu$
Check into the virtual machine virtual machine IP
localhost:centos7 gaoxinfu$ vagrant ssh
Last login: Sat Nov 23 23:37:24 2019 from 10.0.2.2
[vagrant@localhost ~]$ ip a
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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 52:54:00:8a:fe:e6 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global noprefixroute dynamic eth0
valid_lft 84489sec preferred_lft 84489sec
inet6 fe80::5054:ff:fe8a:fee6/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:cc:9d:4d brd ff:ff:ff:ff:ff:ff
inet 192.168.1.7/24 brd 192.168.1.255 scope global noprefixroute dynamic eth1
valid_lft 257297sec preferred_lft 257297sec
inet6 fe80::a00:27ff:fecc:9d4d/64 scope link
valid_lft forever preferred_lft forever
[vagrant@localhost ~]$
如上ip是 192.168.1.7
Design of the virtual machine root account can log in via password
进入虚拟机之后,
我们通过root账户登录(命令 sudo -i)
[root@localhost ~]# sudo -i
[root@localhost ~]# vi /etc/ssh/sshd_config
在上面的命令中配置下面这个属性
PasswordAuthentication yes
相应的
PasswordAuthentication no
这个要注释掉
The above configuration takes effect so
[root@localhost ~]# systemctl restart sshd
[root@localhost ~]#
In the form of a virtual machine sftp login as root account
登录成功
Note here under, we can also visit the above machines go through 127.0.0.1
The above is the reason why port 2222, due to the port mapping virtual machines to create our local vagrant is 2222
localhost:centos7 gaoxinfu$ pwd
/Users/gaoxinfu/docker/centos7
localhost:centos7 gaoxinfu$ vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/gaoxinfu/docker/centos7/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
localhost:centos7 gaoxinfu$
Incidentally change the current password for the root account
[root@localhost ~]# passwd
Changing password for user root.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
How to ensure the synchronization of the server's local folder contents with Vagrant created in the folder contents of the file
1.打开Vagrantfile文件,配置下面属性即可
2.这样你在本地开发了东西之后,他会是自动的同步到服务器里对应的文件夹下面
# config.vm.synced_folder "../data", "/vagrant_data"
第一个目录是你本地的目录,第二个目录是vagrant创建的系统服务器的文件夹目录
比如Windows系统:
config.vm.synced_folder "E://data", "/weblogic/data"
或者Mac|linux系统:
config.vm.synced_folder "/data", "/weblogic/data"