How do you access the console of a GCE VM instance? - console

How can I access the console of a Google Compute Engine VM instance?

To see the console output (read-only), you can use any of the following methods:
Web UI via Developers Console – on the instance detail page, scroll to the bottom of the page and expand the console output view
CLI via gcloud compute instances get-serial-port-output
API via getSerialPortOutput
To get read/write (interactive) access, follow instructions on this page:
gcloud compute instances add-metadata [INSTANCE_NAME] \
--metadata=serial-port-enable=1
and then, per the same page, either connect via Google Cloud Console:
Go to the VM instances page.
Go to the GCE VM instances page
Click the instance you want to connect to.
Scroll to the bottom of the page and look for the Serial port section.
If you want to connect to a serial port other than the default serial port 1, click the down arrow next to the Connect to serial port button and change the port number accordingly.
Click the Connect to serial port button to connect to port 1 by default. For Windows instances, pull down the dropdown menu next to the button and connect to Port 2 to access the serial console.
or, connect via gcloud:
Use the gcloud compute connect-to-serial-port subcommand to connect using the gcloud command-line tool. For example:
gcloud compute connect-to-serial-port [INSTANCE_NAME]
where [INSTANCE_NAME] is the name of the instance for which you want to access the serial console.
By default, the connect-to-serial-port command connects to port 1 of the serial console. If you are connecting to a Windows VM instance, connect to port 2 instead:
gcloud compute connect-to-serial-port [INSTANCE_NAME] --port 2
To connect to any other port, provide a different port number using the --port flag. You can provide a port number from 1 through 4, inclusively. To learn more about port numbers, see Understanding serial port numbering.

While this doesn't answer your direct question, if the reason you need physical console access is to troubleshoot why a system is inaccessible (i.e. it no longer boots or, because of a bad firewall configuration, you can no longer access it over SSH), your best bet is to:
Update the disk configuration so it is not deleted when the instance is destroyed
Delete the instance so the disk is no longer attached to a running instance
Attach the disk to another instance which boots correctly
Mount the disk to a temporary location within that instance, so you can read logs, view/edit configuration files, etc.

Related

AWS Neptune: Notebook Does Not Connect Though I Can Connect to the DB from my EC2 Instance

Problem
I have created an AWS Neptune DB cluster and it does not connect from the Jyupiter Notebook (SageMaker). The status check does not respond and eventually displays a timeout message after a minute or longer. It looks like it is hanging.
I have created a notebook with a new name and a new IAM role name.
I have selected Direct access through Amazon SageMaker which is the default.
After doing this, it simply does not connect to my DB. Even though, I can connect fine with gdotv.com Gremlin IDE and Gremlin Console from an EC2 instance running on the designated VPC.
Possible Fix
This answer pertains to situations where you already can connect to your Neptune from your EC2 instance but not from the SageMaker side.
There are many causes of Neptune connection issue but most of which are security group related and especially that the inbound port 8182 is not enabled for various scenarios.
Specific to the SageMaker notebooks, it may be requesting a connection from a subnet you have not yet permitted 8182. That was my situation.
To check for this condition:
Go to the SageMaker console, Notebook -> Notebook Instances and select your instance.
Scroll down that page until you find the Network card and select subnet. Click on the subnet and take the note of the IPv4 CIDR (you could be using IPv6 too) block information.
On your Neptune Console, select the Cluster's Writer node. This is where you find the security group that the instance is using. Click on the security group link on the top right of the Connectivity and Security card.
Click the Security Group ID in the list and then you should see the Inbound Rules table. Click the Edit inbound rules button on that panel.
Add Rule
And add a new Custom TCP rule for Port 8182 and add the subnet block.
Save the configuration - the save button is often missed but it will show up at the bottom of the panel.
Now restart your notebook and test the status.
Note: If all else fails add 0.0.0.0/32 (the entire world) for a brief period of time and see if it connects. If it does connect, you know it's your SG. If it does not, this is not the answer.

Unable to access Kafka Broker from separate LAN machine

EDIT: OBE - figured it out. Provided in answer for anyone else who has this issue.
I am working in an offline environment and am unable to connect to a kafka broker, on machine 1, from a separate machine, machine 2, on a LAN connection through a single switch.
Machine 1 (where Kafka and ZK are running):
server.properties
listeners=PLAINTEXT://<ethernet_IPv4_m1>:9092
advertised.listeners=PLAINTEXT://<ethernet_IPv4_m1>:9092
zookeeper.connect=localhost:2181
I am starting kafka/ZK from the config files located in kafka_2.12-2.8.0/config and the running the appropritate .bat from kafka_2.12-2.8.0/bin/windows.
On machine 2 I am able to ping <ethernet_IPv4_m1> and get results; however, I fail to get a TCP connection if I run Test-NetConnection <ethernet_IPv4_m1> -p 9092 while kafka is running. In python 3.8.11, using KafkaConsumer from kafka-python, I receive the NoBrokersAvailable error when using <ethernet_IPv4_m1>:9092 as the bootstrap_server. Additionally if I run a python:3.8.12-buster docker container with a '/bin/bash' entrypoint, and follow along with the kafka-listener walkthrough I am unable to connect to the broker. I'm in the exact situation as Scenario 1 provided in the link, but the walkthrough assumes you can connect to the broker. I have also tried opening the 9092 port in my Windows Defender for in/outbound traffic (on both machines) and still have no luck. Neither Kafka, nor networking, are my strong suits and every tutorial/answer I find refers to changing the listener and advertised.listener in the kafka server.properties file - I think I correctly did this, but am unsure. This is everything I have tried so far, any recommendations would be greatly appreciated. Thank you.
For M1, the private network was the active network.
Go to control panel -> Firewall & network protection -> advanced settings (must be admin) -> setup inbound/outbound rules for port 9092 for the active network.

Docker Google cloud

I have a CentOS VM instance in google cloud and I have installed docker on CentOS. I have created a container with web interface. I am not able to access it When i try to access it from outside (In browser Other tab). What do I need to do to access it from outside of cloud?
There are several leaps between your browser your containerised web interface.
The first will be from the IP through the GCP firewall into the Instance, you might be getting stuck here, when you created the instance, in the Firewall section, did you select "Allow HTTP traffic and Allow HTTPS traffic"?
If you click through to your instance details in the GCP dashboard you can see under Firewalls if this is selected, also if you look under Network you can see which network profile your instance it using, you can click the network listed to check if it is set up to allow the traffic you are trying to send though.
If this all looks right and traffic is getting to the instance but not the web interface, it could be that the port from docker is not mapped to the port of the host, when you started the container did you use the -p option to map the ports?
If this is also right, then it could be that the Docker image is not exposing it's port internally, in the Dockerfile used to create the Image for the container is there a line starting with EXPOSE, or does if build FROM an Image that does?
There are more possible points of failure in this chain but I have tried to list some likely answers. If none of this helps then let me know in the comments and we can try and debug the issue.

How to execute a command on hosts (physical machines) via OpenStack code?

I am trying to modify/add some OpenStack code to implement such functionality: after users click one button, some command will be executed on the specified host (e.g. one compute node).
One user scenario is, enable KSM kernel feature on one specified host. All need to do is to run "echo 1 > /sys/kernel/mm/ksm/run". Now I can get the IP of the host (some compute node), but how to execute the above command via OpenStack code?
(I checked all the Nova APIs. It seems there is no such Nova API to execute a command on a host. Also, I checked all the Ironic APIs. The same result.)

Accessing localhost API endpoint from different machine

I have a pressure sensor plugged into my computer, and the only way to collect the data is through a localhost API endpoint, meaning right now only that machine can collect data. Is there any way to receive data from the localhost API on a different machine? I also need to ping the API 20-40 times a second if that matters.
There are couple of ways I can think of, I am assuming both the machines are on same network
Use localhost API to collect the data in database and create a GET endpoint inside same application for fetching the data according your parameters. You can access GET endpoint from different machine by hitting network ip address of your local machine. Which you can check using ifconfig command in your terminal, check en0 type where you will find something like 192.168.X.X. From other machine you can hit http://192.168.X.X:<port>/getData, where <port> is the localhost port.
If you don't want to use database, then you can use publish subscribe mechanism which is real time. see http://autobahn.ws/python/
How publish subscribe works ?
You will have to make your localhost machine a publisher (server) which will publish events or sensor data in your case (real time). The other machine will be subscriber (client ) which will listen to the events from your server and do necessary processing.
Its uses WAMP (Web application messaging protocol) for communication. The sample code for basic publisher and subsriber can be found here.
Follow steps:
1 : Download ngrok,
2 : Go to the path where ngrok.exe file present and open that path in cmd.
3 : Connect your account.
paste : ngrok authtoken1pA6advIt950uA4y2Rixgc8rdx9_23MSDokKjWhbPUW3NSrZK
4 : Replace your port no including bracket.
paste : ngrok http {9003} -host-header="localhost:{9003}".
5 : copy forward line and paste in other system to check.
Forwarding http://d1c0bc16ff7b.ngrok.io

Resources