如何从本机 ip 127.0.0.1 访问 vagrant 中的服务?

How to access service in vagrant from native ip 127.0.0.1?

使用已安装的 Vagrant devstack。在安装配置之前将 HOST_IP 设置为 127.0.0.1。完成安装后,它告诉使用这些信息访问 web ui:

=========================
DevStack Component Timing
=========================
Total runtime    3523

run_process      113
test_with_retry    7
pip_install      647
wait_for_service  51
yum_install      338
git_timed        853
=========================



This is your host IP address: 127.0.0.1
This is your host IPv6 address: ::1
Horizon is now available at http://127.0.0.1/dashboard
Keystone is serving at http://127.0.0.1/identity/
The default users are: admin and demo
The password: secret
Services are running under systemd unit files.
For more information see:
https://docs.openstack.org/developer/devstack/systemd.html

我在Vagrantfile中设置了private_ip 192.168.33.11,我试过这种方式访问​​网络ui:

http://192.168.33.11/dashboard

但是不行。因此,我在 Vagrant 中测试使用 curl 可以确认一些事情:

[stack@localhost devstack]$ curl -I http://127.0.0.1/dashboard
HTTP/1.1 302 Found
Date: Mon, 05 Jun 2017 10:38:37 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod_wsgi/3.4 Python/2.7.5
Vary: Accept-Language,Cookie
X-Frame-Options: SAMEORIGIN
Content-Language: en
Location: http://127.0.0.1/dashboard/auth/login/?next=/dashboard/
Content-Type: text/html; charset=utf-8

现在如何访问控制面板?

这种方式可行:

$ ssh -L 8080:localhost:80 vagrant@192.168.33.11

来自浏览器:

http://localhost:8080/dashboard


参考

$ man ssh
-L [bind_address:]port:host:hostport
         Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side.  This works by allocating a socket to listen to
         port on the local side, optionally bound to the specified bind_address.  Whenever a connection is made to this port, the connection is forwarded over the secure channel,
         and a connection is made to host port hostport from the remote machine.  Port forwardings can also be specified in the configuration file.  IPv6 addresses can be specified
         by enclosing the address in square brackets.  Only the superuser can forward privileged ports.  By default, the local port is bound in accordance with the GatewayPorts set‐
         ting.  However, an explicit bind_address may be used to bind the connection to a specific address.  The bind_address of “localhost” indicates that the listening port be
         bound for local use only, while an empty address or ‘*’ indicates that the port should be available from all interfaces.

这不起作用,因为 devstack 运行 在您的 VM 上的 127.0.0.1 上。

您可以更改配置文件中的 HOST_IP 变量(在 localrc 部分下 - 请参阅 https://docs.openstack.org/developer/devstack/configuration.html)并使用您在 Vagrantfile

中设置的静态 IP
HOST_IP=192.168.33.11
SERVICE_HOST=$HOST_IP