如果你是linux完全可以使用xfowarding,由于我还在用windows本,无奈只能曲线救国,参考了多个帖子,折腾半天总算搞定了。这里搬运一下,顺便添加了一些自己在安装过程中的问题和解决方案。
I followed the steps in the post shown above.
Step1
Connect to your instance either through SSH option or use gcloud option. Once connected update the source list.
sudo apt-get update
Install the Gnome components
Then we need to install the Gnome components for our virtual desktop. So type the following command:
sudo apt-get install gnome-core
Note here gnome-core may not be sufficient. I've tried all gnome packages and finally got it work.
For example, make sure your virtual machine have installed Xorg.
Install a Virtual Desktop using VNC
Now we need a VNC server to interact with desktop environment. I am using vnc4server, you can install your favorite one:
sudo apt-get install vnc4server
Start the vnc server, You’ll then be prompted to create and verify a new password:
vncserver
If everything went fine your VNC server is now running and listening on port 5901. You can verify this with netcat from the Google Compute Engine instance:
$ nc localhost 5901
RFB 003.008
We now need to kill the session we just created and make a tweak to the startup script for VNCServer to make it work properly. If we don’t perform this step then all we will see is a grey cross-hatched screen with an “X” cursor and/or a grey screen with a Terminal Session, depending on the Ubuntu version. Not very useful!
So, type the following command to kill the session:
$ vncserver -kill :1
Now open the file we need to edit:
vim .vnc/xstartup
#!/bin/sh
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc
#[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
#[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
#xsetroot -solid grey
#vncconfig -iconic &
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
metacity &
gnome-settings-daemon &
gnome-panel &
So, we’ve unmasked the unset SESSION_MANAGER line and masked out all the rest. We’ve then added the last 3 lines.
Installing a VNC client
Now install a VNC client on your local machine. I've used the free version of tightVNC for windows.
Open the firewall
First step is to tag our instance as a vnc-server, for that go to the VM description page and click on “add tags”
In order to communicate with our instance we need its external IP. You can find it on the Developers Console.
Let’s try to connect to it using netcat again:
nc 104.197.91.140 5901
The connection will fail, this is expected as the firewall rules block all communications by default for security reasons.
Let’s fix that.
Google has changed the position to add firewall rules. You can find it by following this path and add new firewall rules.
product & services -> VPC network -> firewall rules
Now you can connect to it using netcat successfully.
After opening the vncserver on remote virtual machine, you can use local machine to login tightVNC and connect to the remote VM.
If you find the tightVNC show a grey screen, it must be some packages missing on you VM. Try to install all packages needed to display the desktop screen!
这里再记录一下如何用ssh tunnel连接到GCE
To use the alternative approach with an SSH tunnel, here are the differences from the tutorial you need to follow:
don't open port 5901 in the Google Compute Engine firewall
create an SSH tunnel from your desktop/laptop to GCE VM via:
gcloud compute ssh \
${VM_INSTANCE} \
--project $PROJECT \
--zone $ZONE \
--ssh-arg "-L ${LOCAL_PORT}:localhost:5901"
where you need to provide the right parameters for ${VM_INSTANCE}, $PROJECT, and $ZONE that match your configuration. You can choose ${LOCAL_PORT} to be 5901 if you wish, but if you decide to VNC into several different GCE VM instances, you'll have to choose unique ports for your local machine.
You need to keep this connection open to use VNC. If this connection is closed, you will lose VNC access as well.
Instead of connecting to your VM using its external IP, connect via localhost:${LOCAL_PORT} with ${LOCAL_PORT} same as selected earlier in step #2
网友评论