I created a VM Instance with Ubuntu Precise. Then I installed tons of libraries and set up my environment. I will be using another server with slightly different configurations therefore I want to copy or clone my current instance.
I thought the clone button which appears when I edit an instance was going to do the thing I desired but after I cloned my instance and go into the server, I haven't see any library installed or whatever.
Is there any way to completely create a new copy of a server (instance) like I can in Amazon?
Create a snapshot of your current instance
Create a new instance with this snapshot as a disk
There you go.
There is no native way to clone using gcloud. However you can fake it.
Use the UI console for this.
Navigate to the compute you wish to clone, and click clone.
At the bottom of the clone screen, click the 'Equivalent Rest or command line'; command line for the gcloud commands.
Copy that over to your console and execute the gcloud command.
Related
I accidentally deleted my public and private key and had to generate new SSH keys due to not being able to restore the keys (and not having a backup anywhere). How do I change the public SSH key then of my Oracle Cloud instance?
Terminating the instance and remaking it isn't an option, and I've tried looking online but wasn't able to find much. Any help would be appreciated.
Thanks
Some background
Found a solution! Just so people are aware, there are methods online that involve connecting to the machine via VNC, but for me personally it felt very trial-an-error, when pressing buttons at the wrong time, and it ended up not working properly (VNC didn't display recovery mode for me, just a blank screen after selecting it).
Summary
This guide involves: Creating another machine (as incl. in free tier anyway), detaching the boot volume drive from the machine and attaching it to the machine just created, to do editing to change the keys over, then attaching the drive back up.
Create another VPS (Oracle have them incl. > free tier)
I deleted one of my other VPS' in the Oracle panel (that was a free machine - as I didn't need it and wasn't using it) and created it again anew (I made sure to delete the old boot volumes before continuing).
(This solution is assuming your using Ubuntu 20.04, but this will probably work for other OS's as well)
Basically from there,
I powered off the machine I wanted to change my SSH key of.
After fully being powered off, just detach the boot volume from the VPS, and attached it as a block volume to the machine just created.
Login to the machine via SSH, and run the connection commands by hitting the three dots (image below) and viewing the connection commands, to connect the drive up.
Editing files on the drive & mounting process
Then by running blkid (or sudo fdisk -l for a more friendly view)
you're able to see what drives are available for mounting. So then you just make a folder and simply type:
sudo mount [drive path e.g. /dev/sdb] [folder path e.g. ./drive]
Edit the file at /home/ubuntu/.ssh/authorized_keys, or however your machine is configured (Oracle by default disallows root, but if you've edited your configuration it's up to your end).
Then, simply go to the relevant path to be able to unmount the drive, umount [folder path e.g. ./drive]
Run the disconnect commands for the drive from the panel.
Then, simply detach the drive from your other machine and reattach it back to the original machine. Wait till it's fully attached and then start the machine again.
You can create a console connection, connection to it, then reboot the instance (through OCI console), and get to GRUB in the console connection... a few more steps and you can upload a new ssh key: https://docs.oracle.com/en-us/iaas/Content/Compute/References/serialconsole.htm
We are trying to create a horizontaly Scalable web service via Google Compute Engine.
In order to do so, we have created an Instance Template and a Group of Instances based on this new template. The group of instances create a new virtual machine (we chose Debian) in which we can install our NodeJs application and other stuff.
We unlucky found out that when the VM is turned off everything inside the VM is erased. We would like to create a Snapshot or a Disk Image in order to avoid completely rebuild an instance from sketch, but we encountered two problems:
You can't create a Disk Image while the VM is running but if we turn it off we would lose all data in it.
It is possible to create a Snapshot of a VM while it is running but when you create a new instance from the Snapshot we can't link/join the new instance to the Group of Instances.
How can we get to the solution with those tools?
Thanks
Although it is recommended to shutdown your VM instance before creating an image, it is possible to create an image of a running system.
Connect to your instance (SSH, RDP, etc.)
Shutdown the applications that you can such as databases, etc. This purpose is to minimize disk activity and changes to the file system.
Sync the file system to disk. Linux sudo sync. Windows: Sysinternals wrote Sync which will help. Sysinternals's Sync
Go to the Google Console -> Compute Engine ->Disks.
Select your the disk drive for the VM instance.
At the top of the screen will be a button CREATE IMAGE.
Click the button and complete the dialog.
Make sure that you click the button Keep instance running (not recommended).
Once the image completes, I would launch a new instance and verify that you have everything and that everything is working as expected.
Note: You can also create a disk snapshot.
I have an API which runs on an EC2 instance and connects to a MySQL db.
My goal is to set up a clone of this which I can use as a development platform. Currently everything I do is live.
Ideally I would have up to date data in the test verison of the MySQL database, so maybe a script to auto clone the live version to the test version every day would suffice?
I have a standalone .exe application which calls the API.
What is the typical development work flow here?
I guess I will need a seperate folder on my server for my dev branch. Then I can call the dev url from my standalone application.
So during testing I would change the API url from "/live-api/login.php" to "/test-api/login.php" in my standalone program. I would have the /live-api folder and the /test-api folder hooked up to to the same repo, where the /test-api is always on the dev branch and /live-api is always on master branch?
Thanks!
Your architecture looks good.. You have two folder [ if u are on tomcat two webapps] which come from different branches.
Regarding test db getting updated with production db; it looks tricky. Do you want to have independent RDS for your test environment ? One option is that at night anyway you would have configured to take a snapshot [backup] of your production db.. You can re-create your test RDS db with this new snapshot.. Only drawback would be that any test data created on your test environment will get lost daily..
I have a Google Cloud Platform account that I access from a VirtualBox VM. I am using the Google Compute Engine for a project that I am currently working on, and I had to create a custom image based on the Ubuntu 14.04 image that's available there.
I made changes to the Ubuntu image by ssh'ing into an Ubuntu 14.04 instance, (from my Vbox VM terminal) installing the Matlab compiler runtime, and downloading some other files that I needed. I created the custom image by following the steps according to the documentation.
However, now the changes I made are only available to me when I SSH from my Vbox VM terminal. I need to be able to run a certain matlab program Via startup scripts, how can I make it so that all users using this image have access to the customizations I made? Is there a way I can do this without having to make the edits by ssh'ing from the developers console and redoing all the changes?
EDIT: I don't think I was very clear so Ill give some examples. say my Google account is alexanderlang. When I ssh into an instance created from my custom image from the developers console, bash prompt looks like:
alexanderlang#myinstance $
My Vbox username is alex, and when I ssh into the same instance from my vbox terminal, bash prompt looks like:
alex#myinstance $
alex#myinstance can run matlab programs, but alexanderlang#myinstance cannot. I'm talking about the same instance, created from the same image. I think this might have something to do with the ssh keys for my custom image, but I don't know how to change or remove those keys.
When you connect to your VM instance via ssh by using either Developers Console or gcloud, the user account is dynamically created (if it doesn't already exist) by setting metadata on the VM. The question is: how does each tool choose your username?
When you use Google Developers Console, the only information it knows about you is your Google Account name, so it uses that, e.g., <first-name>_<last-name> or similar.
When you connect to your instance via gcloud, it knows the value of $USER so it uses that instead.
Note that in either case, your account has passwordless sudo access, so if you want to switch from one account to the other, you can run:
sudo su alex
while logged in as alexanderlang and then you have access to all the programs that alex does.
Similarly, you can run:
sudo su alexanderlang
while logged in as alex to do the reverse.
Startup scripts run as root. To run commands as another user, you need to do two things:
change to that username
run commands as that user
sudo su alex will create a new shell and hence ignore the rest of the script (until you manually exit the user shell, which is not what you want).
You can use sudo su alex -c 'command to run' but since what you want to run is a complex script, you need to first save the script to a file, and then run it.
Your options are:
pre-create the shell script to run
dynamically generate it from the startup script
Doing (1) is easy if the script never changes. For frequently-changing scripts (and it sounds like, many dynamically created VMs), you want to use option (2).
Here's how to do this in a startup script:
cat > /tmp/startup-script-helper.sh <<EOF
# ... put the script contents here ...
EOF
sudo su alex -c '/tmp/startup-script-helper.sh'
You can use Packer to create a derived image from a stock GCE VM image. Packer will let you do the following very easily:
boot a GCE VM using an image you specify
run some customization step, e.g., shell script, or Chef/Puppet/etc.
save the resulting image in your Google Cloud Platform project
Then, you can boot any number of new VMs using your newly-created image.
Note that since your VM image will be stored on Google Cloud Storage, you will be charged for the space it uses. Current pricing for Google Cloud Storage standard class is USD $0.026 / GB / month. A typical VM image should be less than 1GB.
You can see a complete example of how I used Packer to build VMs and pre-installed Ambari on it via my GitHub repo.
I am trying to get an application running on OpenShift but after trying to create an ssh key on Ubuntu using ssh-keygen I ran into permissions problems. This is because I find I have no need for the rhc client if it only automates this process but bloats my computer (laptop) with a ruby installation.
I find that it would be best to have an alternative for Ubuntu (Linux) users. Is it possible to make this happen or do I have to go the rhc way?
You get a long way without the rhc command line tool. Obviously you can create your ssh key yourself and add/mange it via the OpenShift website. You can also create your application there and add cartridges. When it comes to starting the app, you can usually do that by jsut pushing your git repository. Last but not least, you can ssh onto your OpenShift gear and do a lot from there, for example view the log files.
That said, the rhc client is your one stop client for all this (and more). So even if you might not need it right now and some task are in fact done easier without it, I would still recommend to install it. A lot of information/tutorials are using rhc and w/o enough experience you will not know how to achieve a certain task in a different way.